From 5274aa53b3eefc661e48fb66befd3e75f7bc4177 Mon Sep 17 00:00:00 2001 From: Dave Voutila Date: Thu, 27 Mar 2025 10:37:36 -0400 Subject: [PATCH] Fix linker invocation on OpenBSD. Firstly, we need to explicitly request pthreads and also need to mind the fact ports (like SDL2) install in /usr/local/lib. Secondly, since OpenBSD 7.4 the system enforces indirect branch targets on hardware platforms that support it. Until the LLVM integration in Odin can be changed to emit proper branch targets (e.g. endbr64 on amd64), we need to request the linker make the resulting program opt-out of enforcement. --- src/linker.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/linker.cpp b/src/linker.cpp index cf2ef638d..56e8d3034 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -701,6 +701,13 @@ gb_internal i32 linker_stage(LinkerData *gen) { // This points the linker to where the entry point is link_settings = gb_string_appendc(link_settings, "-e _main "); } + } else if (build_context.metrics.os == TargetOs_openbsd) { + // OpenBSD ports install shared libraries in /usr/local/lib. Also, we must explicitly link libpthread. + platform_lib_str = gb_string_appendc(platform_lib_str, "-lpthread -Wl,-L/usr/local/lib "); + // Until the LLVM back-end can be adapted to emit endbr64 instructions on amd64, we + // need to pass -z nobtcfi in order to allow the resulting program to run under + // OpenBSD 7.4 and newer. Once support is added at compile time, this can be dropped. + platform_lib_str = gb_string_appendc(platform_lib_str, "-Wl,-z,nobtcfi "); } if (!build_context.no_rpath) {