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 @@...@@ -1,4 +1,6 @@
1 * support -fno-emit-bin for godbolt1 * 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
2 * tests passing with -Dskip-non-native4 * tests passing with -Dskip-non-native
3 * `-ftime-report`5 * `-ftime-report`
4 * -fstack-report print stack size diagnostics\n"6 * -fstack-report print stack size diagnostics\n"
...@@ -12,7 +14,6 @@...@@ -12,7 +14,6 @@
12 * restore error messages for stage2_add_link_lib14 * restore error messages for stage2_add_link_lib
13 * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]15 * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]
14 * try building some software with zig cc to make sure it didn't regress16 * 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
17 * implement proper parsing of clang stderr/stdout and exposing compile errors with the Compilation API18 * implement proper parsing of clang stderr/stdout and exposing compile errors with the Compilation API
18 * implement proper parsing of LLD stderr/stdout and exposing compile errors with the Compilation API19 * 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 {...@@ -454,16 +454,16 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
454 break :blk false;454 break :blk false;
455 };455 };
456456
457 const link_libc = options.link_libc or457 const link_libc = options.link_libc or target_util.osRequiresLibC(options.target);
458 (is_exe_or_dyn_lib and target_util.osRequiresLibC(options.target));
459458
460 const must_dynamic_link = dl: {459 const must_dynamic_link = dl: {
461 if (target_util.cannotDynamicLink(options.target))460 if (target_util.cannotDynamicLink(options.target))
462 break :dl false;461 break :dl false;
463 if (target_util.osRequiresLibC(options.target))462 if (is_exe_or_dyn_lib and link_libc and
464 break :dl true;463 (options.target.isGnuLibC() or target_util.osRequiresLibC(options.target)))
465 if (is_exe_or_dyn_lib and link_libc and options.target.isGnuLibC())464 {
466 break :dl true;465 break :dl true;
466 }
467 if (options.system_libs.len != 0)467 if (options.system_libs.len != 0)
468 break :dl true;468 break :dl true;
469469