authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-09 11:36:30-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-09 11:38:33-07:00
log2836cd5fbdcbb22b1e03c01005e0e09777c5475f
treee0410656d83b3ed802211e201902e4f0d08f917a
parentdb56d74a3bc9c6240d24838753a7042ba91501a1

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.

2 files changed, 15 insertions(+), 0 deletions(-)

src/main.zig+5
...@@ -2010,6 +2010,11 @@ fn buildOutputType(...@@ -2010,6 +2010,11 @@ fn buildOutputType(
2010 _ = system_libs.orderedRemove(lib_name);2010 _ = system_libs.orderedRemove(lib_name);
2011 continue;2011 continue;
2012 }2012 }
2013 if (target_util.is_compiler_rt_lib_name(target_info.target, lib_name)) {
2014 std.log.warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
2015 _ = system_libs.orderedRemove(lib_name);
2016 continue;
2017 }
2013 if (std.fs.path.isAbsolute(lib_name)) {2018 if (std.fs.path.isAbsolute(lib_name)) {
2014 fatal("cannot use absolute path as a system library: {s}", .{lib_name});2019 fatal("cannot use absolute path as a system library: {s}", .{lib_name});
2015 }2020 }
src/target.zig+10
...@@ -427,6 +427,16 @@ pub fn is_libcpp_lib_name(target: std.Target, name: []const u8) bool {...@@ -427,6 +427,16 @@ pub fn is_libcpp_lib_name(target: std.Target, name: []const u8) bool {
427 eqlIgnoreCase(ignore_case, name, "c++abi");427 eqlIgnoreCase(ignore_case, name, "c++abi");
428}428}
429429
430pub fn is_compiler_rt_lib_name(target: std.Target, name: []const u8) bool {
431 if (target.abi.isGnu() and std.mem.eql(u8, name, "gcc_s")) {
432 return true;
433 }
434 if (std.mem.eql(u8, name, "compiler_rt")) {
435 return true;
436 }
437 return false;
438}
439
430pub fn hasDebugInfo(target: std.Target) bool {440pub fn hasDebugInfo(target: std.Target) bool {
431 return !target.cpu.arch.isWasm();441 return !target.cpu.arch.isWasm();
432}442}