aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-12-06 02:57:26 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-12-06 02:57:26 +0000
commitffd902bfb743f0564c8f7689c49403074b6f694d (patch)
tree6dc49fb579a5b784c052b17c74cb58009f216fc2
parentcc10244d7725f191bdc91cd62befff0c97257c7b (diff)
Add a getSymbolOffset method and use it in the ELF writer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120977 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCAsmLayout.h4
-rw-r--r--lib/MC/ELFObjectWriter.cpp23
-rw-r--r--lib/MC/MCAssembler.cpp5
3 files changed, 17 insertions, 15 deletions
diff --git a/include/llvm/MC/MCAsmLayout.h b/include/llvm/MC/MCAsmLayout.h
index 2cde06b4ed..cad7664c3a 100644
--- a/include/llvm/MC/MCAsmLayout.h
+++ b/include/llvm/MC/MCAsmLayout.h
@@ -133,6 +133,10 @@ public:
/// layout.
uint64_t getSymbolAddress(const MCSymbolData *SD) const;
+ /// \brief Get the offset of the given symbol, as computed in the current
+ /// layout.
+ uint64_t getSymbolOffset(const MCSymbolData *SD) const;
+
/// @}
};
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index b84f593a95..1fc844cc4a 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -557,9 +557,8 @@ static uint64_t SymbolValue(MCSymbolData &Data, const MCAsmLayout &Layout) {
if (!Symbol.isInSection())
return 0;
- if (MCFragment *FF = Data.getFragment())
- return Layout.getSymbolAddress(&Data) -
- Layout.getSectionAddress(FF->getParent());
+ if (Data.getFragment())
+ return Layout.getSymbolOffset(&Data);
return 0;
}
@@ -1523,10 +1522,9 @@ void ARMELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
const MCSymbol &SymbolB = RefB->getSymbol();
MCSymbolData &SDB = Asm.getSymbolData(SymbolB);
IsPCRel = true;
- MCSectionData *Sec = Fragment->getParent();
// Offset of the symbol in the section
- int64_t a = Layout.getSymbolAddress(&SDB) - Layout.getSectionAddress(Sec);
+ int64_t a = Layout.getSymbolOffset(&SDB);
// Ofeset of the relocation in the section
int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
@@ -1539,9 +1537,8 @@ void ARMELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
Index = F->getParent()->getOrdinal() + 1;
- MCSectionData *FSD = F->getParent();
// Offset of the symbol in the section
- Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
+ Value += Layout.getSymbolOffset(&SD);
} else {
if (Asm.getSymbolData(Symbol).getFlags() & ELF_Other_Weakref)
WeakrefUsedInReloc.insert(RelocSymbol);
@@ -1601,10 +1598,9 @@ void MBlazeELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
const MCSymbol &SymbolB = RefB->getSymbol();
MCSymbolData &SDB = Asm.getSymbolData(SymbolB);
IsPCRel = true;
- MCSectionData *Sec = Fragment->getParent();
// Offset of the symbol in the section
- int64_t a = Layout.getSymbolAddress(&SDB) - Layout.getSectionAddress(Sec);
+ int64_t a = Layout.getSymbolOffset(&SDB);
// Ofeset of the relocation in the section
int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
@@ -1617,9 +1613,8 @@ void MBlazeELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
Index = F->getParent()->getOrdinal();
- MCSectionData *FSD = F->getParent();
// Offset of the symbol in the section
- Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
+ Value += Layout.getSymbolOffset(&SD);
} else {
if (Asm.getSymbolData(Symbol).getFlags() & ELF_Other_Weakref)
WeakrefUsedInReloc.insert(RelocSymbol);
@@ -1705,10 +1700,9 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
const MCSymbol &SymbolB = RefB->getSymbol();
MCSymbolData &SDB = Asm.getSymbolData(SymbolB);
IsPCRel = true;
- MCSectionData *Sec = Fragment->getParent();
// Offset of the symbol in the section
- int64_t a = Layout.getSymbolAddress(&SDB) - Layout.getSectionAddress(Sec);
+ int64_t a = Layout.getSymbolOffset(&SDB);
// Ofeset of the relocation in the section
int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
@@ -1721,9 +1715,8 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
Index = F->getParent()->getOrdinal() + 1;
- MCSectionData *FSD = F->getParent();
// Offset of the symbol in the section
- Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
+ Value += Layout.getSymbolOffset(&SD);
} else {
if (Asm.getSymbolData(Symbol).getFlags() & ELF_Other_Weakref)
WeakrefUsedInReloc.insert(RelocSymbol);
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp
index 1e701ecf2b..c4e775e2c9 100644
--- a/lib/MC/MCAssembler.cpp
+++ b/lib/MC/MCAssembler.cpp
@@ -154,6 +154,11 @@ uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const {
return F->Offset;
}
+uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const {
+ assert(SD->getFragment() && "Invalid getOffset() on undefined symbol!");
+ return getFragmentOffset(SD->getFragment()) + SD->getOffset();
+}
+
uint64_t MCAsmLayout::getSymbolAddress(const MCSymbolData *SD) const {
assert(SD->getFragment() && "Invalid getAddress() on undefined symbol!");
return getFragmentAddress(SD->getFragment()) + SD->getOffset();