@@ -109,6 +109,14 @@ class MCSymbol {
109
109
// / extension and achieve better bitpacking with MSVC.
110
110
unsigned SymbolContents : 2 ;
111
111
112
+ // / The alignment of the symbol, if it is 'common', or -1.
113
+ // /
114
+ // / The alignment is stored as log2(align) + 1. This allows all values from
115
+ // / 0 to 2^31 to be stored which is every power of 2 representable by an
116
+ // / unsigned.
117
+ static const unsigned NumCommonAlignmentBits = 5 ;
118
+ unsigned CommonAlignLog2 : NumCommonAlignmentBits;
119
+
112
120
// / Index field, for use by the object file implementation.
113
121
mutable uint32_t Index = 0 ;
114
122
@@ -123,11 +131,6 @@ class MCSymbol {
123
131
const MCExpr *Value;
124
132
};
125
133
126
- // / The alignment of the symbol, if it is 'common', or -1.
127
- //
128
- // FIXME: Pack this in with other fields?
129
- unsigned CommonAlign = -1U ;
130
-
131
134
// / The Flags field is used by object file implementations to store
132
135
// / additional per symbol information which is not easily classified.
133
136
mutable uint32_t Flags = 0 ;
@@ -148,7 +151,8 @@ class MCSymbol {
148
151
MCSymbol (SymbolKind Kind, const StringMapEntry<bool > *Name, bool isTemporary)
149
152
: IsTemporary(isTemporary), IsRedefinable(false ), IsUsed(false ),
150
153
IsRegistered (false ), IsExternal(false ), IsPrivateExtern(false ),
151
- Kind(Kind), IsUsedInReloc(false ), SymbolContents(SymContentsUnset) {
154
+ Kind(Kind), IsUsedInReloc(false ), SymbolContents(SymContentsUnset),
155
+ CommonAlignLog2(0 ) {
152
156
Offset = 0 ;
153
157
SectionOrFragmentAndHasName.setInt (!!Name);
154
158
if (Name)
@@ -338,14 +342,20 @@ class MCSymbol {
338
342
void setCommon (uint64_t Size , unsigned Align) {
339
343
assert (getOffset () == 0 );
340
344
CommonSize = Size ;
341
- CommonAlign = Align;
342
345
SymbolContents = SymContentsCommon;
346
+
347
+ assert ((!Align || isPowerOf2_32 (Align)) &&
348
+ " Alignment must be a power of 2" );
349
+ unsigned Log2Align = Log2_32 (Align) + 1 ;
350
+ assert (Log2Align < (1U << NumCommonAlignmentBits) &&
351
+ " Out of range alignment" );
352
+ CommonAlignLog2 = Log2Align;
343
353
}
344
354
345
355
// / Return the alignment of a 'common' symbol.
346
356
unsigned getCommonAlignment () const {
347
357
assert (isCommon () && " Not a 'common' symbol!" );
348
- return CommonAlign ;
358
+ return CommonAlignLog2 ? ( 1U << (CommonAlignLog2 - 1 )) : 0 ;
349
359
}
350
360
351
361
// / Declare this symbol as being 'common'.
@@ -356,7 +366,7 @@ class MCSymbol {
356
366
bool declareCommon (uint64_t Size , unsigned Align) {
357
367
assert (isCommon () || getOffset () == 0 );
358
368
if (isCommon ()) {
359
- if (CommonSize != Size || CommonAlign != Align)
369
+ if (CommonSize != Size || getCommonAlignment () != Align)
360
370
return true ;
361
371
} else
362
372
setCommon (Size , Align);
0 commit comments