[JITLink][COFF] Use DLLImportDefinitionGenerator for creating PLT stubs.

Uses DLLImportDefinitionGenerator for creating PLT stubs. It removes previous approach for dllimport stub creation which can't deal with jump thunks.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132524
This commit is contained in:
sunho 2022-09-10 15:25:44 +09:00
parent 545affbf79
commit bc24e6ab7c
5 changed files with 6 additions and 37 deletions

View File

@ -227,17 +227,7 @@ Error COFFLinkGraphBuilder::graphifySymbols() {
<< " (index: " << SectionIndex << ") \n";
});
else if (Sym->isUndefined()) {
if (SymbolName.startswith(getDLLImportStubPrefix())) {
if (Sym->getValue() != 0)
return make_error<JITLinkError>(
"DLL import symbol has non-zero offset");
auto ExternalSym = createExternalSymbol(
SymIndex, SymbolName.drop_front(getDLLImportStubPrefix().size()),
*Sym, Sec);
GSym = &createDLLImportEntry(SymbolName, *ExternalSym);
} else
GSym = createExternalSymbol(SymIndex, SymbolName, *Sym, Sec);
GSym = createExternalSymbol(SymIndex, SymbolName, *Sym, Sec);
} else if (Sym->isWeakExternal()) {
auto *WeakExternal = Sym->getAux<object::coff_aux_weak_external>();
COFFSymbolIndex TagIndex = WeakExternal->TagIndex;

View File

@ -46,7 +46,6 @@ protected:
const object::COFFObjectFile &getObject() const { return Obj; }
virtual Error addRelocations() = 0;
virtual Symbol &createDLLImportEntry(StringRef StubName, Symbol &Target) = 0;
Error graphifySections();
Error graphifySymbols();

View File

@ -62,12 +62,6 @@ private:
return Error::success();
}
Symbol &createDLLImportEntry(StringRef StubName, Symbol &Target) override {
auto &Sym = DLLImportTable.getEntryForTarget(getGraph(), Target);
Sym.setName(StubName);
return Sym;
}
Error addSingleRelocation(const object::RelocationRef &Rel,
const object::SectionRef &FixupSect,
Block &BlockToFix) {
@ -186,8 +180,6 @@ private:
return Error::success();
}
x86_64::GOTTableManager DLLImportTable;
public:
COFFLinkGraphBuilder_x86_64(const object::COFFObjectFile &Obj, const Triple T)
: COFFLinkGraphBuilder(Obj, std::move(T), getCOFFX86RelocationKindName) {}

View File

@ -180,8 +180,10 @@ COFFPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
if (auto Err = PlatformJD.define(symbolAliases(std::move(*RuntimeAliases))))
return std::move(Err);
auto &HostFuncJD = ES.createBareJITDylib("$<PlatformRuntimeHostFuncJD>");
// Add JIT-dispatch function support symbols.
if (auto Err = PlatformJD.define(absoluteSymbols(
if (auto Err = HostFuncJD.define(absoluteSymbols(
{{ES.intern("__orc_rt_jit_dispatch"),
{EPC.getJITDispatchInfo().JITDispatchFunction.getValue(),
JITSymbolFlags::Exported}},
@ -195,6 +197,7 @@ COFFPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath);
if (!OrcRuntimeArchiveGenerator)
return OrcRuntimeArchiveGenerator.takeError();
PlatformJD.addToLinkOrder(HostFuncJD);
// Create the instance.
Error Err = Error::success();
@ -225,6 +228,7 @@ Error COFFPlatform::setupJITDylib(JITDylib &JD) {
return Err;
}
JD.addGenerator(DLLImportDefinitionGenerator::Create(ES, ObjLinkingLayer));
return Error::success();
}

View File

@ -4,7 +4,6 @@
# RUN: llvm-jitlink -noexec \
# RUN: -slab-allocate 100Kb -slab-address 0xfff00000 -slab-page-size 4096 \
# RUN: -abs external_data=0xdeadbeef \
# RUN: -abs extern_out_of_range32=0x7fff00000000 \
# RUN: -check %s %t/coff_sm_reloc.o
.text
@ -40,21 +39,6 @@ test_rel32_func:
test_rel32_data:
leaq named_data(%rip), %rax
# Check a dllimport stub for target out of reach is created as a GOT entry.
# jitlink-check: decode_operand(test_call_dllimport, 3) = \
# jitlink-check: got_addr(coff_sm_reloc.o, extern_out_of_range32) - \
# jitlink-check: next_pc(test_call_dllimport)
# jitlink-check: *{8}(got_addr(coff_sm_reloc.o, extern_out_of_range32)) = \
# jitlink-check: extern_out_of_range32
.def test_call_dllimport;
.scl 2;
.type 32;
.endef
.globl test_call_dllimport
.p2align 4, 0x90
test_call_dllimport:
callq *__imp_extern_out_of_range32(%rip)
# Check IMAGE_REL_AMD64_ADDR64 sets address of symbol to the fixup position.
# jitlink-check: *{8}(test_addr64) = named_data
.text