authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-06 19:04:39-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-12-06 19:04:39-05:00
logeb9c9a38f268f48ac51223e04fab7af5d8a5a1bd
tree946f2484d8f1ded10f6df4a613a79a0c6da31d6b
parentca069244b200ec1b7f826dd7e7a31a098a4c71a2
parent8f27fc6c072590f4e9047542ee56b85fd133633d
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22167 from alexrp/compiler-rt-names

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

3 files changed, 14 insertions(+), 10 deletions(-)

lib/std/zig/target.zig+2-1
...@@ -263,7 +263,8 @@ pub fn isLibCxxLibName(target: std.Target, name: []const u8) bool {...@@ -263,7 +263,8 @@ pub fn isLibCxxLibName(target: std.Target, name: []const u8) bool {
263263
264 return eqlIgnoreCase(ignore_case, name, "c++") or264 return eqlIgnoreCase(ignore_case, name, "c++") or
265 eqlIgnoreCase(ignore_case, name, "stdc++") or265 eqlIgnoreCase(ignore_case, name, "stdc++") or
266 eqlIgnoreCase(ignore_case, name, "c++abi");266 eqlIgnoreCase(ignore_case, name, "c++abi") or
267 eqlIgnoreCase(ignore_case, name, "supc++");
267}268}
268269
269fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {270fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
src/main.zig+2-5
...@@ -3832,16 +3832,13 @@ fn createModule(...@@ -3832,16 +3832,13 @@ fn createModule(
3832 create_module.opts.link_libcpp = true;3832 create_module.opts.link_libcpp = true;
3833 continue;3833 continue;
3834 }3834 }
3835 switch (target_util.classifyCompilerRtLibName(target, lib_name)) {3835 switch (target_util.classifyCompilerRtLibName(lib_name)) {
3836 .none => {},3836 .none => {},
3837 .only_libunwind, .both => {3837 .only_libunwind, .both => {
3838 create_module.opts.link_libunwind = true;3838 create_module.opts.link_libunwind = true;
3839 continue;3839 continue;
3840 },3840 },
3841 .only_compiler_rt => {3841 .only_compiler_rt => continue,
3842 warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
3843 continue;
3844 },
3845 }3842 }
38463843
3847 if (target.isMinGW()) {3844 if (target.isMinGW()) {
src/target.zig+10-4
...@@ -260,17 +260,23 @@ pub fn supportsReturnAddress(target: std.Target) bool {...@@ -260,17 +260,23 @@ pub fn supportsReturnAddress(target: std.Target) bool {
260260
261pub const CompilerRtClassification = enum { none, only_compiler_rt, only_libunwind, both };261pub const CompilerRtClassification = enum { none, only_compiler_rt, only_libunwind, both };
262262
263pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerRtClassification {263pub fn classifyCompilerRtLibName(name: []const u8) CompilerRtClassification {
264 if (target.abi.isGnu() and std.mem.eql(u8, name, "gcc_s")) {264 if (std.mem.eql(u8, name, "gcc_s")) {
265 // libgcc_s includes exception handling functions, so if linking this library265 // libgcc_s includes exception handling functions, so if linking this library
266 // is requested, zig needs to instead link libunwind. Otherwise we end up with266 // is requested, zig needs to instead link libunwind. Otherwise we end up with
267 // the linker unable to find `_Unwind_RaiseException` and other related symbols.267 // the linker unable to find `_Unwind_RaiseException` and other related symbols.
268 return .both;268 return .both;
269 }269 }
270 if (std.mem.eql(u8, name, "compiler_rt")) {270 if (std.mem.eql(u8, name, "compiler_rt") or
271 std.mem.eql(u8, name, "gcc") or
272 std.mem.eql(u8, name, "atomic") or
273 std.mem.eql(u8, name, "ssp"))
274 {
271 return .only_compiler_rt;275 return .only_compiler_rt;
272 }276 }
273 if (std.mem.eql(u8, name, "unwind")) {277 if (std.mem.eql(u8, name, "unwind") or
278 std.mem.eql(u8, name, "gcc_eh"))
279 {
274 return .only_libunwind;280 return .only_libunwind;
275 }281 }
276 return .none;282 return .none;