Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 5c8a22f

Browse files
committed
Make MCSymbol::Name be a union of uint64_t and a pointer.
This should hopefully fix the 32-bit bots which were allocating space for a pointer but needed to be aligned to 64-bits. Now we allocate enough space for a uint64_t and a pointer and cast to the appropriate storage git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239428 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0e3246a commit 5c8a22f

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

include/llvm/MC/MCSymbol.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,29 @@ class MCSymbol {
120120
friend class MCExpr;
121121
friend class MCContext;
122122

123-
typedef const StringMapEntry<bool> NameEntryTy;
124-
MCSymbol(SymbolKind Kind, NameEntryTy *Name, bool isTemporary)
123+
/// \brief The name for a symbol.
124+
/// MCSymbol contains a uint64_t so is probably aligned to 8. On a 32-bit
125+
/// system, the name is a pointer so isn't going to satisfy the 8 byte
126+
/// alignment of uint64_t. Account for that here.
127+
typedef union {
128+
const StringMapEntry<bool> *NameEntry;
129+
uint64_t AlignmentPadding;
130+
} NameEntryStorageTy;
131+
132+
MCSymbol(SymbolKind Kind, const StringMapEntry<bool> *Name, bool isTemporary)
125133
: Value(nullptr), IsTemporary(isTemporary),
126134
IsRedefinable(false), IsUsed(false), IsRegistered(false),
127135
IsExternal(false), IsPrivateExtern(false), HasName(!!Name),
128136
Kind(Kind) {
129137
Offset = 0;
130138
if (Name)
131-
getNameEntryPtr() = Name;
139+
getNameEntryPtr().NameEntry = Name;
132140
}
133141

134142
// Provide custom new/delete as we will only allocate space for a name
135143
// if we need one.
136-
void *operator new(size_t s, NameEntryTy *Name, MCContext &Ctx);
144+
void *operator new(size_t s, const StringMapEntry<bool> *Name,
145+
MCContext &Ctx);
137146

138147
private:
139148

@@ -160,14 +169,14 @@ class MCSymbol {
160169
}
161170

162171
/// \brief Get a reference to the name field. Requires that we have a name
163-
NameEntryTy *&getNameEntryPtr() {
172+
NameEntryStorageTy &getNameEntryPtr() {
164173
assert(HasName && "Name is required");
165-
NameEntryTy **Name = reinterpret_cast<NameEntryTy **>(this);
174+
NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this);
166175
return *(Name - 1);
167176
}
168-
NameEntryTy *const &getNameEntryPtr() const {
177+
const NameEntryStorageTy &getNameEntryPtr() const {
169178
assert(HasName && "Name is required");
170-
NameEntryTy *const *Name = reinterpret_cast<NameEntryTy *const *>(this);
179+
const auto *Name = reinterpret_cast<const NameEntryStorageTy *>(this);
171180
return *(Name - 1);
172181
}
173182

@@ -177,7 +186,7 @@ class MCSymbol {
177186
if (!HasName)
178187
return StringRef();
179188

180-
return getNameEntryPtr()->first();
189+
return getNameEntryPtr().NameEntry->first();
181190
}
182191

183192
bool isRegistered() const { return IsRegistered; }

lib/MC/MCSymbol.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ using namespace llvm;
1919
// Sentinel value for the absolute pseudo section.
2020
MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
2121

22-
void *MCSymbol::operator new(size_t s, NameEntryTy *Name, MCContext &Ctx) {
23-
size_t Size = s + (Name ? sizeof(Name) : 0);
22+
void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name,
23+
MCContext &Ctx) {
24+
// We may need more space for a Name to account for alignment. So allocate
25+
// space for the storage type and not the name pointer.
26+
size_t Size = s + (Name ? sizeof(NameEntryStorageTy) : 0);
2427

2528
// For safety, ensure that the alignment of a pointer is enough for an
2629
// MCSymbol. This also ensures we don't need padding between the name and
2730
// symbol.
28-
assert(alignOf<MCSymbol>() <= alignOf<NameEntryTy *>() &&
31+
assert(alignOf<MCSymbol>() <= alignOf<NameEntryStorageTy>() &&
2932
"Bad alignment of MCSymbol");
30-
void *Storage = Ctx.allocate(Size, alignOf<NameEntryTy *>());
31-
NameEntryTy **Start = static_cast<NameEntryTy**>(Storage);
32-
NameEntryTy **End = Start + (Name ? 1 : 0);
33+
void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>());
34+
NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
35+
NameEntryStorageTy *End = Start + (Name ? 1 : 0);
3336
return End;
3437
}
3538

0 commit comments

Comments
 (0)