[llvm] 5bac8d4 - Revert "[ORC] Export __cxa_atexit from the main JITDylib in LLJIT."
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 19:49:58 PDT 2020
Author: Nico Weber
Date: 2020-04-01T22:49:38-04:00
New Revision: 5bac8d427d59bd2f25e51980ddbe18017bc45493
URL: https://github.com/llvm/llvm-project/commit/5bac8d427d59bd2f25e51980ddbe18017bc45493
DIFF: https://github.com/llvm/llvm-project/commit/5bac8d427d59bd2f25e51980ddbe18017bc45493.diff
LOG: Revert "[ORC] Export __cxa_atexit from the main JITDylib in LLJIT."
This reverts commit 0071eaaf0892d7ef733578312abefdcf84311071.
Inputs/noop-main.ll wasn't checked in, so this breaks check-llvm
everywhere.
Added:
Modified:
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 9a868a6fbac3..3be1381652a1 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -29,6 +29,14 @@ using namespace llvm::orc;
namespace {
+/// Add a reference to the __dso_handle global to the given module.
+/// Returns a reference to the __dso_handle IR decl.
+GlobalVariable *addDSOHandleDecl(Module &M) {
+ auto DSOHandleTy = StructType::create(M.getContext(), "lljit.dso_handle");
+ return new GlobalVariable(M, DSOHandleTy, true, GlobalValue::ExternalLinkage,
+ nullptr, "__dso_handle");
+}
+
/// Adds helper function decls and wrapper functions that call the helper with
/// some additional prefix arguments.
///
@@ -135,10 +143,11 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
SymbolMap StdInterposes;
StdInterposes[Mangle("__lljit.platform_support_instance")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(this),
- JITSymbolFlags::Exported);
+ JITEvaluatedSymbol(pointerToJITTargetAddress(this), JITSymbolFlags());
StdInterposes[Mangle("__lljit.cxa_atexit_helper")] = JITEvaluatedSymbol(
pointerToJITTargetAddress(registerAtExitHelper), JITSymbolFlags());
+ StdInterposes[Mangle("__lljit.run_atexits_helper")] = JITEvaluatedSymbol(
+ pointerToJITTargetAddress(runAtExitsHelper), JITSymbolFlags());
cantFail(
J.getMainJITDylib().define(absoluteSymbols(std::move(StdInterposes))));
@@ -150,14 +159,6 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
/// Adds a module that defines the __dso_handle global.
Error setupJITDylib(JITDylib &JD) {
-
- // Add per-jitdylib standard interposes.
- MangleAndInterner Mangle(getExecutionSession(), J.getDataLayout());
- SymbolMap PerJDInterposes;
- PerJDInterposes[Mangle("__lljit.run_atexits_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(runAtExitsHelper), JITSymbolFlags());
- cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
-
auto Ctx = std::make_unique<LLVMContext>();
auto M = std::make_unique<Module>("__standard_lib", *Ctx);
M->setDataLayout(J.getDataLayout());
@@ -167,23 +168,9 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
*M, Int64Ty, true, GlobalValue::ExternalLinkage,
ConstantInt::get(Int64Ty, reinterpret_cast<uintptr_t>(&JD)),
"__dso_handle");
- DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
+ DSOHandle->setVisibility(GlobalValue::HiddenVisibility);
DSOHandle->setInitializer(
ConstantInt::get(Int64Ty, pointerToJITTargetAddress(&JD)));
-
- auto *GenericIRPlatformSupportTy =
- StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
-
- auto *PlatformInstanceDecl = new GlobalVariable(
- *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
- nullptr, "__lljit.platform_support_instance");
-
- auto *VoidTy = Type::getVoidTy(*Ctx);
- addHelperAndWrapper(
- *M, "__lljit_run_atexits", FunctionType::get(VoidTy, {}, false),
- GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
- {PlatformInstanceDecl, DSOHandle});
-
return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
}
@@ -329,16 +316,6 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
}
});
- LLVM_DEBUG({
- dbgs() << "JITDylib deinit order is [ ";
- for (auto *JD : DFSLinkOrder)
- dbgs() << "\"" << JD->getName() << "\" ";
- dbgs() << "]\n";
- dbgs() << "Looking up deinit functions:\n";
- for (auto &KV : LookupSymbols)
- dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
- });
-
auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
if (!LookupResult)
@@ -410,19 +387,11 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
static void registerAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
void *DSOHandle) {
- LLVM_DEBUG({
- dbgs() << "Registering atexit function " << (void *)F << " for JD "
- << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
- });
static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
F, Ctx, DSOHandle);
}
static void runAtExitsHelper(void *Self, void *DSOHandle) {
- LLVM_DEBUG({
- dbgs() << "Running atexit functions for JD "
- << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
- });
static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.runAtExits(
DSOHandle);
}
@@ -441,6 +410,8 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
*M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
nullptr, "__lljit.platform_support_instance");
+ auto *DSOHandleDecl = addDSOHandleDecl(*M);
+
auto *Int8Ty = Type::getInt8Ty(*Ctx);
auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
auto *VoidTy = Type::getVoidTy(*Ctx);
@@ -452,9 +423,14 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
*M, "__cxa_atexit",
FunctionType::get(IntTy, {AtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
false),
- GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
+ GlobalValue::HiddenVisibility, "__lljit.cxa_atexit_helper",
{PlatformInstanceDecl});
+ addHelperAndWrapper(
+ *M, "__lljit_run_atexits", FunctionType::get(VoidTy, {}, false),
+ GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
+ {PlatformInstanceDecl, DSOHandleDecl});
+
return ThreadSafeModule(std::move(M), std::move(Ctx));
}
@@ -700,7 +676,7 @@ class MachOPlatformSupport : public LLJIT::PlatformSupport {
auto *DSOHandle =
new GlobalVariable(M, Int64Ty, true, GlobalValue::ExternalLinkage,
ConstantInt::get(Int64Ty, 0), "__dso_handle");
- DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
+ DSOHandle->setVisibility(GlobalValue::HiddenVisibility);
return cantFail(J.getIRCompileLayer().getCompiler()(M));
}
diff --git a/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll b/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
index 67d392e71456..00b54fbf73fd 100644
--- a/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
+++ b/llvm/test/ExecutionEngine/OrcLazy/global-ctors-and-dtors.ll
@@ -1,12 +1,6 @@
-; Test that global constructors and destructors are run:
+; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout %s | FileCheck %s
;
-; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout -extra-module %s \
-; RUN: %S/Inputs/noop-main.ll | FileCheck %s
-;
-; Test that this is true for global constructors and destructors in other
-; JITDylibs.
-; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout \
-; RUN: -jd extra -extra-module %s -jd main %S/Inputs/noop-main.ll | FileCheck %s
+; Test that global constructors and destructors are run.
;
; CHECK: Hello
; CHECK: [ {{.*}}main{{.*}} ]
@@ -28,6 +22,11 @@ entry:
declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
+define i32 @main(i32 %argc, i8** nocapture readnone %argv) {
+entry:
+ ret i32 0
+}
+
define internal void @_GLOBAL__sub_I_hello.cpp() {
entry:
%puts.i.i.i = tail call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
More information about the llvm-commits
mailing list