[ELF] Refactor how exportDynamic is set. NFC

This commit is contained in:
Fangrui Song 2022-02-05 10:25:25 -08:00
parent 7288b85cc8
commit ac2911e738
3 changed files with 17 additions and 19 deletions

View File

@ -1669,7 +1669,6 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL;
uint8_t type = objSym.isTLS() ? STT_TLS : STT_NOTYPE;
uint8_t visibility = mapVisibility(objSym.getVisibility());
bool canOmitFromDynSym = objSym.canBeOmittedFromSymbolTable();
StringRef name;
if (sym) {
@ -1682,8 +1681,6 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
int c = objSym.getComdatIndex();
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
Undefined newSym(&f, name, binding, visibility, type);
if (canOmitFromDynSym)
newSym.exportDynamic = false;
sym->resolve(newSym);
sym->referenced = true;
return;
@ -1695,7 +1692,7 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
objSym.getCommonSize()});
} else {
Defined newSym(&f, name, binding, visibility, type, 0, 0, nullptr);
if (canOmitFromDynSym)
if (objSym.canBeOmittedFromSymbolTable())
newSym.exportDynamic = false;
sym->resolve(newSym);
}

View File

@ -254,7 +254,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
// Identify symbols exported dynamically, and that therefore could be
// referenced by a shared library not visible to the linker.
r.ExportDynamic = sym->computeBinding() != STB_LOCAL &&
(sym->isExportDynamic(sym->kind()) ||
(config->shared || config->exportDynamic ||
sym->exportDynamic || sym->inDynamicList);
const auto *dr = dyn_cast<Defined>(sym);
r.FinalDefinitionInLinkageUnit =

View File

@ -228,10 +228,6 @@ public:
// non-lazy object causes a runtime error.
void extract() const;
static bool isExportDynamic(Kind k) {
return k == SharedKind || config->shared || config->exportDynamic;
}
private:
void resolveUndefined(const Undefined &other);
void resolveCommon(const CommonSymbol &other);
@ -250,14 +246,14 @@ protected:
binding(binding), type(type), stOther(stOther), symbolKind(k),
visibility(stOther & 3),
isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
exportDynamic(isExportDynamic(k)), inDynamicList(false),
canInline(false), referenced(false), traced(false),
hasVersionSuffix(false), isInIplt(false), gotInIgot(false),
isPreemptible(false), used(!config->gcSections), folded(false),
needsTocRestore(false), scriptDefined(false), needsCopy(false),
needsGot(false), needsPlt(false), needsTlsDesc(false),
needsTlsGd(false), needsTlsGdToIe(false), needsTlsLd(false),
needsGotDtprel(false), needsTlsIe(false), hasDirectReloc(false) {}
exportDynamic(false), inDynamicList(false), canInline(false),
referenced(false), traced(false), hasVersionSuffix(false),
isInIplt(false), gotInIgot(false), isPreemptible(false),
used(!config->gcSections), folded(false), needsTocRestore(false),
scriptDefined(false), needsCopy(false), needsGot(false),
needsPlt(false), needsTlsDesc(false), needsTlsGd(false),
needsTlsGdToIe(false), needsTlsLd(false), needsGotDtprel(false),
needsTlsIe(false), hasDirectReloc(false) {}
public:
// True if this symbol is in the Iplt sub-section of the Plt and the Igot
@ -330,7 +326,9 @@ public:
Defined(InputFile *file, StringRef name, uint8_t binding, uint8_t stOther,
uint8_t type, uint64_t value, uint64_t size, SectionBase *section)
: Symbol(DefinedKind, file, name, binding, stOther, type), value(value),
size(size), section(section) {}
size(size), section(section) {
exportDynamic = config->shared || config->exportDynamic;
}
static bool classof(const Symbol *s) { return s->isDefined(); }
@ -365,7 +363,9 @@ public:
CommonSymbol(InputFile *file, StringRef name, uint8_t binding,
uint8_t stOther, uint8_t type, uint64_t alignment, uint64_t size)
: Symbol(CommonKind, file, name, binding, stOther, type),
alignment(alignment), size(size) {}
alignment(alignment), size(size) {
exportDynamic = config->shared || config->exportDynamic;
}
static bool classof(const Symbol *s) { return s->isCommon(); }
@ -396,6 +396,7 @@ public:
: Symbol(SharedKind, &file, name, binding, stOther, type), value(value),
size(size), alignment(alignment) {
this->verdefIndex = verdefIndex;
exportDynamic = true;
// GNU ifunc is a mechanism to allow user-supplied functions to
// resolve PLT slot values at load-time. This is contrary to the
// regular symbol resolution scheme in which symbols are resolved just