mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-25 17:20:48 +00:00
Change how we iterate over relocations on ELF.
For COFF and MachO, sections semantically have relocations that apply to them. That is not the case on ELF. In relocatable objects (.o), a section with relocations in ELF has offsets to another section where the relocations should be applied. In dynamic objects and executables, relocations don't have an offset, they have a virtual address. The section sh_info may or may not point to another section, but that is not actually used for resolving the relocations. This patch exposes that in the ObjectFile API. It has the following advantages: * Most (all?) clients can handle this more efficiently. They will normally walk all relocations, so doing an effort to iterate in a particular order doesn't save time. * llvm-readobj now prints relocations in the same way the native readelf does. * probably most important, relocations that don't point to any section are now visible. This is the case of relocations in the rela.dyn section. See the updated relocation-executable.test for example. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182908 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "RuntimeDyldMachO.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Object/ELF.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::object;
|
||||
@@ -146,6 +147,7 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectBuffer *InputBuffer) {
|
||||
bool isFirstRelocation = true;
|
||||
unsigned SectionID = 0;
|
||||
StubMap Stubs;
|
||||
section_iterator RelocatedSection = si->getRelocatedSection();
|
||||
|
||||
for (relocation_iterator i = si->begin_relocations(),
|
||||
e = si->end_relocations(); i != e; i.increment(err)) {
|
||||
@@ -153,7 +155,8 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectBuffer *InputBuffer) {
|
||||
|
||||
// If it's the first relocation in this section, find its SectionID
|
||||
if (isFirstRelocation) {
|
||||
SectionID = findOrEmitSection(*obj, *si, true, LocalSections);
|
||||
SectionID =
|
||||
findOrEmitSection(*obj, *RelocatedSection, true, LocalSections);
|
||||
DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n");
|
||||
isFirstRelocation = false;
|
||||
}
|
||||
@@ -214,11 +217,25 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj,
|
||||
unsigned StubBufSize = 0,
|
||||
StubSize = getMaxStubSize();
|
||||
error_code err;
|
||||
const ObjectFile *ObjFile = Obj.getObjectFile();
|
||||
// FIXME: this is an inefficient way to handle this. We should computed the
|
||||
// necessary section allocation size in loadObject by walking all the sections
|
||||
// once.
|
||||
if (StubSize > 0) {
|
||||
for (relocation_iterator i = Section.begin_relocations(),
|
||||
e = Section.end_relocations(); i != e; i.increment(err), Check(err))
|
||||
StubBufSize += StubSize;
|
||||
for (section_iterator SI = ObjFile->begin_sections(),
|
||||
SE = ObjFile->end_sections();
|
||||
SI != SE; SI.increment(err), Check(err)) {
|
||||
section_iterator RelSecI = SI->getRelocatedSection();
|
||||
if (!(RelSecI == Section))
|
||||
continue;
|
||||
|
||||
for (relocation_iterator I = SI->begin_relocations(),
|
||||
E = SI->end_relocations(); I != E; I.increment(err), Check(err)) {
|
||||
StubBufSize += StubSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringRef data;
|
||||
uint64_t Alignment64;
|
||||
Check(Section.getContents(data));
|
||||
|
Reference in New Issue
Block a user