Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: Classify various compiler-rt and libunwind names accurately and satisfy them #22167

Merged
merged 7 commits into from
Dec 7, 2024
3 changes: 2 additions & 1 deletion lib/std/zig/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ pub fn isLibCxxLibName(target: std.Target, name: []const u8) bool {

return eqlIgnoreCase(ignore_case, name, "c++") or
eqlIgnoreCase(ignore_case, name, "stdc++") or
eqlIgnoreCase(ignore_case, name, "c++abi");
eqlIgnoreCase(ignore_case, name, "c++abi") or
eqlIgnoreCase(ignore_case, name, "supc++");
}

fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
Expand Down
7 changes: 2 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3832,16 +3832,13 @@ fn createModule(
create_module.opts.link_libcpp = true;
continue;
}
switch (target_util.classifyCompilerRtLibName(target, lib_name)) {
switch (target_util.classifyCompilerRtLibName(lib_name)) {
.none => {},
.only_libunwind, .both => {
create_module.opts.link_libunwind = true;
continue;
},
.only_compiler_rt => {
warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
continue;
Comment on lines -3842 to -3843
Copy link
Member

@andrewrk andrewrk Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this gone now?

edit: nvm I see you addressed it in the commit message.

},
.only_compiler_rt => continue,
}

if (target.isMinGW()) {
Expand Down
14 changes: 10 additions & 4 deletions src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,23 @@ pub fn supportsReturnAddress(target: std.Target) bool {

pub const CompilerRtClassification = enum { none, only_compiler_rt, only_libunwind, both };

pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerRtClassification {
if (target.abi.isGnu() and std.mem.eql(u8, name, "gcc_s")) {
pub fn classifyCompilerRtLibName(name: []const u8) CompilerRtClassification {
if (std.mem.eql(u8, name, "gcc_s")) {
// libgcc_s includes exception handling functions, so if linking this library
// is requested, zig needs to instead link libunwind. Otherwise we end up with
// the linker unable to find `_Unwind_RaiseException` and other related symbols.
return .both;
}
if (std.mem.eql(u8, name, "compiler_rt")) {
if (std.mem.eql(u8, name, "compiler_rt") or
std.mem.eql(u8, name, "gcc") or
std.mem.eql(u8, name, "atomic") or
std.mem.eql(u8, name, "ssp"))
{
return .only_compiler_rt;
}
if (std.mem.eql(u8, name, "unwind")) {
if (std.mem.eql(u8, name, "unwind") or
std.mem.eql(u8, name, "gcc_eh"))
{
return .only_libunwind;
}
return .none;
Expand Down