Skip to content

Commit 1cff723

Browse files
committed
[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
1 parent a2b212b commit 1cff723

File tree

8 files changed

+31
-32
lines changed

8 files changed

+31
-32
lines changed

lld/MachO/ConcatOutputSection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ void TextOutputSection::finalize() {
334334
/*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
335335
} else {
336336
r.referent = thunkInfo.sym = make<Defined>(
337-
thunkName, /*file=*/nullptr, thunkInfo.isec, /*value=*/0,
338-
thunkSize, /*isWeakDef=*/false, /*isExternal=*/false,
339-
/*isPrivateExtern=*/true, /*isThumb=*/false,
337+
thunkName, /*file=*/nullptr, thunkInfo.isec, /*value=*/0, thunkSize,
338+
/*isWeakDef=*/false, /*isExternal=*/false, /*isPrivateExtern=*/true,
339+
/*includeInSymtab=*/true, /*isThumb=*/false,
340340
/*isReferencedDynamically=*/false, /*noDeadStrip=*/false,
341341
/*isWeakDefCanBeHidden=*/false);
342342
}

lld/MachO/Driver.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,11 @@ static void replaceCommonSymbols() {
530530

531531
// FIXME: CommonSymbol should store isReferencedDynamically, noDeadStrip
532532
// and pass them on here.
533-
replaceSymbol<Defined>(sym, sym->getName(), common->getFile(), isec,
534-
/*value=*/0,
535-
/*size=*/0,
536-
/*isWeakDef=*/false,
537-
/*isExternal=*/true, common->privateExtern,
538-
/*isThumb=*/false,
539-
/*isReferencedDynamically=*/false,
540-
/*noDeadStrip=*/false);
533+
replaceSymbol<Defined>(
534+
sym, sym->getName(), common->getFile(), isec, /*value=*/0, /*size=*/0,
535+
/*isWeakDef=*/false, /*isExternal=*/true, common->privateExtern,
536+
/*includeInSymtab=*/true, /*isThumb=*/false,
537+
/*isReferencedDynamically=*/false, /*noDeadStrip=*/false);
541538
}
542539
}
543540

lld/MachO/InputFiles.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,10 @@ static macho::Symbol *createDefined(const NList &sym, StringRef name,
636636
}
637637
assert(!isWeakDefCanBeHidden &&
638638
"weak_def_can_be_hidden on already-hidden symbol?");
639+
bool includeInSymtab = !name.startswith("l") && !name.startswith("L");
639640
return make<Defined>(
640641
name, isec->getFile(), isec, value, size, sym.n_desc & N_WEAK_DEF,
641-
/*isExternal=*/false, /*isPrivateExtern=*/false,
642+
/*isExternal=*/false, /*isPrivateExtern=*/false, includeInSymtab,
642643
sym.n_desc & N_ARM_THUMB_DEF, sym.n_desc & REFERENCED_DYNAMICALLY,
643644
sym.n_desc & N_NO_DEAD_STRIP);
644645
}
@@ -658,7 +659,7 @@ static macho::Symbol *createAbsolute(const NList &sym, InputFile *file,
658659
return make<Defined>(name, file, nullptr, sym.n_value, /*size=*/0,
659660
/*isWeakDef=*/false,
660661
/*isExternal=*/false, /*isPrivateExtern=*/false,
661-
sym.n_desc & N_ARM_THUMB_DEF,
662+
/*includeInSymtab=*/true, sym.n_desc & N_ARM_THUMB_DEF,
662663
/*isReferencedDynamically=*/false,
663664
sym.n_desc & N_NO_DEAD_STRIP);
664665
}

lld/MachO/SymbolTable.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ Defined *SymbolTable::addDefined(StringRef name, InputFile *file,
103103
!isPrivateExtern;
104104
Defined *defined = replaceSymbol<Defined>(
105105
s, name, file, isec, value, size, isWeakDef, /*isExternal=*/true,
106-
isPrivateExtern, isThumb, isReferencedDynamically, noDeadStrip,
107-
overridesWeakDef, isWeakDefCanBeHidden, interposable);
106+
isPrivateExtern, /*includeInSymtab=*/true, isThumb,
107+
isReferencedDynamically, noDeadStrip, overridesWeakDef,
108+
isWeakDefCanBeHidden, interposable);
108109
return defined;
109110
}
110111

@@ -233,9 +234,9 @@ Defined *SymbolTable::addSynthetic(StringRef name, InputSection *isec,
233234
assert(!isec || !isec->getFile()); // See makeSyntheticInputSection().
234235
Defined *s =
235236
addDefined(name, /*file=*/nullptr, isec, value, /*size=*/0,
236-
/*isWeakDef=*/false, isPrivateExtern,
237-
/*isThumb=*/false, referencedDynamically,
238-
/*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
237+
/*isWeakDef=*/false, isPrivateExtern, /*isThumb=*/false,
238+
referencedDynamically, /*noDeadStrip=*/false,
239+
/*isWeakDefCanBeHidden=*/false);
239240
s->includeInSymtab = includeInSymtab;
240241
return s;
241242
}

