diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-03-19 07:09:47 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-03-19 07:09:47 +0000 |
commit | b1e98945e4b107eb3f2ac1b54706c49864842dc4 (patch) | |
tree | 62831961f697a1dd1ac0673c8570daf187627540 /lib | |
parent | bacba997782f624d3c43591a913b8f1e3d733a52 (diff) | |
download | external_llvm-b1e98945e4b107eb3f2ac1b54706c49864842dc4.zip external_llvm-b1e98945e4b107eb3f2ac1b54706c49864842dc4.tar.gz external_llvm-b1e98945e4b107eb3f2ac1b54706c49864842dc4.tar.bz2 |
MC/Mach-O: Lift the fixup evaluation and application up (to the same place), and eliminate MCAsmFixup::FixedValue.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98944 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCAssembler.cpp | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index c18a3a6..500f23f 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -609,19 +609,6 @@ public: Relocations[Fragment.getParent()].push_back(MRE); } - void ComputeRelocationInfo(MCAssembler &Asm, MCDataFragment &Fragment, - MCAsmFixup &Fixup) { - // FIXME: Share layout object. - MCAsmLayout Layout(Asm); - - // Evaluate the fixup; if the value was resolved, no relocation is needed. - MCValue Target; - if (Asm.EvaluateFixup(Layout, Fixup, &Fragment, Target, Fixup.FixedValue)) - return; - - RecordRelocation(Asm, Fragment, Fixup, Target, Fixup.FixedValue); - } - void BindIndirectSymbols(MCAssembler &Asm) { // This is the point where 'as' creates actual symbols for indirect symbols // (in the following two passes). It would be easier for us to do this @@ -785,17 +772,6 @@ public: // Compute symbol table information and bind symbol indices. ComputeSymbolTable(Asm, StringTable, LocalSymbolData, ExternalSymbolData, UndefinedSymbolData); - - // Compute relocations. - for (MCAssembler::iterator it = Asm.begin(), - ie = Asm.end(); it != ie; ++it) { - MCSectionData &SD = *it; - for (MCSectionData::iterator it2 = SD.begin(), - ie2 = SD.end(); it2 != ie2; ++it2) - if (MCDataFragment *DF = dyn_cast<MCDataFragment>(&*it2)) - for (unsigned i = 0, e = DF->fixup_size(); i != e; ++i) - ComputeRelocationInfo(Asm, *DF, DF->getFixups()[i]); - } } void WriteObject(const MCAssembler &Asm) { @@ -955,14 +931,15 @@ public: } } - void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF) { + void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF, + uint64_t FixedValue) { unsigned Size = 1 << getFixupKindLog2Size(Fixup.Kind); // FIXME: Endianness assumption. assert(Fixup.Offset + Size <= DF.getContents().size() && "Invalid fixup offset!"); for (unsigned i = 0; i != Size; ++i) - DF.getContents()[Fixup.Offset + i] = uint8_t(Fixup.FixedValue >> (i * 8)); + DF.getContents()[Fixup.Offset + i] = uint8_t(FixedValue >> (i * 8)); } }; @@ -1394,15 +1371,6 @@ static void WriteFileData(raw_ostream &OS, const MCFragment &F, } case MCFragment::FT_Data: { - MCDataFragment &DF = cast<MCDataFragment>(F); - - // Apply the fixups. - // - // FIXME: Move elsewhere. - for (MCDataFragment::const_fixup_iterator it = DF.fixup_begin(), - ie = DF.fixup_end(); it != ie; ++it) - MOW.ApplyFixup(*it, DF); - OS << cast<MCDataFragment>(F).getContents().str(); break; } @@ -1484,6 +1452,34 @@ void MCAssembler::Finish() { // example, to set the index fields in the symbol data). MOW.ExecutePostLayoutBinding(*this); + // Evaluate and apply the fixups, generating relocation entries as necessary. + MCAsmLayout Layout(*this); + for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) { + for (MCSectionData::iterator it2 = it->begin(), + ie2 = it->end(); it2 != ie2; ++it2) { + MCDataFragment *DF = dyn_cast<MCDataFragment>(it2); + if (!DF) + continue; + + for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(), + ie3 = DF->fixup_end(); it3 != ie3; ++it3) { + MCAsmFixup &Fixup = *it3; + + // Evaluate the fixup. + MCValue Target; + uint64_t FixedValue; + if (!EvaluateFixup(Layout, Fixup, DF, Target, FixedValue)) { + // The fixup was unresolved, we need a relocation. Inform the object + // writer of the relocation, and give it an opportunity to adjust the + // fixup value if need be. + MOW.RecordRelocation(*this, *DF, Fixup, Target, FixedValue); + } + + MOW.ApplyFixup(Fixup, *DF, FixedValue); + } + } + } + // Write the object file. MOW.WriteObject(*this); |