[llvm-commits] [llvm] r120977 - in /llvm/trunk: include/llvm/MC/MCAsmLayout.h lib/MC/ELFObjectWriter.cpp lib/MC/MCAssembler.cpp
Rafael Espindola
rafael.espindola at gmail.com
Sun Dec 5 18:57:26 PST 2010
Author: rafael
Date: Sun Dec 5 20:57:26 2010
New Revision: 120977
URL: http://llvm.org/viewvc/llvm-project?rev=120977&view=rev
Log:
Add a getSymbolOffset method and use it in the ELF writer.
Modified:
llvm/trunk/include/llvm/MC/MCAsmLayout.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=120977&r1=120976&r2=120977&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Sun Dec 5 20:57:26 2010
@@ -133,6 +133,10 @@
/// 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;
+
/// @}
};
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=120977&r1=120976&r2=120977&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Sun Dec 5 20:57:26 2010
@@ -557,9 +557,8 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=120977&r1=120976&r2=120977&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Sun Dec 5 20:57:26 2010
@@ -154,6 +154,11 @@
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();
More information about the llvm-commits
mailing list