[llvm] r238583 - Move common symbol related information from MCSectionData to MCSymbol.
Rafael Espindola
rafael.espindola at gmail.com
Fri May 29 10:48:04 PDT 2015
Author: rafael
Date: Fri May 29 12:48:04 2015
New Revision: 238583
URL: http://llvm.org/viewvc/llvm-project?rev=238583&view=rev
Log:
Move common symbol related information from MCSectionData to MCSymbol.
Modified:
llvm/trunk/include/llvm/MC/MCSymbol.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MCELFStreamer.cpp
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/MC/MCMachOStreamer.cpp
llvm/trunk/lib/MC/MCObjectStreamer.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFStreamer.cpp
Modified: llvm/trunk/include/llvm/MC/MCSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbol.h?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbol.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbol.h Fri May 29 12:48:04 2015
@@ -34,39 +34,17 @@ class MCSymbolData {
/// if it is private extern (bit 1).
PointerIntPair<MCFragment *, 2> Fragment;
- union {
- /// Offset - The offset to apply to the fragment address to form this
- /// symbol's value.
- uint64_t Offset;
-
- /// CommonSize - The size of the symbol, if it is 'common'.
- uint64_t CommonSize;
- };
-
- /// CommonAlign - The alignment of the symbol, if it is 'common', or -1.
- //
- // FIXME: Pack this in with other fields?
- unsigned CommonAlign = -1U;
/// Flags - The Flags field is used by object file implementations to store
/// additional per symbol information which is not easily classified.
uint32_t Flags = 0;
public:
- MCSymbolData() { Offset = 0; }
+ MCSymbolData() {}
MCFragment *getFragment() const { return Fragment.getPointer(); }
void setFragment(MCFragment *Value) { Fragment.setPointer(Value); }
- uint64_t getOffset() const {
- assert(!isCommon());
- return Offset;
- }
- void setOffset(uint64_t Value) {
- assert(!isCommon());
- Offset = Value;
- }
-
/// @}
/// \name Symbol Attributes
/// @{
@@ -81,31 +59,6 @@ public:
Fragment.setInt((Fragment.getInt() & ~2) | (unsigned(Value) << 1));
}
- /// isCommon - Is this a 'common' symbol.
- bool isCommon() const { return CommonAlign != -1U; }
-
- /// setCommon - Mark this symbol as being 'common'.
- ///
- /// \param Size - The size of the symbol.
- /// \param Align - The alignment of the symbol.
- void setCommon(uint64_t Size, unsigned Align) {
- assert(getOffset() == 0);
- CommonSize = Size;
- CommonAlign = Align;
- }
-
- /// getCommonSize - Return the size of a 'common' symbol.
- uint64_t getCommonSize() const {
- assert(isCommon() && "Not a 'common' symbol!");
- return CommonSize;
- }
-
- /// getCommonAlignment - Return the alignment of a 'common' symbol.
- unsigned getCommonAlignment() const {
- assert(isCommon() && "Not a 'common' symbol!");
- return CommonAlign;
- }
-
/// getFlags - Get the (implementation defined) symbol flags.
uint32_t getFlags() const { return Flags; }
@@ -167,6 +120,19 @@ class MCSymbol {
/// symbol has no size this field will be NULL.
const MCExpr *SymbolSize = nullptr;
+ /// The alignment of the symbol, if it is 'common', or -1.
+ //
+ // FIXME: Pack this in with other fields?
+ unsigned CommonAlign = -1U;
+
+ union {
+ /// The offset to apply to the fragment address to form this symbol's value.
+ uint64_t Offset;
+
+ /// The size of the symbol, if it is 'common'.
+ uint64_t CommonSize;
+ };
+
mutable MCSymbolData Data;
private: // MCContext creates and uniques these.
@@ -174,7 +140,9 @@ private: // MCContext creates and unique
friend class MCContext;
MCSymbol(const StringMapEntry<bool> *Name, bool isTemporary)
: Name(Name), Section(nullptr), Value(nullptr), IsTemporary(isTemporary),
- IsRedefinable(false), IsUsed(false), HasData(false), Index(0) {}
+ IsRedefinable(false), IsUsed(false), HasData(false), Index(0) {
+ Offset = 0;
+ }
MCSymbol(const MCSymbol &) = delete;
void operator=(const MCSymbol &) = delete;
@@ -295,6 +263,40 @@ public:
const MCExpr *getSize() const { return SymbolSize; }
+ uint64_t getOffset() const {
+ assert(!isCommon());
+ return Offset;
+ }
+ void setOffset(uint64_t Value) {
+ assert(!isCommon());
+ Offset = Value;
+ }
+
+ /// Return the size of a 'common' symbol.
+ uint64_t getCommonSize() const {
+ assert(isCommon() && "Not a 'common' symbol!");
+ return CommonSize;
+ }
+
+ /// Mark this symbol as being 'common'.
+ ///
+ /// \param Size - The size of the symbol.
+ /// \param Align - The alignment of the symbol.
+ void setCommon(uint64_t Size, unsigned Align) {
+ assert(getOffset() == 0);
+ CommonSize = Size;
+ CommonAlign = Align;
+ }
+
+ /// Return the alignment of a 'common' symbol.
+ unsigned getCommonAlignment() const {
+ assert(isCommon() && "Not a 'common' symbol!");
+ return CommonAlign;
+ }
+
+ /// Is this a 'common' symbol.
+ bool isCommon() const { return CommonAlign != -1U; }
+
/// print - Print the value to the stream \p OS.
void print(raw_ostream &OS) const;
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Fri May 29 12:48:04 2015
@@ -360,8 +360,8 @@ void ELFObjectWriter::writeHeader(const
uint64_t ELFObjectWriter::SymbolValue(const MCSymbol &Sym,
const MCAsmLayout &Layout) {
MCSymbolData &Data = Sym.getData();
- if (Data.isCommon() && Data.isExternal())
- return Data.getCommonAlignment();
+ if (Sym.isCommon() && Data.isExternal())
+ return Sym.getCommonAlignment();
uint64_t Res;
if (!Layout.getSymbolOffset(Sym, Res))
@@ -459,7 +459,7 @@ void ELFObjectWriter::writeSymbol(Symbol
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
// SHN_COMMON.
- bool IsReserved = !Base || OrigData.isCommon();
+ bool IsReserved = !Base || MSD.Symbol->isCommon();
// Binding and Type share the same byte as upper and lower nibbles
uint8_t Binding = MCELF::GetBinding(OrigData);
@@ -832,7 +832,7 @@ void ELFObjectWriter::computeSymbolTable
if (Symbol.isAbsolute()) {
MSD.SectionIndex = ELF::SHN_ABS;
- } else if (SD.isCommon()) {
+ } else if (Symbol.isCommon()) {
assert(!Local);
MSD.SectionIndex = ELF::SHN_COMMON;
} else if (Symbol.isUndefined()) {
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Fri May 29 12:48:04 2015
@@ -127,7 +127,7 @@ static bool getLabelOffset(const MCAsmLa
S.getName() + "'");
return false;
}
- Val = Layout.getFragmentOffset(SD.getFragment()) + SD.getOffset();
+ Val = Layout.getFragmentOffset(SD.getFragment()) + S.getOffset();
return true;
}
@@ -195,8 +195,7 @@ const MCSymbol *MCAsmLayout::getBaseSymb
const MCSymbol &ASym = A->getSymbol();
const MCAssembler &Asm = getAssembler();
- const MCSymbolData &ASD = ASym.getData();
- if (ASD.isCommon()) {
+ if (ASym.isCommon()) {
// FIXME: we should probably add a SMLoc to MCExpr.
Asm.getContext().reportFatalError(SMLoc(),
"Common symbol " + ASym.getName() +
@@ -1189,12 +1188,7 @@ void MCSymbolData::dump() const {
OS << "<MCSymbolData"
<< " Fragment:" << getFragment();
- if (!isCommon())
- OS << " Offset:" << getOffset();
OS << " Flags:" << getFlags();
- if (isCommon())
- OS << " (common, size:" << getCommonSize()
- << " align: " << getCommonAlignment() << ")";
if (isExternal())
OS << " (external)";
if (isPrivateExtern())
Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Fri May 29 12:48:04 2015
@@ -328,7 +328,7 @@ void MCELFStreamer::EmitCommonSymbol(MCS
struct LocalCommon L = {Symbol, Size, ByteAlignment};
LocalCommons.push_back(L);
} else {
- SD.setCommon(Size, ByteAlignment);
+ Symbol->setCommon(Size, ByteAlignment);
}
Symbol->setSize(MCConstantExpr::Create(Size, getContext()));
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Fri May 29 12:48:04 2015
@@ -475,7 +475,7 @@ static void AttemptToFoldSymbolOffsetDif
const MCSymbolData &BD = SB.getData();
if (AD.getFragment() == BD.getFragment()) {
- Addend += (AD.getOffset() - BD.getOffset());
+ Addend += (SA.getOffset() - SB.getOffset());
// Pointers to Thumb symbols need to have their low-bit set to allow
// for interworking.
Modified: llvm/trunk/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCMachOStreamer.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCMachOStreamer.cpp Fri May 29 12:48:04 2015
@@ -392,7 +392,7 @@ void MCMachOStreamer::EmitCommonSymbol(M
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
SD.setExternal(true);
- SD.setCommon(Size, ByteAlignment);
+ Symbol->setCommon(Size, ByteAlignment);
}
void MCMachOStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
@@ -470,7 +470,8 @@ void MCMachOStreamer::FinishImpl() {
MCSymbolData &SD = Symbol.getData();
if (getAssembler().isSymbolLinkerVisible(Symbol) && SD.getFragment()) {
// An atom defining symbol should never be internal to a fragment.
- assert(SD.getOffset() == 0 && "Invalid offset in atom defining symbol!");
+ assert(Symbol.getOffset() == 0 &&
+ "Invalid offset in atom defining symbol!");
DefiningSymbolMap[SD.getFragment()] = &Symbol;
}
}
Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Fri May 29 12:48:04 2015
@@ -49,7 +49,7 @@ void MCObjectStreamer::flushPendingLabel
for (MCSymbol *Sym : PendingLabels) {
MCSymbolData *SD = &Sym->getData();
SD->setFragment(F);
- SD->setOffset(FOffset);
+ Sym->setOffset(FOffset);
}
PendingLabels.clear();
}
@@ -72,9 +72,9 @@ bool MCObjectStreamer::emitAbsoluteSymbo
if (!isa<MCDataFragment>(HiD.getFragment()))
return false;
- assert(HiD.getOffset() >= LoD.getOffset() &&
+ assert(Hi->getOffset() >= Lo->getOffset() &&
"Expected Hi to be greater than Lo");
- EmitIntValue(HiD.getOffset() - LoD.getOffset(), Size);
+ EmitIntValue(Hi->getOffset() - Lo->getOffset(), Size);
return true;
}
@@ -173,7 +173,7 @@ void MCObjectStreamer::EmitLabel(MCSymbo
if (F && !(getAssembler().isBundlingEnabled() &&
getAssembler().getRelaxAll())) {
SD.setFragment(F);
- SD.setOffset(F->getContents().size());
+ Symbol->setOffset(F->getContents().size());
} else {
PendingLabels.push_back(Symbol);
}
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Fri May 29 12:48:04 2015
@@ -373,13 +373,13 @@ void MachObjectWriter::WriteNlist(MachSy
Address = AliaseeInfo->StringIndex;
else if (Symbol->isDefined())
Address = getSymbolAddress(OrigSymbol, Layout);
- else if (Data.isCommon()) {
+ else if (Symbol->isCommon()) {
// Common symbols are encoded with the size in the address
// field, and their alignment in the flags.
- Address = Data.getCommonSize();
+ Address = Symbol->getCommonSize();
// Common alignment is packed into the 'desc' bits.
- if (unsigned Align = Data.getCommonAlignment()) {
+ if (unsigned Align = Symbol->getCommonAlignment()) {
unsigned Log2Size = Log2_32(Align);
assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
if (Log2Size > 15)
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Fri May 29 12:48:04 2015
@@ -365,8 +365,8 @@ void WinCOFFObjectWriter::defineSection(
static uint64_t getSymbolValue(const MCSymbol &Symbol,
const MCAsmLayout &Layout) {
const MCSymbolData &Data = Symbol.getData();
- if (Data.isCommon() && Data.isExternal())
- return Data.getCommonSize();
+ if (Symbol.isCommon() && Data.isExternal())
+ return Symbol.getCommonSize();
uint64_t Res;
if (!Layout.getSymbolOffset(Symbol, Res))
@@ -765,7 +765,7 @@ void WinCOFFObjectWriter::RecordRelocati
Reloc.Symb = coff_symbol->Section->Symbol;
FixedValue +=
Layout.getFragmentOffset(coff_symbol->MC->getData().getFragment()) +
- coff_symbol->MC->getData().getOffset();
+ coff_symbol->MC->getOffset();
} else
Reloc.Symb = coff_symbol;
Modified: llvm/trunk/lib/MC/WinCOFFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFStreamer.cpp?rev=238583&r1=238582&r2=238583&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFStreamer.cpp Fri May 29 12:48:04 2015
@@ -196,7 +196,7 @@ void MCWinCOFFStreamer::EmitCommonSymbol
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
SD.setExternal(true);
- SD.setCommon(Size, ByteAlignment);
+ Symbol->setCommon(Size, ByteAlignment);
if (!T.isKnownWindowsMSVCEnvironment() && ByteAlignment > 1) {
SmallString<128> Directive;
More information about the llvm-commits
mailing list