[lld] 8ca46bb - [ELF] Move isUsedInRegularObj assignment from ctor to call sites. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 23 21:32:56 PST 2022
Author: Fangrui Song
Date: 2022-02-23T21:32:50-08:00
New Revision: 8ca46bba23552e04a704daaac87212b554ed7c93
URL: https://github.com/llvm/llvm-project/commit/8ca46bba23552e04a704daaac87212b554ed7c93
DIFF: https://github.com/llvm/llvm-project/commit/8ca46bba23552e04a704daaac87212b554ed7c93.diff
LOG: [ELF] Move isUsedInRegularObj assignment from ctor to call sites. NFC
This removes the tricky
`isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind)`
and the copy from `Symbol::mergeProperties`.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index d34ee094506d..7978082f86cf 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1958,16 +1958,9 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
sym->partition = newPart.getNumber();
}
-static Symbol *addUndefined(StringRef name) {
- return symtab->addSymbol(
- Undefined{nullptr, name, STB_GLOBAL, STV_DEFAULT, 0});
-}
-
static Symbol *addUnusedUndefined(StringRef name,
uint8_t binding = STB_GLOBAL) {
- Undefined sym{nullptr, name, binding, STV_DEFAULT, 0};
- sym.isUsedInRegularObj = false;
- return symtab->addSymbol(sym);
+ return symtab->addSymbol(Undefined{nullptr, name, binding, STV_DEFAULT, 0});
}
static void markBuffersAsDontNeed(bool skipLinkedOutput) {
@@ -2319,7 +2312,7 @@ void LinkerDriver::link(opt::InputArgList &args) {
// Some symbols (such as __ehdr_start) are defined lazily only when there
// are undefined symbols for them, so we add these to trigger that logic.
for (StringRef name : script->referencedSymbols)
- addUndefined(name);
+ addUnusedUndefined(name)->isUsedInRegularObj = true;
// Prevent LTO from removing any definition referenced by -u.
for (StringRef name : config->undefined)
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index ba1d7944c58e..adedb1611c08 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1054,6 +1054,7 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
else
new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
eSym.st_value, eSym.st_size, sec);
+ symbols[i]->isUsedInRegularObj = true;
}
// Some entries have been filled by LazyObjFile.
@@ -1091,6 +1092,7 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
uint64_t size = eSym.st_size;
Symbol *sym = symbols[i];
+ sym->isUsedInRegularObj = true;
if (LLVM_UNLIKELY(eSym.st_shndx == SHN_COMMON)) {
if (value == 0 || value >= UINT32_MAX)
fatal(toString(this) + ": common symbol '" + sym->getName() +
@@ -1113,12 +1115,9 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
// extract. We should demote the lazy symbol to an Undefined so that any
// relocations outside of the group to it will trigger a discarded section
// error.
- if (sym->symbolKind == Symbol::LazyObjectKind && !sym->file->lazy) {
+ if (sym->symbolKind == Symbol::LazyObjectKind && !sym->file->lazy)
sym->replace(und);
- // Prevent LTO from internalizing the symbol in case there is a
- // reference to this symbol from this file.
- sym->isUsedInRegularObj = true;
- } else
+ else
sym->resolve(und);
continue;
}
@@ -1145,6 +1144,7 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
Symbol *sym = symbols[i];
sym->resolve(Undefined{this, StringRef(), eSym.getBinding(), eSym.st_other,
eSym.getType()});
+ sym->isUsedInRegularObj = true;
sym->referenced = true;
}
}
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index d5cfc34d9eaa..88eb2b263224 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -239,6 +239,7 @@ void LinkerScript::addSymbol(SymbolAssignment *cmd) {
Symbol *sym = symtab->insert(cmd->name);
sym->mergeProperties(newSym);
sym->replace(newSym);
+ sym->isUsedInRegularObj = true;
cmd->sym = cast<Defined>(sym);
}
@@ -259,6 +260,7 @@ static void declareSymbol(SymbolAssignment *cmd) {
cmd->sym = cast<Defined>(sym);
cmd->provide = false;
+ sym->isUsedInRegularObj = true;
sym->scriptDefined = true;
}
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 7a24f8ede31a..e92d4f8bd569 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -110,6 +110,7 @@ Symbol *SymbolTable::addAndCheckDuplicate(const Defined &newSym) {
if (sym->isDefined())
sym->checkDuplicate(newSym);
sym->resolve(newSym);
+ sym->isUsedInRegularObj = true;
return sym;
}
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 9b231ba46a56..6bf63c25225e 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -385,8 +385,6 @@ static uint8_t getMinVisibility(uint8_t va, uint8_t vb) {
void Symbol::mergeProperties(const Symbol &other) {
if (other.exportDynamic)
exportDynamic = true;
- if (other.isUsedInRegularObj)
- isUsedInRegularObj = true;
// DSO symbols do not affect visibility in the output.
if (!other.isShared())
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index e7010de4919b..d2ce34d4bba1 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -238,12 +238,11 @@ class Symbol {
: file(file), nameData(name.data()), nameSize(name.size()),
binding(binding), type(type), stOther(stOther), symbolKind(k),
visibility(stOther & 3), isPreemptible(false),
- isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
- used(false), exportDynamic(false), inDynamicList(false),
- referenced(false), traced(false), hasVersionSuffix(false),
- isInIplt(false), gotInIgot(false), folded(false),
- needsTocRestore(false), scriptDefined(false), needsCopy(false),
- needsGot(false), needsPlt(false), needsTlsDesc(false),
+ isUsedInRegularObj(false), used(false), exportDynamic(false),
+ inDynamicList(false), referenced(false), traced(false),
+ hasVersionSuffix(false), isInIplt(false), gotInIgot(false),
+ folded(false), needsTocRestore(false), scriptDefined(false),
+ needsCopy(false), needsGot(false), needsPlt(false), needsTlsDesc(false),
needsTlsGd(false), needsTlsGdToIe(false), needsGotDtprel(false),
needsTlsIe(false), hasDirectReloc(false) {}
@@ -427,9 +426,7 @@ class LazyObject : public Symbol {
public:
LazyObject(InputFile &file)
: Symbol(LazyObjectKind, &file, {}, llvm::ELF::STB_GLOBAL,
- llvm::ELF::STV_DEFAULT, llvm::ELF::STT_NOTYPE) {
- isUsedInRegularObj = false;
- }
+ llvm::ELF::STV_DEFAULT, llvm::ELF::STT_NOTYPE) {}
static bool classof(const Symbol *s) { return s->kind() == LazyObjectKind; }
};
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index f690711af5c1..59177ffcacf5 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -171,12 +171,14 @@ static Defined *addOptionalRegular(StringRef name, SectionBase *sec,
s->resolve(Defined{nullptr, StringRef(), STB_GLOBAL, stOther, STT_NOTYPE, val,
/*size=*/0, sec});
+ s->isUsedInRegularObj = true;
return cast<Defined>(s);
}
static Defined *addAbsolute(StringRef name) {
Symbol *sym = symtab->addSymbol(Defined{nullptr, name, STB_GLOBAL, STV_HIDDEN,
STT_NOTYPE, 0, 0, nullptr});
+ sym->isUsedInRegularObj = true;
return cast<Defined>(sym);
}
@@ -1830,9 +1832,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
// Even the author of gold doesn't remember why gold behaves that way.
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
if (mainPart->dynamic->parent)
- symtab->addSymbol(
- Defined{/*file=*/nullptr, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
- /*value=*/0, /*size=*/0, mainPart->dynamic.get()});
+ symtab->addSymbol(Defined{/*file=*/nullptr, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
+ /*value=*/0, /*size=*/0, mainPart->dynamic.get()})->isUsedInRegularObj = true;
// Define __rel[a]_iplt_{start,end} symbols if needed.
addRelIpltSymbols();
More information about the llvm-commits
mailing list