mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-13 13:45:16 +00:00
[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
This commit is contained in:
parent
a2b212bafc
commit
1cff723ff5
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user