forked from OSchip/llvm-project
Propagate relocation info to resolveRelocation.
This gets most of the MCJITs tests passing with MachO. llvm-svn: 180716
This commit is contained in:
parent
63524b9453
commit
f1f1c626e7
|
@ -391,26 +391,14 @@ void RuntimeDyldImpl::reassignSectionAddress(unsigned SectionID,
|
||||||
Sections[SectionID].LoadAddress = Addr;
|
Sections[SectionID].LoadAddress = Addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuntimeDyldImpl::resolveRelocationEntry(const RelocationEntry &RE,
|
|
||||||
uint64_t Value) {
|
|
||||||
// Ignore relocations for sections that were not loaded
|
|
||||||
if (Sections[RE.SectionID].Address != 0) {
|
|
||||||
DEBUG(dbgs() << "\tSectionID: " << RE.SectionID
|
|
||||||
<< " + " << RE.Offset << " ("
|
|
||||||
<< format("%p", Sections[RE.SectionID].Address + RE.Offset) << ")"
|
|
||||||
<< " RelType: " << RE.RelType
|
|
||||||
<< " Addend: " << RE.Addend
|
|
||||||
<< "\n");
|
|
||||||
|
|
||||||
resolveRelocation(Sections[RE.SectionID], RE.Offset,
|
|
||||||
Value, RE.RelType, RE.Addend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RuntimeDyldImpl::resolveRelocationList(const RelocationList &Relocs,
|
void RuntimeDyldImpl::resolveRelocationList(const RelocationList &Relocs,
|
||||||
uint64_t Value) {
|
uint64_t Value) {
|
||||||
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
|
||||||
resolveRelocationEntry(Relocs[i], Value);
|
const RelocationEntry &RE = Relocs[i];
|
||||||
|
// Ignore relocations for sections that were not loaded
|
||||||
|
if (Sections[RE.SectionID].Address == 0)
|
||||||
|
continue;
|
||||||
|
resolveRelocation(RE, Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -560,6 +560,12 @@ void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RuntimeDyldELF::resolveRelocation(const RelocationEntry &RE,
|
||||||
|
uint64_t Value) {
|
||||||
|
const SectionEntry &Section = Sections[RE.SectionID];
|
||||||
|
return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend);
|
||||||
|
}
|
||||||
|
|
||||||
void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section,
|
void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section,
|
||||||
uint64_t Offset,
|
uint64_t Offset,
|
||||||
uint64_t Value,
|
uint64_t Value,
|
||||||
|
|
|
@ -31,6 +31,12 @@ namespace {
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
class RuntimeDyldELF : public RuntimeDyldImpl {
|
class RuntimeDyldELF : public RuntimeDyldImpl {
|
||||||
|
void resolveRelocation(const SectionEntry &Section,
|
||||||
|
uint64_t Offset,
|
||||||
|
uint64_t Value,
|
||||||
|
uint32_t Type,
|
||||||
|
int64_t Addend);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resolveX86_64Relocation(const SectionEntry &Section,
|
void resolveX86_64Relocation(const SectionEntry &Section,
|
||||||
uint64_t Offset,
|
uint64_t Offset,
|
||||||
|
@ -62,11 +68,7 @@ protected:
|
||||||
uint32_t Type,
|
uint32_t Type,
|
||||||
int64_t Addend);
|
int64_t Addend);
|
||||||
|
|
||||||
virtual void resolveRelocation(const SectionEntry &Section,
|
virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
|
||||||
uint64_t Offset,
|
|
||||||
uint64_t Value,
|
|
||||||
uint32_t Type,
|
|
||||||
int64_t Addend);
|
|
||||||
|
|
||||||
virtual void processRelocationRef(unsigned SectionID,
|
virtual void processRelocationRef(unsigned SectionID,
|
||||||
relocation_iterator RelI,
|
relocation_iterator RelI,
|
||||||
|
|
|
@ -89,8 +89,20 @@ public:
|
||||||
/// used to make a relocation section relative instead of symbol relative.
|
/// used to make a relocation section relative instead of symbol relative.
|
||||||
intptr_t Addend;
|
intptr_t Addend;
|
||||||
|
|
||||||
|
/// True if this is a PCRel relocation (MachO specific).
|
||||||
|
bool IsPCRel;
|
||||||
|
|
||||||
|
/// The size of this relocation (MachO specific).
|
||||||
|
unsigned Size;
|
||||||
|
|
||||||
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
|
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
|
||||||
: SectionID(id), Offset(offset), RelType(type), Addend(addend) {}
|
: SectionID(id), Offset(offset), RelType(type), Addend(addend),
|
||||||
|
IsPCRel(false), Size(0) {}
|
||||||
|
|
||||||
|
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend,
|
||||||
|
bool IsPCRel, unsigned Size)
|
||||||
|
: SectionID(id), Offset(offset), RelType(type), Addend(addend),
|
||||||
|
IsPCRel(IsPCRel), Size(Size) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class RelocationValueRef {
|
class RelocationValueRef {
|
||||||
|
@ -257,7 +269,6 @@ protected:
|
||||||
|
|
||||||
/// \brief Resolves relocations from Relocs list with address from Value.
|
/// \brief Resolves relocations from Relocs list with address from Value.
|
||||||
void resolveRelocationList(const RelocationList &Relocs, uint64_t Value);
|
void resolveRelocationList(const RelocationList &Relocs, uint64_t Value);
|
||||||
void resolveRelocationEntry(const RelocationEntry &RE, uint64_t Value);
|
|
||||||
|
|
||||||
/// \brief A object file specific relocation resolver
|
/// \brief A object file specific relocation resolver
|
||||||
/// \param Section The section where the relocation is being applied
|
/// \param Section The section where the relocation is being applied
|
||||||
|
@ -266,11 +277,7 @@ protected:
|
||||||
/// \param Type object file specific relocation type
|
/// \param Type object file specific relocation type
|
||||||
/// \param Addend A constant addend used to compute the value to be stored
|
/// \param Addend A constant addend used to compute the value to be stored
|
||||||
/// into the relocatable field
|
/// into the relocatable field
|
||||||
virtual void resolveRelocation(const SectionEntry &Section,
|
virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value) = 0;
|
||||||
uint64_t Offset,
|
|
||||||
uint64_t Value,
|
|
||||||
uint32_t Type,
|
|
||||||
int64_t Addend) = 0;
|
|
||||||
|
|
||||||
/// \brief Parses the object file relocation and stores it to Relocations
|
/// \brief Parses the object file relocation and stores it to Relocations
|
||||||
/// or SymbolRelocations (this depends on the object file type).
|
/// or SymbolRelocations (this depends on the object file type).
|
||||||
|
|
|
@ -21,16 +21,24 @@ using namespace llvm::object;
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
void RuntimeDyldMachO::resolveRelocation(const RelocationEntry &RE,
|
||||||
|
uint64_t Value) {
|
||||||
|
const SectionEntry &Section = Sections[RE.SectionID];
|
||||||
|
return resolveRelocation(Section, RE.Offset, Value, RE.RelType, RE.Addend,
|
||||||
|
RE.IsPCRel, RE.Size);
|
||||||
|
}
|
||||||
|
|
||||||
void RuntimeDyldMachO::resolveRelocation(const SectionEntry &Section,
|
void RuntimeDyldMachO::resolveRelocation(const SectionEntry &Section,
|
||||||
uint64_t Offset,
|
uint64_t Offset,
|
||||||
uint64_t Value,
|
uint64_t Value,
|
||||||
uint32_t Type,
|
uint32_t Type,
|
||||||
int64_t Addend) {
|
int64_t Addend,
|
||||||
|
bool isPCRel,
|
||||||
|
unsigned LogSize) {
|
||||||
uint8_t *LocalAddress = Section.Address + Offset;
|
uint8_t *LocalAddress = Section.Address + Offset;
|
||||||
uint64_t FinalAddress = Section.LoadAddress + Offset;
|
uint64_t FinalAddress = Section.LoadAddress + Offset;
|
||||||
bool isPCRel = (Type >> 24) & 1;
|
unsigned MachoType = Type;
|
||||||
unsigned MachoType = (Type >> 28) & 0xf;
|
unsigned Size = 1 << LogSize;
|
||||||
unsigned Size = 1 << ((Type >> 25) & 3);
|
|
||||||
|
|
||||||
DEBUG(dbgs() << "resolveRelocation LocalAddress: "
|
DEBUG(dbgs() << "resolveRelocation LocalAddress: "
|
||||||
<< format("%p", LocalAddress)
|
<< format("%p", LocalAddress)
|
||||||
|
@ -220,6 +228,8 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
|
||||||
SectionEntry &Section = Sections[SectionID];
|
SectionEntry &Section = Sections[SectionID];
|
||||||
|
|
||||||
bool isExtern = MachO->getPlainRelocationExternal(RE);
|
bool isExtern = MachO->getPlainRelocationExternal(RE);
|
||||||
|
bool IsPCRel = MachO->getAnyRelocationPCRel(RE);
|
||||||
|
unsigned Size = MachO->getAnyRelocationLength(RE);
|
||||||
if (isExtern) {
|
if (isExtern) {
|
||||||
// Obtain the symbol name which is referenced in the relocation
|
// Obtain the symbol name which is referenced in the relocation
|
||||||
SymbolRef Symbol;
|
SymbolRef Symbol;
|
||||||
|
@ -276,7 +286,7 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
|
||||||
if (i != Stubs.end())
|
if (i != Stubs.end())
|
||||||
resolveRelocation(Section, Offset,
|
resolveRelocation(Section, Offset,
|
||||||
(uint64_t)Section.Address + i->second,
|
(uint64_t)Section.Address + i->second,
|
||||||
RelType, 0);
|
RelType, 0, IsPCRel, Size);
|
||||||
else {
|
else {
|
||||||
// Create a new stub function.
|
// Create a new stub function.
|
||||||
Stubs[Value] = Section.StubOffset;
|
Stubs[Value] = Section.StubOffset;
|
||||||
|
@ -290,11 +300,12 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID,
|
||||||
addRelocationForSection(RE, Value.SectionID);
|
addRelocationForSection(RE, Value.SectionID);
|
||||||
resolveRelocation(Section, Offset,
|
resolveRelocation(Section, Offset,
|
||||||
(uint64_t)Section.Address + Section.StubOffset,
|
(uint64_t)Section.Address + Section.StubOffset,
|
||||||
RelType, 0);
|
RelType, 0, IsPCRel, Size);
|
||||||
Section.StubOffset += getMaxStubSize();
|
Section.StubOffset += getMaxStubSize();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RelocationEntry RE(SectionID, Offset, RelType, Value.Addend);
|
RelocationEntry RE(SectionID, Offset, RelType, Value.Addend,
|
||||||
|
IsPCRel, Size);
|
||||||
if (Value.SymbolName)
|
if (Value.SymbolName)
|
||||||
addRelocationForSymbol(RE, Value.SymbolName);
|
addRelocationForSymbol(RE, Value.SymbolName);
|
||||||
else
|
else
|
||||||
|
|
|
@ -55,12 +55,15 @@ protected:
|
||||||
const SymbolTableMap &Symbols,
|
const SymbolTableMap &Symbols,
|
||||||
StubMap &Stubs);
|
StubMap &Stubs);
|
||||||
|
|
||||||
|
void resolveRelocation(const SectionEntry &Section,
|
||||||
|
uint64_t Offset,
|
||||||
|
uint64_t Value,
|
||||||
|
uint32_t Type,
|
||||||
|
int64_t Addend,
|
||||||
|
bool isPCRel,
|
||||||
|
unsigned Size);
|
||||||
public:
|
public:
|
||||||
virtual void resolveRelocation(const SectionEntry &Section,
|
virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value);
|
||||||
uint64_t Offset,
|
|
||||||
uint64_t Value,
|
|
||||||
uint32_t Type,
|
|
||||||
int64_t Addend);
|
|
||||||
|
|
||||||
RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
|
RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: %lli_mcjit %s
|
; RUN: %lli_mcjit %s
|
||||||
|
; XFAIL: darwin
|
||||||
;
|
;
|
||||||
; Verify relocations to global symbols with addend work correctly.
|
; Verify relocations to global symbols with addend work correctly.
|
||||||
;
|
;
|
||||||
|
|
|
@ -14,10 +14,7 @@ if ('X86' in targets) | ('ARM' in targets) | ('Mips' in targets) | \
|
||||||
else:
|
else:
|
||||||
config.unsupported = True
|
config.unsupported = True
|
||||||
|
|
||||||
if root.host_arch not in ['x86', 'x86_64', 'ARM', 'Mips', 'PowerPC']:
|
if root.host_arch not in ['i386', 'x86', 'x86_64', 'ARM', 'Mips', 'PowerPC']:
|
||||||
config.unsupported = True
|
|
||||||
|
|
||||||
if root.host_os in ['Darwin']:
|
|
||||||
config.unsupported = True
|
config.unsupported = True
|
||||||
|
|
||||||
if 'powerpc' in root.target_triple and not 'powerpc64' in root.target_triple:
|
if 'powerpc' in root.target_triple and not 'powerpc64' in root.target_triple:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: %lli_mcjit -O0 %s
|
; RUN: %lli_mcjit -O0 %s
|
||||||
|
; XFAIL: darwin
|
||||||
|
|
||||||
; This test checks that common symbols have been allocated addresses honouring
|
; This test checks that common symbols have been allocated addresses honouring
|
||||||
; the alignment requirement.
|
; the alignment requirement.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: %lli_mcjit %s > /dev/null
|
; RUN: %lli_mcjit %s > /dev/null
|
||||||
|
; XFAIL: darwin
|
||||||
@var = global i32 1, align 4
|
@var = global i32 1, align 4
|
||||||
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @ctor_func }]
|
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @ctor_func }]
|
||||||
@llvm.global_dtors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @dtor_func }]
|
@llvm.global_dtors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @dtor_func }]
|
||||||
|
|
Loading…
Reference in New Issue