aboutsummaryrefslogtreecommitdiff
path: root/src/linker.cpp
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-22 20:47:10 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-22 21:39:35 -0400
commit6c5b96948e827a0b22435c1bb367414c8a187666 (patch)
tree9fed9910602913dede14be482a9c340fd9fe2b4e /src/linker.cpp
parent82c9681e2805e58309a057c00d176a34ae74721e (diff)
Enable all sanitizers on FreeBSD
Diffstat (limited to 'src/linker.cpp')
-rw-r--r--src/linker.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/linker.cpp b/src/linker.cpp
index 41d4a13a1..447d66d0a 100644
--- a/src/linker.cpp
+++ b/src/linker.cpp
@@ -802,6 +802,18 @@ try_cross_linking:;
link_settings = gb_string_appendc(link_settings, "-e _main ");
}
} else if (build_context.metrics.os == TargetOs_freebsd) {
+ if (build_context.sanitizer_flags & (SanitizerFlag_Address | SanitizerFlag_Memory)) {
+ // It's imperative that `pthread` is linked before `libc`,
+ // otherwise ASan/MSan will be unable to call `pthread_key_create`
+ // because FreeBSD's `libthr` implementation of `pthread`
+ // needs to replace the relevant stubs first.
+ //
+ // (Presumably TSan implements its own `pthread` interface,
+ // which is why it isn't required.)
+ //
+ // See: https://reviews.llvm.org/D39254
+ platform_lib_str = gb_string_appendc(platform_lib_str, "-lpthread ");
+ }
// FreeBSD pkg installs third-party shared libraries in /usr/local/lib.
platform_lib_str = gb_string_appendc(platform_lib_str, "-Wl,-L/usr/local/lib ");
} else if (build_context.metrics.os == TargetOs_openbsd) {