[lld] b0211de - [ELF] Change Symbol::verdefIndex from uint32_t to uint16_t
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 15 17:59:35 PST 2021
Author: Fangrui Song
Date: 2021-12-15T17:59:30-08:00
New Revision: b0211de5e30a92aef68ceaf43e5042f610d7333f
URL: https://github.com/llvm/llvm-project/commit/b0211de5e30a92aef68ceaf43e5042f610d7333f
DIFF: https://github.com/llvm/llvm-project/commit/b0211de5e30a92aef68ceaf43e5042f610d7333f.diff
LOG: [ELF] Change Symbol::verdefIndex from uint32_t to uint16_t
The SHT_GNU_version index is 16-bit, so the 32-bit value is a waste.
Technically non-default version index 0x7fff uses version index 0xffff,
but it is impossible in practice.
This change decreases sizeof(SymbolUnion) from 80 to 72 on ELF64 platforms.
Memory usage decreases by 1% when linking a large executable.
Added:
Modified:
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index 9bb2e7ddaf51..ce77f9233fea 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -230,7 +230,7 @@ bool SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId,
// If the version has not been assigned, verdefIndex is -1. Use an arbitrary
// number (0) to indicate the version has been assigned.
- if (sym->verdefIndex == UINT32_C(-1)) {
+ if (sym->verdefIndex == uint16_t(-1)) {
sym->verdefIndex = 0;
sym->versionId = versionId;
}
@@ -249,7 +249,7 @@ void SymbolTable::assignWildcardVersion(SymbolVersion ver, uint16_t versionId,
// so we set a version to a symbol only if no version has been assigned
// to the symbol. This behavior is compatible with GNU.
for (Symbol *sym : findAllByVersion(ver, includeNonDefault))
- if (sym->verdefIndex == UINT32_C(-1)) {
+ if (sym->verdefIndex == uint16_t(-1)) {
sym->verdefIndex = 0;
sym->versionId = versionId;
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 5569bd8880c2..b0b7832135a7 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -86,7 +86,7 @@ class Symbol {
uint32_t globalDynIndex = -1;
// This field is a index to the symbol's version definition.
- uint32_t verdefIndex = -1;
+ uint16_t verdefIndex = -1;
// Version definition index.
uint16_t versionId;
@@ -365,7 +365,7 @@ class SharedSymbol : public Symbol {
SharedSymbol(InputFile &file, StringRef name, uint8_t binding,
uint8_t stOther, uint8_t type, uint64_t value, uint64_t size,
- uint32_t alignment, uint32_t verdefIndex)
+ uint32_t alignment, uint16_t verdefIndex)
: Symbol(SharedKind, &file, name, binding, stOther, type), value(value),
size(size), alignment(alignment) {
this->verdefIndex = verdefIndex;
@@ -487,9 +487,9 @@ union SymbolUnion {
};
// It is important to keep the size of SymbolUnion small for performance and
-// memory usage reasons. 80 bytes is a soft limit based on the size of Defined
+// memory usage reasons. 72 bytes is a soft limit based on the size of Defined
// on a 64-bit system.
-static_assert(sizeof(SymbolUnion) <= 80, "SymbolUnion too large");
+static_assert(sizeof(SymbolUnion) <= 72, "SymbolUnion too large");
template <typename T> struct AssertSymbol {
static_assert(std::is_trivially_destructible<T>(),
More information about the llvm-commits
mailing list