diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -328,15 +328,15 @@ std::to_string(thunkInfo.sequence++)); if (!isa(funcSym) || cast(funcSym)->isExternal()) { r.referent = thunkInfo.sym = symtab->addDefined( - thunkName, /*file=*/nullptr, thunkInfo.isec, /*value=*/0, - thunkSize, /*isWeakDef=*/false, /*isPrivateExtern=*/true, + thunkName, /*file=*/nullptr, thunkInfo.isec, /*value=*/0, thunkSize, + /*isWeakDef=*/false, /*isPrivateExtern=*/true, /*isThumb=*/false, /*isReferencedDynamically=*/false, /*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 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -530,14 +530,11 @@ // 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 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -636,9 +636,10 @@ } 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 @@ 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 --- a/lld/MachO/SymbolTable.cpp +++ b/lld/MachO/SymbolTable.cpp @@ -103,8 +103,9 @@ !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; } @@ -230,12 +231,11 @@ uint64_t value, bool isPrivateExtern, bool includeInSymtab, bool referencedDynamically) { - 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.h b/lld/MachO/Symbols.h --- a/lld/MachO/Symbols.h +++ b/lld/MachO/Symbols.h @@ -117,9 +117,9 @@ 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/Symbols.cpp b/lld/MachO/Symbols.cpp --- a/lld/MachO/Symbols.cpp +++ b/lld/MachO/Symbols.cpp @@ -42,12 +42,12 @@ 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/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -634,6 +634,7 @@ 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 @@ 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 @@ 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 @@ 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 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -307,6 +307,7 @@ 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);