authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-26 01:58:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-26 01:58:16-07:00
log819625d2740838ad10440f4af04200a38b5c65e2
treeb2fbe9a4c38d7debe0af61d6c6709a8998b8eabe
parent6af2990549709ec5e2bc1efeb5090a944f1a8bdf

fix logic for choosing when dynamic linking is required

When building object files or static libraries, link_mode can still be static even if the OS needs libc for syscalls.

2 files changed, 7 insertions(+), 6 deletions(-)

BRANCH_TODO+2-1
......@@ -1,4 +1,6 @@
11 * support -fno-emit-bin for godbolt
2 * restore the legacy -femit-h feature using the stage1 backend
3 * figure out why test-translate-c is failing
24 * tests passing with -Dskip-non-native
35 * `-ftime-report`
46 * -fstack-report print stack size diagnostics\n"
......@@ -12,7 +14,6 @@
1214 * restore error messages for stage2_add_link_lib
1315 * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]
1416 * try building some software with zig cc to make sure it didn't regress
15 * restore the legacy -femit-h feature using the stage1 backend
1617
1718 * implement proper parsing of clang stderr/stdout and exposing compile errors with the Compilation API
1819 * implement proper parsing of LLD stderr/stdout and exposing compile errors with the Compilation API
src/Compilation.zig+5-5
......@@ -454,16 +454,16 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
454454 break :blk false;
455455 };
456456
457 const link_libc = options.link_libc or
458 (is_exe_or_dyn_lib and target_util.osRequiresLibC(options.target));
457 const link_libc = options.link_libc or target_util.osRequiresLibC(options.target);
459458
460459 const must_dynamic_link = dl: {
461460 if (target_util.cannotDynamicLink(options.target))
462461 break :dl false;
463 if (target_util.osRequiresLibC(options.target))
464 break :dl true;
465 if (is_exe_or_dyn_lib and link_libc and options.target.isGnuLibC())
462 if (is_exe_or_dyn_lib and link_libc and
463 (options.target.isGnuLibC() or target_util.osRequiresLibC(options.target)))
464 {
466465 break :dl true;
466 }
467467 if (options.system_libs.len != 0)
468468 break :dl true;
469469