[lld] 4641d86 - [ELF] Shrink binding and type in Symbol
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 10:47:36 PDT 2022
Author: Shoaib Meenai
Date: 2022-04-20T10:46:36-07:00
New Revision: 4641d86e45bf752e24b0a8a28d48891cef566aff
URL: https://github.com/llvm/llvm-project/commit/4641d86e45bf752e24b0a8a28d48891cef566aff
DIFF: https://github.com/llvm/llvm-project/commit/4641d86e45bf752e24b0a8a28d48891cef566aff.diff
LOG: [ELF] Shrink binding and type in Symbol
STB_HIPROC and STT_HIPROC are both 15, so we can fit the symbol binding
and type in 4 bits. This gives us an additional byte to use for Symbol
flags (without increasing the type's size), which I'll be making use of
in the next diff.
Reorder type and binding based on a suggestion from @MaskRay, to
optimize st_info computation on little-endian systems (see
https://godbolt.org/z/nMn8Yar43).
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D124042
Added:
Modified:
lld/ELF/Symbols.h
Removed:
################################################################################
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 766c89b259a42..f968aeac0a2c3 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -73,15 +73,19 @@ class Symbol {
uint32_t nameSize;
public:
+ // The next three fields have the same meaning as the ELF symbol attributes.
+ // type and binding are placed in this order to optimize generating st_info,
+ // which is defined as (binding << 4) + (type & 0xf), on a little-endian
+ // system.
+ uint8_t type : 4; // symbol type
+
// 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.
// - An undefined weak will not extract archive members, but we have to
// remember it is weak.
- uint8_t binding;
+ uint8_t binding : 4;
- // The following fields have the same meaning as the ELF symbol attributes.
- uint8_t type; // symbol type
uint8_t stOther; // st_other field value
uint8_t symbolKind;
@@ -236,8 +240,8 @@ class Symbol {
protected:
Symbol(Kind k, InputFile *file, StringRef name, uint8_t binding,
uint8_t stOther, uint8_t type)
- : file(file), nameData(name.data()), nameSize(name.size()),
- binding(binding), type(type), stOther(stOther), symbolKind(k),
+ : file(file), nameData(name.data()), nameSize(name.size()), type(type),
+ binding(binding), stOther(stOther), symbolKind(k),
visibility(stOther & 3), isPreemptible(false),
isUsedInRegularObj(false), used(false), exportDynamic(false),
inDynamicList(false), referenced(false), traced(false),
More information about the llvm-commits
mailing list