mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-30 09:01:19 +00:00
This patch add support for executing global constructors and destructors in the ExecutionEngine.
This commit is contained in:
parent
4aa04245e5
commit
01dbc5da33
@ -219,6 +219,11 @@ ExecutionEngine::ExecutionEngine(bool enableObjectDump,
|
||||
}
|
||||
|
||||
ExecutionEngine::~ExecutionEngine() {
|
||||
// Execute the global destructors from the module being processed.
|
||||
// TODO: Allow JIT deinitialize for AArch64. Currently there's a bug causing a
|
||||
// crash for AArch64 see related issue #71963.
|
||||
if (jit && !jit->getTargetTriple().isAArch64())
|
||||
llvm::consumeError(jit->deinitialize(jit->getMainJITDylib()));
|
||||
// Run all dynamic library destroy callbacks to prepare for the shutdown.
|
||||
for (LibraryDestroyFn destroy : destroyFns)
|
||||
destroy();
|
||||
@ -396,6 +401,12 @@ ExecutionEngine::create(Operation *m, const ExecutionEngineOptions &options,
|
||||
};
|
||||
engine->registerSymbols(runtimeSymbolMap);
|
||||
|
||||
// Execute the global constructors from the module being processed.
|
||||
// TODO: Allow JIT initialize for AArch64. Currently there's a bug causing a
|
||||
// crash for AArch64 see related issue #71963.
|
||||
if (!engine->jit->getTargetTriple().isAArch64())
|
||||
cantFail(engine->jit->initialize(engine->jit->getMainJITDylib()));
|
||||
|
||||
return std::move(engine);
|
||||
}
|
||||
|
||||
|
33
mlir/test/mlir-cpu-runner/global-constructors.mlir
Normal file
33
mlir/test/mlir-cpu-runner/global-constructors.mlir
Normal file
@ -0,0 +1,33 @@
|
||||
// UNSUPPORTED: target=aarch64{{.*}}
|
||||
// RUN: mlir-cpu-runner %s -e entry -entry-point-result=void \
|
||||
// RUN: -shared-libs=%mlir_c_runner_utils | \
|
||||
// RUN: FileCheck %s
|
||||
|
||||
// Test that the `ctor` executes before `entry` and that `dtor` executes last.
|
||||
module {
|
||||
llvm.func @printNewline()
|
||||
llvm.func @printI64(i64)
|
||||
llvm.mlir.global_ctors {ctors = [@ctor], priorities = [0 : i32]}
|
||||
llvm.mlir.global_dtors {dtors = [@dtor], priorities = [0 : i32]}
|
||||
llvm.func @ctor() {
|
||||
%0 = llvm.mlir.constant(1 : i64) : i64
|
||||
llvm.call @printI64(%0) : (i64) -> ()
|
||||
llvm.call @printNewline() : () -> ()
|
||||
// CHECK: 1
|
||||
llvm.return
|
||||
}
|
||||
llvm.func @entry() {
|
||||
%0 = llvm.mlir.constant(2 : i64) : i64
|
||||
llvm.call @printI64(%0) : (i64) -> ()
|
||||
llvm.call @printNewline() : () -> ()
|
||||
// CHECK: 2
|
||||
llvm.return
|
||||
}
|
||||
llvm.func @dtor() {
|
||||
%0 = llvm.mlir.constant(3 : i64) : i64
|
||||
llvm.call @printI64(%0) : (i64) -> ()
|
||||
llvm.call @printNewline() : () -> ()
|
||||
// CHECK: 3
|
||||
llvm.return
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user