Skip to content

Commit ac2911e

Browse files
committed
[ELF] Refactor how exportDynamic is set. NFC
1 parent 7288b85 commit ac2911e

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,6 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
16691669
uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL;
16701670
uint8_t type = objSym.isTLS() ? STT_TLS : STT_NOTYPE;
16711671
uint8_t visibility = mapVisibility(objSym.getVisibility());
1672-
bool canOmitFromDynSym = objSym.canBeOmittedFromSymbolTable();
16731672

16741673
StringRef name;
16751674
if (sym) {
@@ -1682,8 +1681,6 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
16821681
int c = objSym.getComdatIndex();
16831682
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
16841683
Undefined newSym(&f, name, binding, visibility, type);
1685-
if (canOmitFromDynSym)
1686-
newSym.exportDynamic = false;
16871684
sym->resolve(newSym);
16881685
sym->referenced = true;
16891686
return;
@@ -1695,7 +1692,7 @@ createBitcodeSymbol(Symbol *&sym, const std::vector<bool> &keptComdats,
16951692
objSym.getCommonSize()});
16961693
} else {
16971694
Defined newSym(&f, name, binding, visibility, type, 0, 0, nullptr);
1698-
if (canOmitFromDynSym)
1695+
if (objSym.canBeOmittedFromSymbolTable())
16991696
newSym.exportDynamic = false;
17001697
sym->resolve(newSym);
17011698
}

lld/ELF/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
254254
// Identify symbols exported dynamically, and that therefore could be
255255
// referenced by a shared library not visible to the linker.
256256
r.ExportDynamic = sym->computeBinding() != STB_LOCAL &&
257-
(sym->isExportDynamic(sym->kind()) ||
257+
(config->shared || config->exportDynamic ||
258258
sym->exportDynamic || sym->inDynamicList);
259259
const auto *dr = dyn_cast<Defined>(sym);
260260
r.FinalDefinitionInLinkageUnit =

lld/ELF/Symbols.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,6 @@ class Symbol {
228228
// non-lazy object causes a runtime error.
229229
void extract() const;
230230

231-
static bool isExportDynamic(Kind k) {
232-
return k == SharedKind || config->shared || config->exportDynamic;
233-
}
234-
235231
private:
236232
void resolveUndefined(const Undefined &other);
237233
void resolveCommon(const CommonSymbol &other);
@@ -250,14 +246,14 @@ class Symbol {
250246
binding(binding), type(type), stOther(stOther), symbolKind(k),
251247
visibility(stOther & 3),
252248
isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
253-
exportDynamic(isExportDynamic(k)), inDynamicList(false),
254-
canInline(false), referenced(false), traced(false),
255-
hasVersionSuffix(false), isInIplt(false), gotInIgot(false),
256-
isPreemptible(false), used(!config->gcSections), folded(false),
257-
needsTocRestore(false), scriptDefined(false), needsCopy(false),
258-
needsGot(false), needsPlt(false), needsTlsDesc(false),
259-
needsTlsGd(false), needsTlsGdToIe(false), needsTlsLd(false),
260-
needsGotDtprel(false), needsTlsIe(false), hasDirectReloc(false) {}
249+
exportDynamic(false), inDynamicList(false), canInline(false),
250+
referenced(false), traced(false), hasVersionSuffix(false),
251+
isInIplt(false), gotInIgot(false), isPreemptible(false),
252+
used(!config->gcSections), folded(false), needsTocRestore(false),
253+
scriptDefined(false), needsCopy(false), needsGot(false),
254+
needsPlt(false), needsTlsDesc(false), needsTlsGd(false),
255+
needsTlsGdToIe(false), needsTlsLd(false), needsGotDtprel(false),
256+
needsTlsIe(false), hasDirectReloc(false) {}
261257

262258
public:
263259
// True if this symbol is in the Iplt sub-section of the Plt and the Igot
@@ -330,7 +326,9 @@ class Defined : public Symbol {
330326
Defined(InputFile *file, StringRef name, uint8_t binding, uint8_t stOther,
331327
uint8_t type, uint64_t value, uint64_t size, SectionBase *section)
332328
: Symbol(DefinedKind, file, name, binding, stOther, type), value(value),
333-
size(size), section(section) {}
329+
size(size), section(section) {
330+
exportDynamic = config->shared || config->exportDynamic;
331+
}
334332

335333
static bool classof(const Symbol *s) { return s->isDefined(); }
336334

@@ -365,7 +363,9 @@ class CommonSymbol : public Symbol {
365363
CommonSymbol(InputFile *file, StringRef name, uint8_t binding,
366364
uint8_t stOther, uint8_t type, uint64_t alignment, uint64_t size)
367365
: Symbol(CommonKind, file, name, binding, stOther, type),
368-
alignment(alignment), size(size) {}
366+
alignment(alignment), size(size) {
367+
exportDynamic = config->shared || config->exportDynamic;
368+
}
369369

370370
static bool classof(const Symbol *s) { return s->isCommon(); }
371371

@@ -396,6 +396,7 @@ class SharedSymbol : public Symbol {
396396
: Symbol(SharedKind, &file, name, binding, stOther, type), value(value),
397397
size(size), alignment(alignment) {
398398
this->verdefIndex = verdefIndex;
399+
exportDynamic = true;
399400
// GNU ifunc is a mechanism to allow user-supplied functions to
400401
// resolve PLT slot values at load-time. This is contrary to the
401402
// regular symbol resolution scheme in which symbols are resolved just

0 commit comments

Comments
 (0)