Skip to content

Commit 34e998c

Browse files
authored
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
2 parents 9421b77 + 713360a commit 34e998c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/llvm_backend.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,10 @@ gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProc
19071907
lb_add_attribute_to_proc(p->module, p->value, "optnone");
19081908
lb_add_attribute_to_proc(p->module, p->value, "noinline");
19091909

1910+
// Make sure shared libraries call their own runtime startup on Linux.
1911+
LLVMSetVisibility(p->value, LLVMHiddenVisibility);
1912+
LLVMSetLinkage(p->value, LLVMWeakAnyLinkage);
1913+
19101914
lb_begin_procedure_body(p);
19111915

19121916
lb_setup_type_info_data(main_module);
@@ -2016,6 +2020,10 @@ gb_internal lbProcedure *lb_create_cleanup_runtime(lbModule *main_module) { // C
20162020
lb_add_attribute_to_proc(p->module, p->value, "optnone");
20172021
lb_add_attribute_to_proc(p->module, p->value, "noinline");
20182022

2023+
// Make sure shared libraries call their own runtime cleanup on Linux.
2024+
LLVMSetVisibility(p->value, LLVMHiddenVisibility);
2025+
LLVMSetLinkage(p->value, LLVMWeakAnyLinkage);
2026+
20192027
lb_begin_procedure_body(p);
20202028

20212029
CheckerInfo *info = main_module->gen->info;

0 commit comments

Comments
 (0)