diff options
Diffstat (limited to 'src/Compilation/Config.zig')
| -rw-r--r-- | src/Compilation/Config.zig | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index b46837679a..493c63f34f 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -335,6 +335,13 @@ pub fn resolve(options: Options) ResolveError!Config { break :b true; } if (options.link_libc) |x| break :b x; + switch (target.os.tag) { + // These targets don't require libc, but we don't yet have a syscall layer for them, + // so we default to linking libc for now. + .freebsd, + => break :b true, + else => {}, + } if (options.ensure_libc_on_non_freestanding and target.os.tag != .freestanding) break :b true; @@ -353,7 +360,9 @@ pub fn resolve(options: Options) ResolveError!Config { break :b .static; } if (explicitly_exe_or_dyn_lib and link_libc and - (target_util.osRequiresLibC(target) or (target.isGnuLibC() and !options.resolved_target.is_native_abi))) + (target_util.osRequiresLibC(target) or + // For these libcs, Zig can only provide dynamic libc when cross-compiling. + ((target.isGnuLibC() or target.isFreeBSDLibC()) and !options.resolved_target.is_native_abi))) { if (options.link_mode == .static) return error.LibCRequiresDynamicLinking; break :b .dynamic; @@ -368,12 +377,18 @@ pub fn resolve(options: Options) ResolveError!Config { if (options.link_mode) |link_mode| break :b link_mode; - if (explicitly_exe_or_dyn_lib and link_libc and options.resolved_target.is_native_abi and - (target.isGnuLibC() or target.isMuslLibC())) - { - // If targeting the system's native ABI and the system's libc is - // glibc or musl, link dynamically by default. - break :b .dynamic; + if (explicitly_exe_or_dyn_lib and link_libc) { + // When using the native glibc/musl ABI, dynamic linking is usually what people want. + if (options.resolved_target.is_native_abi and (target.isGnuLibC() or target.isMuslLibC())) { + break :b .dynamic; + } + + // When targeting systems where the kernel and libc are developed alongside each other, + // dynamic linking is the better default; static libc may contain code that requires + // the very latest kernel version. + if (target.isFreeBSDLibC()) { + break :b .dynamic; + } } // Static is generally a better default. Fight me. |
