[PATCH] D23565: [ELF] Linkerscript: fix relocation offsets
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 17 08:54:05 PDT 2016
evgeny777 updated this revision to Diff 68369.
evgeny777 added a comment.
Fixed bug in fixDynamicRelocs()
https://reviews.llvm.org/D23565
Files:
ELF/LinkerScript.cpp
ELF/OutputSections.cpp
ELF/OutputSections.h
Index: ELF/OutputSections.h
===================================================================
--- ELF/OutputSections.h
+++ ELF/OutputSections.h
@@ -237,9 +237,13 @@
UseSymVA(UseSymVA), Addend(Addend) {}
uintX_t getOffset() const;
+ void setSectionOffset(uintX_t Offset) { OffsetInSec = Offset; }
uintX_t getAddend() const;
uint32_t getSymIndex() const;
- const OutputSectionBase<ELFT> *getOutputSec() const { return OutputSec; }
+ const OutputSectionBase<ELFT> *getOutputSec() const {
+ return OutputSec ? OutputSec : InputSec->OutSec;
+ }
+ const InputSectionBase<ELFT> *getInputSec() const { return InputSec; }
uint32_t Type;
@@ -379,9 +383,10 @@
typename Base::Kind getKind() const override { return Base::Reloc; }
static bool classof(const Base *B) { return B->getKind() == Base::Reloc; }
+ std::vector<DynamicReloc<ELFT>> Relocs;
+
private:
bool Sort;
- std::vector<DynamicReloc<ELFT>> Relocs;
};
template <class ELFT>
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -1994,6 +1994,11 @@
template class BuildIdHexstring<ELF64LE>;
template class BuildIdHexstring<ELF64BE>;
+template class DynamicReloc<ELF32LE>;
+template class DynamicReloc<ELF32BE>;
+template class DynamicReloc<ELF64LE>;
+template class DynamicReloc<ELF64BE>;
+
template class OutputSectionFactory<ELF32LE>;
template class OutputSectionFactory<ELF32BE>;
template class OutputSectionFactory<ELF64LE>;
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -304,6 +304,19 @@
}
}
+template <class ELFT> static void fixStaticRelocs(InputSection<ELFT> *I) {
+ for (Relocation<ELFT> &R : I->Relocations)
+ R.Offset += I->OutSecOff;
+}
+
+template <class ELFT>
+static void fixDynamicRelocs(OutputSectionBase<ELFT> *OutSec) {
+ for (DynamicReloc<ELFT> &D : Out<ELFT>::RelaDyn->Relocs)
+ if (D.getOutputSec() == OutSec)
+ D.setSectionOffset(D.getOffset() - D.getOutputSec()->getVA() +
+ cast<InputSection<ELFT>>(D.getInputSec())->OutSecOff);
+}
+
template <class ELFT> void assignOffsets(OutputSectionBase<ELFT> *Sec) {
auto *OutSec = dyn_cast<OutputSection<ELFT>>(Sec);
if (!OutSec) {
@@ -330,12 +343,14 @@
Off = alignTo(Off, I->Alignment);
I->OutSecOff = Off;
Off += I->getSize();
+ fixStaticRelocs(I);
}
// Update section size inside for-loop, so that SIZEOF
// works correctly in the case below:
// .foo { *(.aaa) a = SIZEOF(.foo); *(.bbb) }
Sec->setSize(Off);
}
+ fixDynamicRelocs(Sec);
}
template <class ELFT>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23565.68369.patch
Type: text/x-patch
Size: 2752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160817/6e92eed7/attachment.bin>
More information about the llvm-commits
mailing list