diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/MC/MCContext.cpp | 11 | ||||
| -rw-r--r-- | llvm/lib/MC/MCSymbol.cpp | 15 |
2 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 1e52eedaf18..785f9ac5456 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -135,7 +135,7 @@ MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) { } auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first; - Sym = new (*this) MCSymbolELF(&*NameIter, /*isTemporary*/ false); + Sym = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false); if (!OldSym) OldSym = Sym; @@ -164,14 +164,15 @@ MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name, if (MOFI) { switch (MOFI->getObjectFileType()) { case MCObjectFileInfo::IsCOFF: - return new (*this) MCSymbolCOFF(Name, IsTemporary); + return new (Name, *this) MCSymbolCOFF(Name, IsTemporary); case MCObjectFileInfo::IsELF: - return new (*this) MCSymbolELF(Name, IsTemporary); + return new (Name, *this) MCSymbolELF(Name, IsTemporary); case MCObjectFileInfo::IsMachO: - return new (*this) MCSymbolMachO(Name, IsTemporary); + return new (Name, *this) MCSymbolMachO(Name, IsTemporary); } } - return new (*this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary); + return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name, + IsTemporary); } MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp index 8d07b7605ce..7eba5e0317c 100644 --- a/llvm/lib/MC/MCSymbol.cpp +++ b/llvm/lib/MC/MCSymbol.cpp @@ -9,6 +9,7 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -18,6 +19,20 @@ using namespace llvm; // Sentinel value for the absolute pseudo section. MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1); +void *MCSymbol::operator new(size_t s, NameEntryTy *Name, MCContext &Ctx) { + size_t Size = s + (Name ? sizeof(Name) : 0); + + // For safety, ensure that the alignment of a pointer is enough for an + // MCSymbol. This also ensures we don't need padding between the name and + // symbol. + assert(alignOf<MCSymbol>() <= alignof(NameEntryTy *) && + "Bad alignment of MCSymbol"); + void *Storage = Ctx.allocate(Size, alignof(NameEntryTy *)); + NameEntryTy **Start = static_cast<NameEntryTy**>(Storage); + NameEntryTy **End = Start + (Name ? 1 : 0); + return End; +} + void MCSymbol::setVariableValue(const MCExpr *Value) { assert(!IsUsed && "Cannot set a variable that has already been used."); assert(Value && "Invalid variable value!"); |

