Skip to content

Commit

Permalink
[lld][ELF] Annotate Bitfields with Preferred Types (llvm#97737)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenary committed Jul 5, 2024
1 parent e2cee2c commit f542796
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lld/ELF/InputSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ class SectionBase {

Kind kind() const { return (Kind)sectionKind; }

LLVM_PREFERRED_TYPE(Kind)
uint8_t sectionKind : 3;

// The next two bit fields are only used by InputSectionBase, but we
// put them here so the struct packs better.

LLVM_PREFERRED_TYPE(bool)
uint8_t bss : 1;

// Set for sections that should not be folded by ICF.
LLVM_PREFERRED_TYPE(bool)
uint8_t keepUnique : 1;

uint8_t partition = 1;
Expand Down Expand Up @@ -282,6 +285,7 @@ struct SectionPiece {
: inputOff(off), live(live), hash(hash >> 1) {}

uint32_t inputOff;
LLVM_PREFERRED_TYPE(bool)
uint32_t live : 1;
uint32_t hash : 31;
uint64_t outputOff = 0;
Expand Down
18 changes: 18 additions & 0 deletions lld/ELF/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,21 @@ class Symbol {
uint8_t partition;

// True if this symbol is preemptible at load time.
LLVM_PREFERRED_TYPE(bool)
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.
LLVM_PREFERRED_TYPE(bool)
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.
LLVM_PREFERRED_TYPE(bool)
uint8_t used : 1;

// Used by a Defined symbol with protected or default visibility, to record
Expand All @@ -138,27 +141,33 @@ class Symbol {
// - If -shared or --export-dynamic is specified, any symbol in an object
// file/bitcode sets this property, unless suppressed by LTO
// canBeOmittedFromSymbolTable().
LLVM_PREFERRED_TYPE(bool)
uint8_t exportDynamic : 1;

// True if the symbol is in the --dynamic-list file. A Defined symbol with
// protected or default visibility with this property is required to be
// exported into .dynsym.
LLVM_PREFERRED_TYPE(bool)
uint8_t inDynamicList : 1;

// Used to track if there has been at least one undefined reference to the
// symbol. For Undefined and SharedSymbol, the binding may change to STB_WEAK
// if the first undefined reference from a non-shared object is weak.
LLVM_PREFERRED_TYPE(bool)
uint8_t referenced : 1;

// Used to track if this symbol will be referenced after wrapping is performed
// (i.e. this will be true for foo if __real_foo is referenced, and will be
// true for __wrap_foo if foo is referenced).
LLVM_PREFERRED_TYPE(bool)
uint8_t referencedAfterWrap : 1;

// True if this symbol is specified by --trace-symbol option.
LLVM_PREFERRED_TYPE(bool)
uint8_t traced : 1;

// True if the name contains '@'.
LLVM_PREFERRED_TYPE(bool)
uint8_t hasVersionSuffix : 1;

// Symbol visibility. This is the computed minimum visibility of all
Expand Down Expand Up @@ -270,20 +279,24 @@ class Symbol {
public:
// True if this symbol is in the Iplt sub-section of the Plt and the Igot
// sub-section of the .got.plt or .got.
LLVM_PREFERRED_TYPE(bool)
uint8_t isInIplt : 1;

// True if this symbol needs a GOT entry and its GOT entry is actually in
// Igot. This will be true only for certain non-preemptible ifuncs.
LLVM_PREFERRED_TYPE(bool)
uint8_t gotInIgot : 1;

// True if defined relative to a section discarded by ICF.
LLVM_PREFERRED_TYPE(bool)
uint8_t folded : 1;

// Allow reuse of a bit between architecture-exclusive symbol flags.
// - needsTocRestore(): On PPC64, true if a call to this symbol needs to be
// followed by a restore of the toc pointer.
// - isTagged(): On AArch64, true if the symbol needs special relocation and
// metadata semantics because it's tagged, under the AArch64 MemtagABI.
LLVM_PREFERRED_TYPE(bool)
uint8_t archSpecificBit : 1;
bool needsTocRestore() const { return archSpecificBit; }
bool isTagged() const { return archSpecificBit; }
Expand All @@ -296,13 +309,16 @@ class Symbol {
//
// LTO shouldn't inline the symbol because it doesn't know the final content
// of the symbol.
LLVM_PREFERRED_TYPE(bool)
uint8_t scriptDefined : 1;

// True if defined in a DSO. There may also be a definition in a relocatable
// object file.
LLVM_PREFERRED_TYPE(bool)
uint8_t dsoDefined : 1;

// True if defined in a DSO as protected visibility.
LLVM_PREFERRED_TYPE(bool)
uint8_t dsoProtected : 1;

// Temporary flags used to communicate which symbol entries need PLT and GOT
Expand All @@ -319,9 +335,11 @@ class Symbol {
// to a Verneed index in the output. Otherwise, this represents the Verdef
// index (VER_NDX_LOCAL, VER_NDX_GLOBAL, or a named version).
uint16_t versionId;
LLVM_PREFERRED_TYPE(bool)
uint8_t versionScriptAssigned : 1;

// True if targeted by a range extension thunk.
LLVM_PREFERRED_TYPE(bool)
uint8_t thunkAccessed : 1;

void setFlags(uint16_t bits) {
Expand Down

0 comments on commit f542796

Please sign in to comment.