2014-07-18 02:54:50 +08:00
|
|
|
//===---- RuntimeDyldMachOI386.h ---- MachO/I386 specific code. ---*- C++ -*-=//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-07-18 02:54:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H
|
|
|
|
#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
#include "../RuntimeDyldMachO.h"
|
2016-04-28 04:54:49 +08:00
|
|
|
#include <string>
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "dyld"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class RuntimeDyldMachOI386
|
|
|
|
: public RuntimeDyldMachOCRTPBase<RuntimeDyldMachOI386> {
|
|
|
|
public:
|
2014-09-04 12:53:03 +08:00
|
|
|
|
|
|
|
typedef uint32_t TargetPtrT;
|
|
|
|
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
RuntimeDyldMachOI386(RuntimeDyld::MemoryManager &MM,
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbolResolver &Resolver)
|
[MCJIT][Orc] Refactor RTDyldMemoryManager, weave RuntimeDyld::SymbolInfo through
MCJIT.
This patch decouples the two responsibilities of the RTDyldMemoryManager class,
memory management and symbol resolution, into two new classes:
RuntimeDyld::MemoryManager and RuntimeDyld::SymbolResolver.
The symbol resolution interface is modified slightly, from:
uint64_t getSymbolAddress(const std::string &Name);
to:
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name);
The latter passes symbol flags along with symbol addresses, allowing RuntimeDyld
and others to reason about non-strong/non-exported symbols.
The memory management interface removes the following method:
void notifyObjectLoaded(ExecutionEngine *EE,
const object::ObjectFile &) {}
as it is not related to memory management. (Note: Backwards compatibility *is*
maintained for this method in MCJIT and OrcMCJITReplacement, see below).
The RTDyldMemoryManager class remains in-tree for backwards compatibility.
It inherits directly from RuntimeDyld::SymbolResolver, and indirectly from
RuntimeDyld::MemoryManager via the new MCJITMemoryManager class, which
just subclasses RuntimeDyld::MemoryManager and reintroduces the
notifyObjectLoaded method for backwards compatibility).
The EngineBuilder class retains the existing method:
EngineBuilder&
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
and includes two new methods:
EngineBuilder&
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);
EngineBuilder&
setSymbolResolver(std::unique_ptr<RuntimeDyld::SymbolResolver> SR);
Clients should use EITHER:
A single call to setMCJITMemoryManager with an RTDyldMemoryManager.
OR (exclusive)
One call each to each of setMemoryManager and setSymbolResolver.
This patch should be fully compatible with existing uses of RTDyldMemoryManager.
If it is not it should be considered a bug, and the patch either fixed or
reverted.
If clients find the new API to be an improvement the goal will be to deprecate
and eventually remove the RTDyldMemoryManager class in favor of the new classes.
llvm-svn: 233509
2015-03-30 11:37:06 +08:00
|
|
|
: RuntimeDyldMachOCRTPBase(MM, Resolver) {}
|
2014-07-18 02:54:50 +08:00
|
|
|
|
Simplify decoupling between RuntimeDyld/RuntimeDyldChecker, add 'got_addr' util.
This patch reduces the number of functions in the interface between RuntimeDyld
and RuntimeDyldChecker by combining "GetXAddress" and "GetXContent" functions
into "GetXInfo" functions that return a struct describing both the address and
content. The GetStubOffset function is also replaced with a pair of utilities,
GetStubInfo and GetGOTInfo, that fit the new scheme. For RuntimeDyld both of
these functions will return the same result, but for the new JITLink linker
(https://reviews.llvm.org/D58704) these will provide the addresses of PLT stubs
and GOT entries respectively.
For JITLink's use, a 'got_addr' utility has been added to the rtdyld-check
language, and the syntax of 'got_addr' and 'stub_addr' has been changed: both
functions now take two arguments, a 'stub container name' and a target symbol
name. For llvm-rtdyld/RuntimeDyld the stub container name is the object file
name and section name, separated by a slash. E.g.:
rtdyld-check: *{8}(stub_addr(foo.o/__text, y)) = y
For the upcoming llvm-jitlink utility, which creates stubs on a per-file basis
rather than a per-section basis, the container name is just the file name. E.g.:
jitlink-check: *{8}(got_addr(foo.o, y)) = y
llvm-svn: 358295
2019-04-13 02:07:28 +08:00
|
|
|
unsigned getMaxStubSize() const override { return 0; }
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
unsigned getStubAlignment() override { return 1; }
|
|
|
|
|
2016-04-28 04:24:48 +08:00
|
|
|
Expected<relocation_iterator>
|
2014-07-18 02:54:50 +08:00
|
|
|
processRelocationRef(unsigned SectionID, relocation_iterator RelI,
|
2014-11-27 00:54:40 +08:00
|
|
|
const ObjectFile &BaseObjT,
|
|
|
|
ObjSectionToIDMap &ObjSectionToID,
|
2014-11-27 13:40:13 +08:00
|
|
|
StubMap &Stubs) override {
|
2014-07-18 02:54:50 +08:00
|
|
|
const MachOObjectFile &Obj =
|
2014-11-27 00:54:40 +08:00
|
|
|
static_cast<const MachOObjectFile &>(BaseObjT);
|
2014-07-18 02:54:50 +08:00
|
|
|
MachO::any_relocation_info RelInfo =
|
|
|
|
Obj.getRelocation(RelI->getRawDataRefImpl());
|
|
|
|
uint32_t RelType = Obj.getAnyRelocationType(RelInfo);
|
|
|
|
|
|
|
|
if (Obj.isRelocationScattered(RelInfo)) {
|
|
|
|
if (RelType == MachO::GENERIC_RELOC_SECTDIFF ||
|
|
|
|
RelType == MachO::GENERIC_RELOC_LOCAL_SECTDIFF)
|
2014-11-27 00:54:40 +08:00
|
|
|
return processSECTDIFFRelocation(SectionID, RelI, Obj,
|
2014-07-18 02:54:50 +08:00
|
|
|
ObjSectionToID);
|
2014-09-10 08:13:42 +08:00
|
|
|
else if (RelType == MachO::GENERIC_RELOC_VANILLA)
|
2015-07-25 01:40:04 +08:00
|
|
|
return processScatteredVANILLA(SectionID, RelI, Obj, ObjSectionToID);
|
2016-04-28 08:49:37 +08:00
|
|
|
return make_error<RuntimeDyldError>(("Unhandled I386 scattered relocation "
|
|
|
|
"type: " + Twine(RelType)).str());
|
2016-04-28 04:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (RelType) {
|
|
|
|
UNIMPLEMENTED_RELOC(MachO::GENERIC_RELOC_PAIR);
|
|
|
|
UNIMPLEMENTED_RELOC(MachO::GENERIC_RELOC_PB_LA_PTR);
|
|
|
|
UNIMPLEMENTED_RELOC(MachO::GENERIC_RELOC_TLV);
|
|
|
|
default:
|
|
|
|
if (RelType > MachO::GENERIC_RELOC_TLV)
|
2016-04-28 08:49:37 +08:00
|
|
|
return make_error<RuntimeDyldError>(("MachO I386 relocation type " +
|
|
|
|
Twine(RelType) +
|
|
|
|
" is out of range").str());
|
2016-04-28 04:24:48 +08:00
|
|
|
break;
|
2014-07-18 02:54:50 +08:00
|
|
|
}
|
|
|
|
|
2014-11-27 00:54:40 +08:00
|
|
|
RelocationEntry RE(getRelocationEntry(SectionID, Obj, RelI));
|
2014-08-09 07:12:22 +08:00
|
|
|
RE.Addend = memcpyAddend(RE);
|
2016-04-28 04:24:48 +08:00
|
|
|
RelocationValueRef Value;
|
|
|
|
if (auto ValueOrErr = getRelocationValueRef(Obj, RelI, RE, ObjSectionToID))
|
|
|
|
Value = *ValueOrErr;
|
|
|
|
else
|
|
|
|
return ValueOrErr.takeError();
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
// Addends for external, PC-rel relocations on i386 point back to the zero
|
|
|
|
// offset. Calculate the final offset from the relocation target instead.
|
|
|
|
// This allows us to use the same logic for both external and internal
|
|
|
|
// relocations in resolveI386RelocationRef.
|
|
|
|
// bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);
|
|
|
|
// if (IsExtern && RE.IsPCRel) {
|
|
|
|
// uint64_t RelocAddr = 0;
|
|
|
|
// RelI->getAddress(RelocAddr);
|
|
|
|
// Value.Addend += RelocAddr + 4;
|
|
|
|
// }
|
|
|
|
if (RE.IsPCRel)
|
Remove getRelocationAddress.
Originally added in r139314.
Back then it didn't actually get the address, it got whatever value the
relocation used: address or offset.
The values in different object formats are:
* MachO: Always an offset.
* COFF: Always an address, but when talking about the virtual address of
sections it says: "for simplicity, compilers should set this to zero".
* ELF: An offset for .o files and and address for .so files. In the case of the
.so, the relocation in not linked to any section (sh_info is 0). We can't
really compute an offset.
Some API mappings would be:
* Use getAddress for everything. It would be quite cumbersome. To compute the
address elf has to follow sh_info, which can be corrupted and therefore the
method has to return an ErrorOr. The address of the section is also the same
for every relocation in a section, so we shouldn't have to check the error
and fetch the value for every relocation.
* Use a getValue and make it up to the user to know what it is getting.
* Use a getOffset and:
* Assert for dynamic ELF objects. That is a very peculiar case and it is
probably fair to ask any tool that wants to support it to use ELF.h. The
only tool we have that reads those (llvm-readobj) already does that. The
only other use case I can think of is a dynamic linker.
* Check that COFF .obj files have sections with zero virtual address spaces. If
it turns out that some assembler/compiler produces these, we can change
COFFObjectFile::getRelocationOffset to subtract it. Given COFF format,
this can be done without the need for ErrorOr.
The getRelocationAddress method was never implemented for COFF. It also
had exactly one use in a very peculiar case: a shortcut for adding the
section value to a pcrel reloc on MachO.
Given that, I don't expect that there is any use out there of the C API. If
that is not the case, let me know and I will add it back with the implementation
inlined and do a proper deprecation.
llvm-svn: 241450
2015-07-06 22:55:37 +08:00
|
|
|
makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
|
2014-07-18 02:54:50 +08:00
|
|
|
|
2014-09-07 12:03:32 +08:00
|
|
|
RE.Addend = Value.Offset;
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
if (Value.SymbolName)
|
|
|
|
addRelocationForSymbol(RE, Value.SymbolName);
|
|
|
|
else
|
|
|
|
addRelocationForSection(RE, Value.SectionID);
|
|
|
|
|
|
|
|
return ++RelI;
|
|
|
|
}
|
|
|
|
|
2014-09-03 19:41:21 +08:00
|
|
|
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dumpRelocationToResolve(RE, Value));
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
const SectionEntry &Section = Sections[RE.SectionID];
|
2015-11-24 05:47:41 +08:00
|
|
|
uint8_t *LocalAddress = Section.getAddressWithOffset(RE.Offset);
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
if (RE.IsPCRel) {
|
2015-11-24 05:47:41 +08:00
|
|
|
uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.Offset);
|
2014-07-18 02:54:50 +08:00
|
|
|
Value -= FinalAddress + 4; // see MachOX86_64::resolveRelocation.
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (RE.RelType) {
|
|
|
|
case MachO::GENERIC_RELOC_VANILLA:
|
2014-08-30 07:17:47 +08:00
|
|
|
writeBytesUnaligned(Value + RE.Addend, LocalAddress, 1 << RE.Size);
|
2014-07-18 02:54:50 +08:00
|
|
|
break;
|
|
|
|
case MachO::GENERIC_RELOC_SECTDIFF:
|
|
|
|
case MachO::GENERIC_RELOC_LOCAL_SECTDIFF: {
|
2015-11-24 05:47:41 +08:00
|
|
|
uint64_t SectionABase = Sections[RE.Sections.SectionA].getLoadAddress();
|
|
|
|
uint64_t SectionBBase = Sections[RE.Sections.SectionB].getLoadAddress();
|
2014-07-18 02:54:50 +08:00
|
|
|
assert((Value == SectionABase || Value == SectionBBase) &&
|
|
|
|
"Unexpected SECTDIFF relocation value.");
|
|
|
|
Value = SectionABase - SectionBBase + RE.Addend;
|
2014-08-30 07:17:47 +08:00
|
|
|
writeBytesUnaligned(Value, LocalAddress, 1 << RE.Size);
|
2014-07-18 02:54:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-04-28 04:24:48 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid relocation type!");
|
2014-07-18 02:54:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 04:24:48 +08:00
|
|
|
Error finalizeSection(const ObjectFile &Obj, unsigned SectionID,
|
2014-07-18 02:54:50 +08:00
|
|
|
const SectionRef &Section) {
|
|
|
|
StringRef Name;
|
2019-08-14 19:10:11 +08:00
|
|
|
if (Expected<StringRef> NameOrErr = Section.getName())
|
|
|
|
Name = *NameOrErr;
|
|
|
|
else
|
|
|
|
consumeError(NameOrErr.takeError());
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
if (Name == "__jump_table")
|
2016-04-28 04:24:48 +08:00
|
|
|
return populateJumpTable(cast<MachOObjectFile>(Obj), Section, SectionID);
|
2014-07-18 02:54:50 +08:00
|
|
|
else if (Name == "__pointers")
|
2016-04-28 04:24:48 +08:00
|
|
|
return populateIndirectSymbolPointersSection(cast<MachOObjectFile>(Obj),
|
|
|
|
Section, SectionID);
|
|
|
|
return Error::success();
|
2014-07-18 02:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-04-28 04:24:48 +08:00
|
|
|
Expected<relocation_iterator>
|
2014-07-18 02:54:50 +08:00
|
|
|
processSECTDIFFRelocation(unsigned SectionID, relocation_iterator RelI,
|
2014-11-27 00:54:40 +08:00
|
|
|
const ObjectFile &BaseObjT,
|
2014-07-18 02:54:50 +08:00
|
|
|
ObjSectionToIDMap &ObjSectionToID) {
|
2014-11-27 00:54:40 +08:00
|
|
|
const MachOObjectFile &Obj =
|
|
|
|
static_cast<const MachOObjectFile&>(BaseObjT);
|
2014-07-18 02:54:50 +08:00
|
|
|
MachO::any_relocation_info RE =
|
2014-11-27 00:54:40 +08:00
|
|
|
Obj.getRelocation(RelI->getRawDataRefImpl());
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
SectionEntry &Section = Sections[SectionID];
|
2014-11-27 00:54:40 +08:00
|
|
|
uint32_t RelocType = Obj.getAnyRelocationType(RE);
|
|
|
|
bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
|
|
|
|
unsigned Size = Obj.getAnyRelocationLength(RE);
|
2015-06-30 07:29:12 +08:00
|
|
|
uint64_t Offset = RelI->getOffset();
|
2015-11-24 05:47:41 +08:00
|
|
|
uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
|
2014-07-18 02:54:50 +08:00
|
|
|
unsigned NumBytes = 1 << Size;
|
2014-10-11 07:07:09 +08:00
|
|
|
uint64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
++RelI;
|
|
|
|
MachO::any_relocation_info RE2 =
|
2014-11-27 00:54:40 +08:00
|
|
|
Obj.getRelocation(RelI->getRawDataRefImpl());
|
2014-07-18 02:54:50 +08:00
|
|
|
|
2014-11-27 00:54:40 +08:00
|
|
|
uint32_t AddrA = Obj.getScatteredRelocationValue(RE);
|
|
|
|
section_iterator SAI = getSectionByAddress(Obj, AddrA);
|
|
|
|
assert(SAI != Obj.section_end() && "Can't find section for address A");
|
2014-10-08 23:28:58 +08:00
|
|
|
uint64_t SectionABase = SAI->getAddress();
|
2014-07-18 02:54:50 +08:00
|
|
|
uint64_t SectionAOffset = AddrA - SectionABase;
|
|
|
|
SectionRef SectionA = *SAI;
|
2014-10-08 23:28:58 +08:00
|
|
|
bool IsCode = SectionA.isText();
|
2016-04-28 04:24:48 +08:00
|
|
|
uint32_t SectionAID = ~0U;
|
|
|
|
if (auto SectionAIDOrErr =
|
|
|
|
findOrEmitSection(Obj, SectionA, IsCode, ObjSectionToID))
|
|
|
|
SectionAID = *SectionAIDOrErr;
|
|
|
|
else
|
|
|
|
return SectionAIDOrErr.takeError();
|
2014-07-18 02:54:50 +08:00
|
|
|
|
2014-11-27 00:54:40 +08:00
|
|
|
uint32_t AddrB = Obj.getScatteredRelocationValue(RE2);
|
|
|
|
section_iterator SBI = getSectionByAddress(Obj, AddrB);
|
|
|
|
assert(SBI != Obj.section_end() && "Can't find section for address B");
|
2014-10-08 23:28:58 +08:00
|
|
|
uint64_t SectionBBase = SBI->getAddress();
|
2014-07-18 02:54:50 +08:00
|
|
|
uint64_t SectionBOffset = AddrB - SectionBBase;
|
|
|
|
SectionRef SectionB = *SBI;
|
2016-04-28 04:24:48 +08:00
|
|
|
uint32_t SectionBID = ~0U;
|
|
|
|
if (auto SectionBIDOrErr =
|
|
|
|
findOrEmitSection(Obj, SectionB, IsCode, ObjSectionToID))
|
|
|
|
SectionBID = *SectionBIDOrErr;
|
|
|
|
else
|
|
|
|
return SectionBIDOrErr.takeError();
|
2014-07-18 02:54:50 +08:00
|
|
|
|
2015-05-28 04:50:01 +08:00
|
|
|
// Compute the addend 'C' from the original expression 'A - B + C'.
|
|
|
|
Addend -= AddrA - AddrB;
|
2014-07-18 02:54:50 +08:00
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Found SECTDIFF: AddrA: " << AddrA
|
|
|
|
<< ", AddrB: " << AddrB << ", Addend: " << Addend
|
|
|
|
<< ", SectionA ID: " << SectionAID << ", SectionAOffset: "
|
|
|
|
<< SectionAOffset << ", SectionB ID: " << SectionBID
|
|
|
|
<< ", SectionBOffset: " << SectionBOffset << "\n");
|
2015-05-28 04:50:01 +08:00
|
|
|
RelocationEntry R(SectionID, Offset, RelocType, Addend, SectionAID,
|
|
|
|
SectionAOffset, SectionBID, SectionBOffset,
|
|
|
|
IsPCRel, Size);
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
addRelocationForSection(R, SectionAID);
|
|
|
|
|
|
|
|
return ++RelI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate stubs in __jump_table section.
|
2016-04-28 04:24:48 +08:00
|
|
|
Error populateJumpTable(const MachOObjectFile &Obj,
|
|
|
|
const SectionRef &JTSection,
|
2014-07-18 02:54:50 +08:00
|
|
|
unsigned JTSectionID) {
|
|
|
|
MachO::dysymtab_command DySymTabCmd = Obj.getDysymtabLoadCommand();
|
|
|
|
MachO::section Sec32 = Obj.getSection(JTSection.getRawDataRefImpl());
|
|
|
|
uint32_t JTSectionSize = Sec32.size;
|
|
|
|
unsigned FirstIndirectSymbol = Sec32.reserved1;
|
|
|
|
unsigned JTEntrySize = Sec32.reserved2;
|
|
|
|
unsigned NumJTEntries = JTSectionSize / JTEntrySize;
|
|
|
|
uint8_t *JTSectionAddr = getSectionAddress(JTSectionID);
|
|
|
|
unsigned JTEntryOffset = 0;
|
|
|
|
|
2016-04-28 04:24:48 +08:00
|
|
|
if (JTSectionSize % JTEntrySize != 0)
|
|
|
|
return make_error<RuntimeDyldError>("Jump-table section does not contain "
|
|
|
|
"a whole number of stubs?");
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < NumJTEntries; ++i) {
|
|
|
|
unsigned SymbolIndex =
|
|
|
|
Obj.getIndirectSymbolTableEntry(DySymTabCmd, FirstIndirectSymbol + i);
|
|
|
|
symbol_iterator SI = Obj.getSymbolByIndex(SymbolIndex);
|
2016-04-21 05:24:34 +08:00
|
|
|
Expected<StringRef> IndirectSymbolName = SI->getName();
|
2016-04-28 04:24:48 +08:00
|
|
|
if (!IndirectSymbolName)
|
|
|
|
return IndirectSymbolName.takeError();
|
2014-07-18 02:54:50 +08:00
|
|
|
uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
|
|
|
|
createStubFunction(JTEntryAddr);
|
|
|
|
RelocationEntry RE(JTSectionID, JTEntryOffset + 1,
|
|
|
|
MachO::GENERIC_RELOC_VANILLA, 0, true, 2);
|
2015-07-03 04:55:21 +08:00
|
|
|
addRelocationForSymbol(RE, *IndirectSymbolName);
|
2014-07-18 02:54:50 +08:00
|
|
|
JTEntryOffset += JTEntrySize;
|
|
|
|
}
|
2016-04-28 04:24:48 +08:00
|
|
|
|
|
|
|
return Error::success();
|
2014-07-18 02:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2014-07-18 02:54:50 +08:00
|
|
|
|
|
|
|
#undef DEBUG_TYPE
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#endif
|