aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_proc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/llvm_backend_proc.cpp')
-rw-r--r--src/llvm_backend_proc.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp
index e52e91f75..7897e17cd 100644
--- a/src/llvm_backend_proc.cpp
+++ b/src/llvm_backend_proc.cpp
@@ -289,6 +289,19 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
lb_set_linkage_from_entity_flags(p->module, p->value, entity->flags);
+ // With LTO on Windows, required procedures with external linkage need to be added to
+ // llvm.used to survive linker-level dead code elimination. This is necessary because
+ // LLVM may generate implicit calls to runtime builtins (e.g., __extendhfsf2 for f16
+ // conversions) during instruction lowering, after the IR is finalized.
+ if (build_context.lto_kind != LTO_None && build_context.metrics.os == TargetOs_windows) {
+ if (entity->flags & EntityFlag_Require) {
+ LLVMLinkage linkage = LLVMGetLinkage(p->value);
+ if (linkage != LLVMInternalLinkage) {
+ lb_append_to_used(m, p->value);
+ }
+ }
+ }
+
if (m->debug_builder) { // Debug Information
Type *bt = base_type(p->type);