Index: llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h =================================================================== --- llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h +++ llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h @@ -46,7 +46,6 @@ const object::COFFObjectFile &getObject() const { return Obj; } virtual Error addRelocations() = 0; - virtual Symbol &createDLLImportEntry(StringRef StubName, Symbol &Target) = 0; Error graphifySections(); Error graphifySymbols(); Index: llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp =================================================================== --- llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp +++ llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp @@ -227,17 +227,7 @@ << " (index: " << SectionIndex << ") \n"; }); else if (Sym->isUndefined()) { - if (SymbolName.startswith(getDLLImportStubPrefix())) { - if (Sym->getValue() != 0) - return make_error( - "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(); COFFSymbolIndex TagIndex = WeakExternal->TagIndex; Index: llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp =================================================================== --- llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp +++ llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp @@ -62,12 +62,6 @@ 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 @@ return Error::success(); } - x86_64::GOTTableManager DLLImportTable; - public: COFFLinkGraphBuilder_x86_64(const object::COFFObjectFile &Obj, const Triple T) : COFFLinkGraphBuilder(Obj, std::move(T), getCOFFX86RelocationKindName) {} Index: llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp =================================================================== --- llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp +++ llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp @@ -180,8 +180,10 @@ if (auto Err = PlatformJD.define(symbolAliases(std::move(*RuntimeAliases)))) return std::move(Err); + auto &HostFuncJD = ES.createBareJITDylib("$"); + // 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 @@ StaticLibraryDefinitionGenerator::Load(ObjLinkingLayer, OrcRuntimePath); if (!OrcRuntimeArchiveGenerator) return OrcRuntimeArchiveGenerator.takeError(); + PlatformJD.addToLinkOrder(HostFuncJD); // Create the instance. Error Err = Error::success(); @@ -225,6 +228,7 @@ return Err; } + JD.addGenerator(DLLImportDefinitionGenerator::Create(ES, ObjLinkingLayer)); return Error::success(); } Index: llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s =================================================================== --- llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s +++ llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s @@ -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_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