aboutsummaryrefslogtreecommitdiff
path: root/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-09-30 20:18:35 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-09-30 20:18:35 +0000
commit7eae36b38b874f417fa191fc1cfec22c100f164d (patch)
tree8c16949ea213be52128add5ff41b4598b34f2132 /lib/MC/ELFObjectWriter.cpp
parenta3fbadfcd882f9f15bda7c1213b5ff52d6582a10 (diff)
Factor some logic into ShouldRelocOnSymbol. This simplifies the code and
fixes some cases where we were producing relocations with at symbol that should use a section instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115194 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r--lib/MC/ELFObjectWriter.cpp69
1 files changed, 31 insertions, 38 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index a80e7b6b08..1890da72e0 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -500,11 +500,22 @@ void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F,
}
}
-static const MCSymbolData *getAtom(const MCSymbolData &SD) {
- if (!SD.getFragment())
- return 0;
+static bool ShouldRelocOnSymbol(const MCSymbolData &SD,
+ const MCValue &Target) {
+ const MCSymbol &Symbol = SD.getSymbol();
+ if (Symbol.isUndefined())
+ return true;
+
+ const MCSectionELF &Section =
+ static_cast<const MCSectionELF&>(Symbol.getSection());
+
+ if (Section.getFlags() & MCSectionELF::SHF_MERGE)
+ return Target.getConstant() != 0;
- return SD.getFragment()->getAtom();
+ if (SD.isExternal())
+ return true;
+
+ return false;
}
// FIXME: this is currently X86/X86_64 only
@@ -522,48 +533,30 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
if (!Target.isAbsolute()) {
const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
MCSymbolData &SD = Asm.getSymbolData(*Symbol);
- const MCSymbolData *Base = getAtom(SD);
MCFragment *F = SD.getFragment();
- // Avoid relocations for cases like jumps and calls in the same file.
+ // Check that this case has already been fully resolved before we get
+ // here.
if (Symbol->isDefined() && !SD.isExternal() &&
IsPCRel &&
&Fragment->getParent()->getSection() == &Symbol->getSection()) {
- uint64_t FixupAddr = Layout.getFragmentAddress(Fragment) + Fixup.getOffset();
- FixedValue = Layout.getSymbolAddress(&SD) + Target.getConstant() - FixupAddr;
+ llvm_unreachable("We don't need a relocation in this case.");
return;
}
- if (Base) {
- if (Base != &SD) {
- Index = F->getParent()->getOrdinal() + LocalSymbolData.size() + 1;
-
- MCSectionData *FSD = F->getParent();
- // Offset of the symbol in the section
- Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
- } else
- Index = getSymbolIndexInSymbolTable(Asm, Symbol);
- Addend = Value;
- // Compensate for the addend on i386.
- if (Is64Bit)
- Value = 0;
- } else {
- if (F) {
- // Index of the section in .symtab against this symbol
- // is being relocated + 2 (empty section + abs. symbols).
- Index = F->getParent()->getOrdinal() + LocalSymbolData.size() + 1;
-
- MCSectionData *FSD = F->getParent();
- // Offset of the symbol in the section
- Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
- } else {
- Index = getSymbolIndexInSymbolTable(Asm, Symbol);
- }
- Addend = Value;
- // Compensate for the addend on i386.
- if (Is64Bit)
- Value = 0;
- }
+ bool RelocOnSymbol = ShouldRelocOnSymbol(SD, Target);
+ if (!RelocOnSymbol) {
+ Index = F->getParent()->getOrdinal() + LocalSymbolData.size() + 1;
+
+ MCSectionData *FSD = F->getParent();
+ // Offset of the symbol in the section
+ Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
+ } else
+ Index = getSymbolIndexInSymbolTable(Asm, Symbol);
+ Addend = Value;
+ // Compensate for the addend on i386.
+ if (Is64Bit)
+ Value = 0;
}
FixedValue = Value;