summaryrefslogtreecommitdiff
path: root/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-09-30 02:22:20 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-09-30 02:22:20 +0000
commit7070387f08f7dc797b554ed8013cba9f8b74121a (patch)
treeb2551756c1093c8e4396c9c2596eca5f8657fd51 /lib/MC/ELFObjectWriter.cpp
parent7ebc863c156c5ccd127045ddb8d663c3b49ac5f3 (diff)
downloadllvm-7070387f08f7dc797b554ed8013cba9f8b74121a.tar.gz
llvm-7070387f08f7dc797b554ed8013cba9f8b74121a.tar.bz2
llvm-7070387f08f7dc797b554ed8013cba9f8b74121a.tar.xz
Make it possible for the MCObjectWriter to decide if a given fixup is fully
resolved or not. Different object files have different restrictions and different native assemblers have different idiosyncrasies we want to emulate for now. Move the existing MachO logic to the new place and implement an ELF one that gets fixups to globals right. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115131 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r--lib/MC/ELFObjectWriter.cpp55
1 files changed, 51 insertions, 4 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index b60271f1b2..94251d76b2 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -274,6 +274,11 @@ namespace {
void WriteRelocationsFragment(const MCAssembler &Asm, MCDataFragment *F,
const MCSectionData *SD);
+ bool IsFixupFullyResolved(const MCAssembler &Asm,
+ const MCValue Target,
+ bool IsPCRel,
+ const MCFragment *DF) const;
+
void WriteObject(const MCAssembler &Asm, const MCAsmLayout &Layout);
};
@@ -775,7 +780,7 @@ void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
WriteRelocationsFragment(Asm, F, &SD);
- Asm.AddSectionToTheEnd(RelaSD, Layout);
+ Asm.AddSectionToTheEnd(*Writer, RelaSD, Layout);
}
}
@@ -873,11 +878,11 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,
// Symbol table
F = new MCDataFragment(&SymtabSD);
WriteSymbolTable(F, Asm, Layout, NumRegularSections);
- Asm.AddSectionToTheEnd(SymtabSD, Layout);
+ Asm.AddSectionToTheEnd(*Writer, SymtabSD, Layout);
F = new MCDataFragment(&StrtabSD);
F->getContents().append(StringTable.begin(), StringTable.end());
- Asm.AddSectionToTheEnd(StrtabSD, Layout);
+ Asm.AddSectionToTheEnd(*Writer, StrtabSD, Layout);
F = new MCDataFragment(&ShstrtabSD);
@@ -903,7 +908,41 @@ void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,
F->getContents() += '\x00';
}
- Asm.AddSectionToTheEnd(ShstrtabSD, Layout);
+ Asm.AddSectionToTheEnd(*Writer, ShstrtabSD, Layout);
+}
+
+bool ELFObjectWriterImpl::IsFixupFullyResolved(const MCAssembler &Asm,
+ const MCValue Target,
+ bool IsPCRel,
+ const MCFragment *DF) const {
+ // If this is a PCrel relocation, find the section this fixup value is
+ // relative to.
+ const MCSection *BaseSection = 0;
+ if (IsPCRel) {
+ BaseSection = &DF->getParent()->getSection();
+ assert(BaseSection);
+ }
+
+ const MCSection *SectionA = 0;
+ const MCSymbol *SymbolA = 0;
+ if (const MCSymbolRefExpr *A = Target.getSymA()) {
+ SymbolA = &A->getSymbol();
+ SectionA = &SymbolA->getSection();
+ }
+
+ const MCSection *SectionB = 0;
+ if (const MCSymbolRefExpr *B = Target.getSymB()) {
+ SectionB = &B->getSymbol().getSection();
+ }
+
+ if (!BaseSection)
+ return SectionA == SectionB;
+
+ const MCSymbolData &DataA = Asm.getSymbolData(*SymbolA);
+ if (DataA.isExternal())
+ return false;
+
+ return !SectionB && BaseSection == SectionA;
}
void ELFObjectWriterImpl::WriteObject(const MCAssembler &Asm,
@@ -1064,6 +1103,14 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
Target, FixedValue);
}
+bool ELFObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm,
+ const MCValue Target,
+ bool IsPCRel,
+ const MCFragment *DF) const {
+ return ((ELFObjectWriterImpl*) Impl)->IsFixupFullyResolved(Asm, Target,
+ IsPCRel, DF);
+}
+
void ELFObjectWriter::WriteObject(const MCAssembler &Asm,
const MCAsmLayout &Layout) {
((ELFObjectWriterImpl*) Impl)->WriteObject(Asm, Layout);