Commit 819625d274

Andrew Kelley <andrew@ziglang.org>
2020-09-26 10:58:16
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.
1 parent 6af2990
Changed files (2)
src/Compilation.zig
@@ -454,16 +454,16 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
             break :blk false;
         };
 
-        const link_libc = options.link_libc or
-            (is_exe_or_dyn_lib and target_util.osRequiresLibC(options.target));
+        const link_libc = options.link_libc or target_util.osRequiresLibC(options.target);
 
         const must_dynamic_link = dl: {
             if (target_util.cannotDynamicLink(options.target))
                 break :dl false;
-            if (target_util.osRequiresLibC(options.target))
-                break :dl true;
-            if (is_exe_or_dyn_lib and link_libc and options.target.isGnuLibC())
+            if (is_exe_or_dyn_lib and link_libc and
+                (options.target.isGnuLibC() or target_util.osRequiresLibC(options.target)))
+            {
                 break :dl true;
+            }
             if (options.system_libs.len != 0)
                 break :dl true;
 
BRANCH_TODO
@@ -1,4 +1,6 @@
  * support -fno-emit-bin for godbolt
+ * restore the legacy -femit-h feature using the stage1 backend
+ * figure out why test-translate-c is failing
  * tests passing with -Dskip-non-native
  * `-ftime-report`
  *  -fstack-report               print stack size diagnostics\n"
@@ -12,7 +14,6 @@
  * restore error messages for stage2_add_link_lib
  * windows CUSTOMBUILD : error : unable to build compiler_rt: FileNotFound [D:\a\1\s\build\zig_install_lib_files.vcxproj]
  * try building some software with zig cc to make sure it didn't regress
- * restore the legacy -femit-h feature using the stage1 backend
 
  * implement proper parsing of clang stderr/stdout and exposing compile errors with the Compilation API
  * implement proper parsing of LLD stderr/stdout and exposing compile errors with the Compilation API