aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-05-22 15:27:53 +0100
committerGitHub <noreply@github.com>2025-05-22 15:27:53 +0100
commit34e998c1fcc9cdcc2a6cc0476cc0d774a7c7ed26 (patch)
tree39d1e9b6aac753ab078736dae57e8c8ba70c3ff8 /src
parent9421b77eb5bc722980d8de0f3720a0729d137aff (diff)
parent713360a792ea54211624f7ac18e68c4c4a16aeb1 (diff)
Merge pull request #5173 from Feoramund/fix-linux-shared-lib-runtime-call
Keep shared libraries from calling main program's startup/cleanup procs on Linux
Diffstat (limited to 'src')
-rw-r--r--src/llvm_backend.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 361a0c46b..f0bbe5473 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -1907,6 +1907,10 @@ gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProc
lb_add_attribute_to_proc(p->module, p->value, "optnone");
lb_add_attribute_to_proc(p->module, p->value, "noinline");
+ // Make sure shared libraries call their own runtime startup on Linux.
+ LLVMSetVisibility(p->value, LLVMHiddenVisibility);
+ LLVMSetLinkage(p->value, LLVMWeakAnyLinkage);
+
lb_begin_procedure_body(p);
lb_setup_type_info_data(main_module);
@@ -2016,6 +2020,10 @@ gb_internal lbProcedure *lb_create_cleanup_runtime(lbModule *main_module) { // C
lb_add_attribute_to_proc(p->module, p->value, "optnone");
lb_add_attribute_to_proc(p->module, p->value, "noinline");
+ // Make sure shared libraries call their own runtime cleanup on Linux.
+ LLVMSetVisibility(p->value, LLVMHiddenVisibility);
+ LLVMSetLinkage(p->value, LLVMWeakAnyLinkage);
+
lb_begin_procedure_body(p);
CheckerInfo *info = main_module->gen->info;