aboutsummaryrefslogtreecommitdiff
path: root/src/linker.cpp
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2025-06-08 16:17:32 -0700
committerColin Davidson <colrdavidson@gmail.com>2025-06-08 16:17:32 -0700
commit04481e0fd289f854e35a84da909184140940bbf7 (patch)
tree97224c25709866edbf16a486fdbd30a4d736701a /src/linker.cpp
parentb1ed22d84f2aae617c90c60701e9f25345cab980 (diff)
parent7813e9fb378753bf110f0ad4b5cc85e7f16336d4 (diff)
Merge branch 'master' into macharena
Diffstat (limited to 'src/linker.cpp')
-rw-r--r--src/linker.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/linker.cpp b/src/linker.cpp
index ec165ef7d..2210c1306 100644
--- a/src/linker.cpp
+++ b/src/linker.cpp
@@ -281,9 +281,9 @@ try_cross_linking:;
link_settings = gb_string_append_fmt(link_settings, " /ENTRY:mainCRTStartup");
}
- if (build_context.pdb_filepath != "") {
- String pdb_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_PDB]);
- link_settings = gb_string_append_fmt(link_settings, " /PDB:\"%.*s\"", LIT(pdb_path));
+ if (build_context.build_paths[BuildPath_Symbols].name != "") {
+ String symbol_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_Symbols]);
+ link_settings = gb_string_append_fmt(link_settings, " /PDB:\"%.*s\"", LIT(symbol_path));
}
if (build_context.build_mode != BuildMode_StaticLibrary) {
@@ -321,7 +321,7 @@ try_cross_linking:;
"",
LIT(build_context.ODIN_ROOT), object_files, LIT(output_filename),
link_settings,
- LIT(build_context.ODIN_WINDOWS_SUBSYSTEM),
+ LIT(windows_subsystem_names[build_context.ODIN_WINDOWS_SUBSYSTEM]),
LIT(build_context.link_flags),
LIT(build_context.extra_linker_flags),
lib_str
@@ -341,7 +341,7 @@ try_cross_linking:;
"",
LIT(build_context.ODIN_ROOT), object_files, LIT(output_filename),
link_settings,
- LIT(build_context.ODIN_WINDOWS_SUBSYSTEM),
+ LIT(windows_subsystem_names[build_context.ODIN_WINDOWS_SUBSYSTEM]),
LIT(build_context.link_flags),
LIT(build_context.extra_linker_flags),
lib_str
@@ -404,7 +404,7 @@ try_cross_linking:;
"",
LIT(vs_exe_path), LIT(linker_name), object_files, LIT(res_path), LIT(output_filename),
link_settings,
- LIT(build_context.ODIN_WINDOWS_SUBSYSTEM),
+ LIT(windows_subsystem_names[build_context.ODIN_WINDOWS_SUBSYSTEM]),
LIT(build_context.link_flags),
LIT(build_context.extra_linker_flags),
lib_str
@@ -769,7 +769,17 @@ try_cross_linking:;
gbString platform_lib_str = gb_string_make(heap_allocator(), "");
defer (gb_string_free(platform_lib_str));
if (build_context.metrics.os == TargetOs_darwin) {
- platform_lib_str = gb_string_appendc(platform_lib_str, "-Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib ");
+ // Get the MacOSX SDK path.
+ gbString darwin_sdk_path = gb_string_make(temporary_allocator(), "");
+ if (!system_exec_command_line_app_output("xcrun --sdk macosx --show-sdk-path", &darwin_sdk_path)) {
+ darwin_sdk_path = gb_string_set(darwin_sdk_path, "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk");
+ } else {
+ // Trim the trailing newline.
+ darwin_sdk_path = gb_string_trim_space(darwin_sdk_path);
+ }
+ platform_lib_str = gb_string_append_fmt(platform_lib_str, "--sysroot %s ", darwin_sdk_path);
+
+ platform_lib_str = gb_string_appendc(platform_lib_str, "-L/usr/local/lib ");
// Homebrew's default library path, checking if it exists to avoid linking warnings.
if (gb_file_exists("/opt/homebrew/lib")) {
@@ -791,6 +801,21 @@ try_cross_linking:;
// 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_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) {
// 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 ");