[llvm] bc24e6a - [JITLink][COFF] Use DLLImportDefinitionGenerator for creating PLT stubs.
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 23:27:49 PDT 2022
Author: sunho
Date: 2022-09-10T15:25:44+09:00
New Revision: bc24e6ab7c5ebb40045d0efe49da94b5ccc30b16
URL: https://github.com/llvm/llvm-project/commit/bc24e6ab7c5ebb40045d0efe49da94b5ccc30b16
DIFF: https://github.com/llvm/llvm-project/commit/bc24e6ab7c5ebb40045d0efe49da94b5ccc30b16.diff
LOG: [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
Added:
Modified:
llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp
llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
index 05b66cb2e504d..6e1801cab1700 100644
--- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp
@@ -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;
diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
index f7f10bcce208f..58c8341c07c95 100644
--- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
+++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h
@@ -46,7 +46,6 @@ class COFFLinkGraphBuilder {
const object::COFFObjectFile &getObject() const { return Obj; }
virtual Error addRelocations() = 0;
- virtual Symbol &createDLLImportEntry(StringRef StubName, Symbol &Target) = 0;
Error graphifySections();
Error graphifySymbols();
diff --git a/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp
index 88fc6b98ab9c1..b09dc769b81c9 100644
--- a/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/COFF_x86_64.cpp
@@ -62,12 +62,6 @@ class COFFLinkGraphBuilder_x86_64 : public COFFLinkGraphBuilder {
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 @@ class COFFLinkGraphBuilder_x86_64 : public COFFLinkGraphBuilder {
return Error::success();
}
- x86_64::GOTTableManager DLLImportTable;
-
public:
COFFLinkGraphBuilder_x86_64(const object::COFFObjectFile &Obj, const Triple T)
: COFFLinkGraphBuilder(Obj, std::move(T), getCOFFX86RelocationKindName) {}
diff --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
index d702fefe2de4a..15ca2df3df8d0 100644
--- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
@@ -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();
}
diff --git a/llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s b/llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s
index dd3f53d899c7b..38f4fb11ba012 100644
--- a/llvm/test/ExecutionEngine/JITLink/X86/COFF_x86-64_small_pic_relocations.s
+++ b/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_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
More information about the llvm-commits
mailing list