diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-03-27 15:05:34 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-27 15:05:34 +0000 |
| commit | 71db9ac1ba7ca3aef94bfd026b0e4bc444a20124 (patch) | |
| tree | 1b431a1cfbef5baab122e7bafbf98fdb0085f447 | |
| parent | 8b30adf60bf7a66318c83ba6c286f7710a79094d (diff) | |
| parent | 5274aa53b3eefc661e48fb66befd3e75f7bc4177 (diff) | |
Merge pull request #4976 from voutilad/openbsd-linker
Fix linking of programs on OpenBSD
| -rw-r--r-- | base/runtime/os_specific_bsd.odin | 2 | ||||
| -rw-r--r-- | core/os/os_openbsd.odin | 2 | ||||
| -rw-r--r-- | src/linker.cpp | 7 |
3 files changed, 9 insertions, 2 deletions
diff --git a/base/runtime/os_specific_bsd.odin b/base/runtime/os_specific_bsd.odin index 5d198484b..466001ada 100644 --- a/base/runtime/os_specific_bsd.odin +++ b/base/runtime/os_specific_bsd.odin @@ -9,7 +9,7 @@ foreign libc { @(link_name="write") _unix_write :: proc(fd: i32, buf: rawptr, size: int) -> int --- - when ODIN_OS == .NetBSD { + when ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD { @(link_name="__errno") __error :: proc() -> ^i32 --- } else { __error :: proc() -> ^i32 --- diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin index 3c377968c..6548a57dc 100644 --- a/core/os/os_openbsd.odin +++ b/core/os/os_openbsd.odin @@ -343,7 +343,7 @@ AT_REMOVEDIR :: 0x08 @(default_calling_convention="c") foreign libc { - @(link_name="__error") __error :: proc() -> ^c.int --- + @(link_name="__errno") __error :: proc() -> ^c.int --- @(link_name="fork") _unix_fork :: proc() -> pid_t --- @(link_name="getthrid") _unix_getthrid :: proc() -> int --- 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) { |