Skip to content

Commit f542796

Browse files
authored
[lld][ELF] Annotate Bitfields with Preferred Types (#97737)
1 parent e2cee2c commit f542796

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lld/ELF/InputSection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ class SectionBase {
5252

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

55+
LLVM_PREFERRED_TYPE(Kind)
5556
uint8_t sectionKind : 3;
5657

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

61+
LLVM_PREFERRED_TYPE(bool)
6062
uint8_t bss : 1;
6163

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

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

284287
uint32_t inputOff;
288+
LLVM_PREFERRED_TYPE(bool)
285289
uint32_t live : 1;
286290
uint32_t hash : 31;
287291
uint64_t outputOff = 0;

lld/ELF/Symbols.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,21 @@ class Symbol {
115115
uint8_t partition;
116116

117117
// True if this symbol is preemptible at load time.
118+
LLVM_PREFERRED_TYPE(bool)
118119
uint8_t isPreemptible : 1;
119120

120121
// True if the symbol was used for linking and thus need to be added to the
121122
// output file's symbol table. This is true for all symbols except for
122123
// unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that
123124
// are unreferenced except by other bitcode objects.
125+
LLVM_PREFERRED_TYPE(bool)
124126
uint8_t isUsedInRegularObj : 1;
125127

126128
// True if an undefined or shared symbol is used from a live section.
127129
//
128130
// NOTE: In Writer.cpp the field is used to mark local defined symbols
129131
// which are referenced by relocations when -r or --emit-relocs is given.
132+
LLVM_PREFERRED_TYPE(bool)
130133
uint8_t used : 1;
131134

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

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

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

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

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

161169
// True if the name contains '@'.
170+
LLVM_PREFERRED_TYPE(bool)
162171
uint8_t hasVersionSuffix : 1;
163172

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

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

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

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

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

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

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

324341
// True if targeted by a range extension thunk.
342+
LLVM_PREFERRED_TYPE(bool)
325343
uint8_t thunkAccessed : 1;
326344

327345
void setFlags(uint16_t bits) {

0 commit comments

Comments
 (0)