diff options
author | Jez Ng <jezng@fb.com> | 2022-04-11 22:45:25 +0300 |
---|---|---|
committer | Jez Ng <jezng@fb.com> | 2022-04-11 22:45:46 +0300 |
commit | 1cff723ff527030295d84d3bb52d4d0b7cddb43a (patch) | |
tree | c3ac0d6271599a707687fcc21abd9e697a07f5c4 /lld | |
parent | a2b212bafc9508e54f94b1dce7a46e21ff9b5e91 (diff) |
[lld-macho][nfc] Use includeInSymtab for all symtab-skipping logic
{D123302} got me looking deeper at `includeInSymtab`. I thought it was a
little odd that there were excluded (live) symbols for which
`includeInSymtab` was false; we shouldn't have so many different ways to
exclude a symbol. As such, this diff makes the `L`-prefixed-symbol
exclusion code use `includeInSymtab` too. (Note that as part of our
support for `__eh_frame`, we will also be excluding all `__eh_frame`
symbols from the symtab in a future diff.)
Another thing I noticed is that the `emitStabs` code never has to deal
with excluded symbols because `SymtabSection::finalize()` already
filters them out. As such, I've updated the comments and asserts from
{D123302} to reflect this.
Reviewed By: #lld-macho, thakis
Differential Revision: https://reviews.llvm.org/D123433
Diffstat (limited to 'lld')
-rw-r--r-- | lld/MachO/ConcatOutputSection.cpp | 6 | ||||
-rw-r--r-- | lld/MachO/Driver.cpp | 13 | ||||
-rw-r--r-- | lld/MachO/InputFiles.cpp | 5 | ||||
-rw-r--r-- | lld/MachO/SymbolTable.cpp | 11 | ||||
-rw-r--r-- | lld/MachO/Symbols.cpp | 4 | ||||
-rw-r--r-- | lld/MachO/Symbols.h | 6 | ||||
-rw-r--r-- | lld/MachO/SyntheticSections.cpp | 17 | ||||
-rw-r--r-- | lld/MachO/UnwindInfoSection.cpp | 1 |
8 files changed, 31 insertions, 32 deletions
diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp index 5b2ea4424328..27db6cc5d40d 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<Defined>( - 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 2661c7071212..ae974a5e34d7 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<Defined>(sym, sym->getName(), common->getFile(), isec, - /*value=*/0, - /*size=*/0, - /*isWeakDef=*/false, - /*isExternal=*/true, common->privateExtern, - /*isThumb=*/false, - /*isReferencedDynamically=*/false, - /*noDeadStrip=*/false); + replaceSymbol<Defined>( + 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 8423fb8bb9be..4e37bad92361 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<Defined>( 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<Defined>(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 a3e32537dc4f..113b4dba7f34 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<Defined>( 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 16868adcdfa9..31ee4c65fe6d 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 211983f0790f..7dbab691c564 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 8ed6f5c2d51c..7e1d92b3bad8 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -634,6 +634,7 @@ void StubHelperSection::setup() { make<Defined>("__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<Defined>(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<ObjFile>(file)) { for (Symbol *sym : objFile->symbols) { if (auto *defined = dyn_cast_or_null<Defined>(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 ace4bfe2ee09..475d8a04be33 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -270,6 +270,7 @@ void UnwindInfoSectionImpl<Ptr>::prepareRelocations(ConcatInputSection *isec) { s = make<Defined>("<internal>", /*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); |