Skip to content

Commit

Permalink
CLI: ignore -lgcc_s when it is redundant with compiler-rt
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewrk committed Feb 9, 2022
1 parent db56d74 commit 2836cd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,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});
}
Expand Down
10 changes: 10 additions & 0 deletions src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2836cd5

Please sign in to comment.