lld/MachO/Symbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ uint64_t Symbol::getTlvVA() const { return in.tlvPointers->getVA(gotIndex); }
4242
4343
Defined::Defined(StringRefZ name, InputFile *file, InputSection *isec,
4444
uint64_t value, uint64_t size, bool isWeakDef, bool isExternal,
45-
bool isPrivateExtern, bool isThumb,
45+
bool isPrivateExtern, bool includeInSymtab, bool isThumb,
4646
bool isReferencedDynamically, bool noDeadStrip,
4747
bool canOverrideWeakDef, bool isWeakDefCanBeHidden,
4848
bool interposable)
4949
: Symbol(DefinedKind, name, file), overridesWeakDef(canOverrideWeakDef),
50-
privateExtern(isPrivateExtern), includeInSymtab(true),
50+
privateExtern(isPrivateExtern), includeInSymtab(includeInSymtab),
5151
wasIdenticalCodeFolded(false), thumb(isThumb),
5252
referencedDynamically(isReferencedDynamically), noDeadStrip(noDeadStrip),
5353
interposable(interposable), weakDefCanBeHidden(isWeakDefCanBeHidden),

lld/MachO/Symbols.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ class Defined : public Symbol {
117117
public:
118118
Defined(StringRefZ name, InputFile *file, InputSection *isec, uint64_t value,
119119
uint64_t size, bool isWeakDef, bool isExternal, bool isPrivateExtern,
120-
bool isThumb, bool isReferencedDynamically, bool noDeadStrip,
121-
bool canOverrideWeakDef = false, bool isWeakDefCanBeHidden = false,
122-
bool interposable = false);
120+
bool includeInSymtab, bool isThumb, bool isReferencedDynamically,
121+
bool noDeadStrip, bool canOverrideWeakDef = false,
122+
bool isWeakDefCanBeHidden = false, bool interposable = false);
123123

124124
bool isWeakDef() const override { return weakDef; }
125125
bool isExternalWeakDef() const {

lld/MachO/SyntheticSections.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ void StubHelperSection::setup() {
634634
make<Defined>("__dyld_private", nullptr, in.imageLoaderCache, 0, 0,
635635
/*isWeakDef=*/false,
636636
/*isExternal=*/false, /*isPrivateExtern=*/false,
637+
/*includeInSymtab=*/true,
637638
/*isThumb=*/false, /*isReferencedDynamically=*/false,
638639
/*noDeadStrip=*/false);
639640
dyldPrivate->used = true;
@@ -896,6 +897,9 @@ void SymtabSection::emitStabs() {
896897
assert(sym->isLive() &&
897898
"dead symbols should not be in localSymbols, externalSymbols");
898899
if (auto *defined = dyn_cast<Defined>(sym)) {
900+
// Excluded symbols should have been filtered out in finalizeContents().
901+
assert(defined->includeInSymtab);
902+
899903
if (defined->isAbsolute())
900904
continue;
901905

@@ -909,10 +913,6 @@ void SymtabSection::emitStabs() {
909913
if (!file || !file->compileUnit)
910914
continue;
911915

912-
// All symbols that set includeInSymtab to false are synthetic symbols.
913-
// Those have `file` set to nullptr and were already skipped due to that.
914-
assert(defined->includeInSymtab);
915-
916916
symbolsNeedingStabs.push_back(defined);
917917
}
918918
}
@@ -969,11 +969,10 @@ void SymtabSection::finalizeContents() {
969969
if (auto *objFile = dyn_cast<ObjFile>(file)) {
970970
for (Symbol *sym : objFile->symbols) {
971971
if (auto *defined = dyn_cast_or_null<Defined>(sym)) {
972-
if (!defined->isExternal() && defined->isLive()) {
973-
StringRef name = defined->getName();
974-
if (!name.startswith("l") && !name.startswith("L"))
975-
addSymbol(localSymbols, sym);
976-
}
972+
if (defined->isExternal() || !defined->isLive() ||
973+
!defined->includeInSymtab)
974+
continue;
975+
addSymbol(localSymbols, sym);
977976
}
978977
}
979978
}

lld/MachO/UnwindInfoSection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ void UnwindInfoSectionImpl<Ptr>::prepareRelocations(ConcatInputSection *isec) {
270270
s = make<Defined>("<internal>", /*file=*/nullptr, referentIsec,
271271
r.addend, /*size=*/0, /*isWeakDef=*/false,
272272
/*isExternal=*/false, /*isPrivateExtern=*/false,
273+
/*includeInSymtab=*/true,
273274
/*isThumb=*/false, /*isReferencedDynamically=*/false,
274275
/*noDeadStrip=*/false);
275276
in.got->addEntry(s);

0 commit comments

Comments
 (0)