diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp index 5b2ea442432809..27db6cc5d40d38 100644 --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -334,9 +334,9 @@ void TextOutputSection::finalize() { /*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false); } else { r.referent = thunkInfo.sym = make( - thunkName, /*file=*/nullptr, thunkInfo.isec, /*value=*/0, - thunkSize, /*isWeakDef=*/false, /*isExternal=*/false, - /*isPrivateExtern=*/true, /*isThumb=*/false, + thunkName, /*file=*/nullptr, thunkInfo.isec, /*value=*/0, thunkSize, + /*isWeakDef=*/false, /*isExternal=*/false, /*isPrivateExtern=*/true, + /*includeInSymtab=*/true, /*isThumb=*/false, /*isReferencedDynamically=*/false, /*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false); } diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 2661c707121240..ae974a5e34d72a 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -530,14 +530,11 @@ static void replaceCommonSymbols() { // FIXME: CommonSymbol should store isReferencedDynamically, noDeadStrip // and pass them on here. - replaceSymbol(sym, sym->getName(), common->getFile(), isec, - /*value=*/0, - /*size=*/0, - /*isWeakDef=*/false, - /*isExternal=*/true, common->privateExtern, - /*isThumb=*/false, - /*isReferencedDynamically=*/false, - /*noDeadStrip=*/false); + replaceSymbol( + sym, sym->getName(), common->getFile(), isec, /*value=*/0, /*size=*/0, + /*isWeakDef=*/false, /*isExternal=*/true, common->privateExtern, + /*includeInSymtab=*/true, /*isThumb=*/false, + /*isReferencedDynamically=*/false, /*noDeadStrip=*/false); } } diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 8423fb8bb9beb9..4e37bad92361b1 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -636,9 +636,10 @@ static macho::Symbol *createDefined(const NList &sym, StringRef name, } assert(!isWeakDefCanBeHidden && "weak_def_can_be_hidden on already-hidden symbol?"); + bool includeInSymtab = !name.startswith("l") && !name.startswith("L"); return make( name, isec->getFile(), isec, value, size, sym.n_desc & N_WEAK_DEF, - /*isExternal=*/false, /*isPrivateExtern=*/false, + /*isExternal=*/false, /*isPrivateExtern=*/false, includeInSymtab, sym.n_desc & N_ARM_THUMB_DEF, sym.n_desc & REFERENCED_DYNAMICALLY, sym.n_desc & N_NO_DEAD_STRIP); } @@ -658,7 +659,7 @@ static macho::Symbol *createAbsolute(const NList &sym, InputFile *file, return make(name, file, nullptr, sym.n_value, /*size=*/0, /*isWeakDef=*/false, /*isExternal=*/false, /*isPrivateExtern=*/false, - sym.n_desc & N_ARM_THUMB_DEF, + /*includeInSymtab=*/true, sym.n_desc & N_ARM_THUMB_DEF, /*isReferencedDynamically=*/false, sym.n_desc & N_NO_DEAD_STRIP); } diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp index a3e32537dc4f80..113b4dba7f3450 100644 --- a/lld/MachO/SymbolTable.cpp +++ b/lld/MachO/SymbolTable.cpp @@ -103,8 +103,9 @@ Defined *SymbolTable::addDefined(StringRef name, InputFile *file, !isPrivateExtern; Defined *defined = replaceSymbol( s, name, file, isec, value, size, isWeakDef, /*isExternal=*/true, - isPrivateExtern, isThumb, isReferencedDynamically, noDeadStrip, - overridesWeakDef, isWeakDefCanBeHidden, interposable); + isPrivateExtern, /*includeInSymtab=*/true, isThumb, + isReferencedDynamically, noDeadStrip, overridesWeakDef, + isWeakDefCanBeHidden, interposable); return defined; } @@ -233,9 +234,9 @@ Defined *SymbolTable::addSynthetic(StringRef name, InputSection *isec, assert(!isec || !isec->getFile()); // See makeSyntheticInputSection(). Defined *s = addDefined(name, /*file=*/nullptr, isec, value, /*size=*/0, - /*isWeakDef=*/false, isPrivateExtern, - /*isThumb=*/false, referencedDynamically, - /*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false); + /*isWeakDef=*/false, isPrivateExtern, /*isThumb=*/false, + referencedDynamically, /*noDeadStrip=*/false, + /*isWeakDefCanBeHidden=*/false); s->includeInSymtab = includeInSymtab; return s; } diff --git a/lld/MachO/Symbols.cpp b/lld/MachO/Symbols.cpp index 16868adcdfa965..31ee4c65fe6d44 100644 --- a/lld/MachO/Symbols.cpp +++ b/lld/MachO/Symbols.cpp @@ -42,12 +42,12 @@ uint64_t Symbol::getTlvVA() const { return in.tlvPointers->getVA(gotIndex); } Defined::Defined(StringRefZ name, InputFile *file, InputSection *isec, uint64_t value, uint64_t size, bool isWeakDef, bool isExternal, - bool isPrivateExtern, bool isThumb, + bool isPrivateExtern, bool includeInSymtab, bool isThumb, bool isReferencedDynamically, bool noDeadStrip, bool canOverrideWeakDef, bool isWeakDefCanBeHidden, bool interposable) : Symbol(DefinedKind, name, file), overridesWeakDef(canOverrideWeakDef), - privateExtern(isPrivateExtern), includeInSymtab(true), + privateExtern(isPrivateExtern), includeInSymtab(includeInSymtab), wasIdenticalCodeFolded(false), thumb(isThumb), referencedDynamically(isReferencedDynamically), noDeadStrip(noDeadStrip), interposable(interposable), weakDefCanBeHidden(isWeakDefCanBeHidden), diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h index 211983f0790f61..7dbab691c564da 100644 --- a/lld/MachO/Symbols.h +++ b/lld/MachO/Symbols.h @@ -117,9 +117,9 @@ class Defined : public Symbol { public: Defined(StringRefZ name, InputFile *file, InputSection *isec, uint64_t value, uint64_t size, bool isWeakDef, bool isExternal, bool isPrivateExtern, - bool isThumb, bool isReferencedDynamically, bool noDeadStrip, - bool canOverrideWeakDef = false, bool isWeakDefCanBeHidden = false, - bool interposable = false); + bool includeInSymtab, bool isThumb, bool isReferencedDynamically, + bool noDeadStrip, bool canOverrideWeakDef = false, + bool isWeakDefCanBeHidden = false, bool interposable = false); bool isWeakDef() const override { return weakDef; } bool isExternalWeakDef() const { diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 8ed6f5c2d51c2d..7e1d92b3bad818 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -634,6 +634,7 @@ void StubHelperSection::setup() { make("__dyld_private", nullptr, in.imageLoaderCache, 0, 0, /*isWeakDef=*/false, /*isExternal=*/false, /*isPrivateExtern=*/false, + /*includeInSymtab=*/true, /*isThumb=*/false, /*isReferencedDynamically=*/false, /*noDeadStrip=*/false); dyldPrivate->used = true; @@ -896,6 +897,9 @@ void SymtabSection::emitStabs() { assert(sym->isLive() && "dead symbols should not be in localSymbols, externalSymbols"); if (auto *defined = dyn_cast(sym)) { + // Excluded symbols should have been filtered out in finalizeContents(). + assert(defined->includeInSymtab); + if (defined->isAbsolute()) continue; @@ -909,10 +913,6 @@ void SymtabSection::emitStabs() { if (!file || !file->compileUnit) continue; - // All symbols that set includeInSymtab to false are synthetic symbols. - // Those have `file` set to nullptr and were already skipped due to that. - assert(defined->includeInSymtab); - symbolsNeedingStabs.push_back(defined); } } @@ -969,11 +969,10 @@ void SymtabSection::finalizeContents() { if (auto *objFile = dyn_cast(file)) { for (Symbol *sym : objFile->symbols) { if (auto *defined = dyn_cast_or_null(sym)) { - if (!defined->isExternal() && defined->isLive()) { - StringRef name = defined->getName(); - if (!name.startswith("l") && !name.startswith("L")) - addSymbol(localSymbols, sym); - } + if (defined->isExternal() || !defined->isLive() || + !defined->includeInSymtab) + continue; + addSymbol(localSymbols, sym); } } } diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index ace4bfe2ee09d9..475d8a04be33c0 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -270,6 +270,7 @@ void UnwindInfoSectionImpl::prepareRelocations(ConcatInputSection *isec) { s = make("", /*file=*/nullptr, referentIsec, r.addend, /*size=*/0, /*isWeakDef=*/false, /*isExternal=*/false, /*isPrivateExtern=*/false, + /*includeInSymtab=*/true, /*isThumb=*/false, /*isReferencedDynamically=*/false, /*noDeadStrip=*/false); in.got->addEntry(s);