[lld] 73f55fb - [ELF] Reorder Symbol members to improve access locality. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 5 15:47:10 PST 2022
Author: Fangrui Song
Date: 2022-02-05T14:11:37-08:00
New Revision: 73f55fba7651e4a08e95ed7153e30b6eeaab2ab7
URL: https://github.com/llvm/llvm-project/commit/73f55fba7651e4a08e95ed7153e30b6eeaab2ab7
DIFF: https://github.com/llvm/llvm-project/commit/73f55fba7651e4a08e95ed7153e30b6eeaab2ab7.diff
LOG: [ELF] Reorder Symbol members to improve access locality. NFC
* partition and isPreemptible are frequently used. Move it to the front
* move used beside isUsedInRegularObj. They are similar and accessed together in .symtab finalizing
* move auxIdx/dynsymIndex/verdefIndex to the end.
This decreases code size.
Added:
Modified:
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 36f838a751ab7..58f8bc8cab401 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -84,7 +84,7 @@ Symbol *SymbolTable::insert(StringRef name) {
// when it is a placeholder must be initialized here.
sym->setName(name);
sym->symbolKind = Symbol::PlaceholderKind;
- sym->versionId = VER_NDX_GLOBAL;
+ sym->partition = 1;
sym->visibility = STV_DEFAULT;
sym->isUsedInRegularObj = false;
sym->exportDynamic = false;
@@ -92,9 +92,9 @@ Symbol *SymbolTable::insert(StringRef name) {
sym->referenced = false;
sym->traced = false;
sym->scriptDefined = false;
+ sym->versionId = VER_NDX_GLOBAL;
if (pos != StringRef::npos)
sym->hasVersionSuffix = true;
- sym->partition = 1;
return sym;
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index d04454cc8749a..d8970c51ad59e 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -77,17 +77,6 @@ class Symbol {
uint32_t nameSize;
public:
- // A symAux index used to access GOT/PLT entry indexes. This is allocated in
- // postScanRelocations().
- uint32_t auxIdx = -1;
- uint32_t dynsymIndex = 0;
-
- // This field is a index to the symbol's version definition.
- uint16_t verdefIndex = -1;
-
- // Version definition index.
- uint16_t versionId;
-
// Symbol binding. This is not overwritten by replace() to track
// changes during resolution. In particular:
// - An undefined weak is still weak when it resolves to a shared library.
@@ -101,16 +90,28 @@ class Symbol {
uint8_t symbolKind;
+ // The partition whose dynamic symbol table contains this symbol's definition.
+ uint8_t partition = 1;
+
// Symbol visibility. This is the computed minimum visibility of all
// observed non-DSO symbols.
uint8_t visibility : 2;
+ // True if this symbol is preemptible at load time.
+ uint8_t isPreemptible : 1;
+
// True if the symbol was used for linking and thus need to be added to the
// output file's symbol table. This is true for all symbols except for
// unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that
// are unreferenced except by other bitcode objects.
uint8_t isUsedInRegularObj : 1;
+ // True if an undefined or shared symbol is used from a live section.
+ //
+ // NOTE: In Writer.cpp the field is used to mark local defined symbols
+ // which are referenced by relocations when -r or --emit-relocs is given.
+ uint8_t used : 1;
+
// Used by a Defined symbol with protected or default visibility, to record
// whether it is required to be exported into .dynsym. This is set when any of
// the following conditions hold:
@@ -239,11 +240,11 @@ class Symbol {
uint8_t stOther, uint8_t type)
: file(file), nameData(name.data()), nameSize(name.size()),
binding(binding), type(type), stOther(stOther), symbolKind(k),
- visibility(stOther & 3),
+ visibility(stOther & 3), isPreemptible(false),
isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
- exportDynamic(false), inDynamicList(false), referenced(false),
- traced(false), hasVersionSuffix(false), isInIplt(false),
- gotInIgot(false), isPreemptible(false), used(false), folded(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), needsTlsLd(false),
@@ -258,15 +259,6 @@ class Symbol {
// Igot. This will be true only for certain non-preemptible ifuncs.
uint8_t gotInIgot : 1;
- // True if this symbol is preemptible at load time.
- uint8_t isPreemptible : 1;
-
- // True if an undefined or shared symbol is used from a live section.
- //
- // NOTE: In Writer.cpp the field is used to mark local defined symbols
- // which are referenced by relocations when -r or --emit-relocs is given.
- uint8_t used : 1;
-
// True if defined relative to a section discarded by ICF.
uint8_t folded : 1;
@@ -296,6 +288,17 @@ class Symbol {
uint8_t needsTlsIe : 1;
uint8_t hasDirectReloc : 1;
+ // A symAux index used to access GOT/PLT entry indexes. This is allocated in
+ // postScanRelocations().
+ uint32_t auxIdx = -1;
+ uint32_t dynsymIndex = 0;
+
+ // This field is a index to the symbol's version definition.
+ uint16_t verdefIndex = -1;
+
+ // Version definition index.
+ uint16_t versionId;
+
bool needsDynReloc() const {
return needsCopy || needsGot || needsPlt || needsTlsDesc || needsTlsGd ||
needsTlsGdToIe || needsTlsLd || needsGotDtprel || needsTlsIe;
@@ -306,9 +309,6 @@ class Symbol {
symAux.emplace_back();
}
- // The partition whose dynamic symbol table contains this symbol's definition.
- uint8_t partition = 1;
-
bool isSection() const { return type == llvm::ELF::STT_SECTION; }
bool isTls() const { return type == llvm::ELF::STT_TLS; }
bool isFunc() const { return type == llvm::ELF::STT_FUNC; }
@@ -581,17 +581,17 @@ void Symbol::replace(const Symbol &newSym) {
// old may be a placeholder. The referenced fields must be initialized in
// SymbolTable::insert.
- versionId = old.versionId;
+ partition = old.partition;
visibility = old.visibility;
+ isPreemptible = old.isPreemptible;
isUsedInRegularObj = old.isUsedInRegularObj;
exportDynamic = old.exportDynamic;
inDynamicList = old.inDynamicList;
referenced = old.referenced;
traced = old.traced;
hasVersionSuffix = old.hasVersionSuffix;
- isPreemptible = old.isPreemptible;
scriptDefined = old.scriptDefined;
- partition = old.partition;
+ versionId = old.versionId;
// Print out a log message if --trace-symbol was specified.
// This is for debugging.
More information about the llvm-commits
mailing list