From 03ae1208a8ae29f66a99f72f68cef655167ef486 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 12 Oct 2024 21:49:15 +0200 Subject: [PATCH] Safer function registration. --- src/compiler/llvm_codegen.c | 2 +- src/compiler/llvm_codegen_function.c | 3 +-- src/compiler/llvm_codegen_type.c | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index b1bbe3258..cf74f6f92 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -919,7 +919,7 @@ void llvm_set_comdat(GenContext *c, LLVMValueRef global) void llvm_set_selector_linkage(GenContext *c, LLVMValueRef selector) { LLVMSetVisibility(selector, LLVMDefaultVisibility); - LLVMSetLinkage(selector, LLVMLinkOnceODRLinkage); + LLVMSetLinkage(selector, LLVMWeakAnyLinkage); llvm_set_comdat(c, selector); } diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index e2d8c0c7c..d60dfc968 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -584,8 +584,7 @@ void llvm_emit_dynamic_functions(GenContext *c, Decl **funcs) } LLVMValueRef initializer = LLVMAddFunction(c->module, ".c3_dynamic_register", c->xtor_func_type); - LLVMSetLinkage(initializer, LLVMPrivateLinkage); - LLVMSetVisibility(initializer, LLVMDefaultVisibility); + LLVMSetLinkage(initializer, LLVMInternalLinkage); LLVMSetAlignment(initializer, 8); LLVMValueRef vals_fn[3] = { llvm_const_int(c, type_int, 1), initializer, llvm_get_zero(c, type_voidptr) }; vec_add(c->constructors, LLVMConstNamedStruct(c->xtor_entry_type, vals_fn, 3)); diff --git a/src/compiler/llvm_codegen_type.c b/src/compiler/llvm_codegen_type.c index fa5b17d5d..21da814dd 100644 --- a/src/compiler/llvm_codegen_type.c +++ b/src/compiler/llvm_codegen_type.c @@ -467,7 +467,7 @@ static inline LLVMValueRef llvm_generate_introspection_global(GenContext *c, LLV } else { - llvm_set_linkonce(c, global_name); + llvm_set_selector_linkage(c, global_name); } if (original_global) { @@ -558,7 +558,7 @@ static LLVMValueRef llvm_get_introspection_for_enum(GenContext *c, Type *type) scratch_buffer_to_string(), LLVMTypeOf(associated_value_arr), 0); - llvm_set_linkonce(c, global_ref); + llvm_set_selector_linkage(c, global_ref); LLVMSetInitializer(global_ref, associated_value_arr); LLVMSetGlobalConstant(global_ref, true); associated_value->backend_ref = global_ref; @@ -605,7 +605,7 @@ static LLVMValueRef llvm_get_introspection_for_fault(GenContext *c, Type *type) llvm_const_int(c, type_usz, val->enum_constant.ordinal + 1 )}; LLVMSetInitializer(global_name, llvm_get_struct_named(c->fault_type, vals, 3)); - llvm_set_linkonce(c, global_name); + llvm_set_selector_linkage(c, global_name); val->backend_ref = LLVMBuildPtrToInt(c->builder, global_name, c->typeid_type, ""); } LLVMValueRef* values = elements ? MALLOC(sizeof(LLVMValueRef) * elements) : NULL;