Commit d2398cf009

Andrew Kelley <andrew@ziglang.org>
2022-02-09 19:36:30
CLI: ignore -lgcc_s when it is redundant with compiler-rt
For some projects, they can't help themselves, -lgcc_s ends up on the compiler command line even though it does not belong there. In Zig we know what -lgcc_s does. It's an alternative to compiler-rt. With this commit we emit a warning telling that it is unnecessary to put such thing on the command line, and happily ignore it, since we will fulfill the dependency with compiler-rt.
1 parent 0d006af
Changed files (2)
src/main.zig
@@ -1998,6 +1998,11 @@ fn buildOutputType(
                 _ = system_libs.orderedRemove(lib_name);
                 continue;
             }
+            if (target_util.is_compiler_rt_lib_name(target_info.target, lib_name)) {
+                std.log.warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
+                _ = system_libs.orderedRemove(lib_name);
+                continue;
+            }
             if (std.fs.path.isAbsolute(lib_name)) {
                 fatal("cannot use absolute path as a system library: {s}", .{lib_name});
             }
src/target.zig
@@ -427,6 +427,16 @@ pub fn is_libcpp_lib_name(target: std.Target, name: []const u8) bool {
         eqlIgnoreCase(ignore_case, name, "c++abi");
 }
 
+pub fn is_compiler_rt_lib_name(target: std.Target, name: []const u8) bool {
+    if (target.abi.isGnu() and std.mem.eql(u8, name, "gcc_s")) {
+        return true;
+    }
+    if (std.mem.eql(u8, name, "compiler_rt")) {
+        return true;
+    }
+    return false;
+}
+
 pub fn hasDebugInfo(target: std.Target) bool {
     return !target.cpu.arch.isWasm();
 }