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 {
263263
264264 return eqlIgnoreCase(ignore_case, name, "c++") or
265265 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++");
267268}
268269
269270fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool {
src/main.zig+2-5
......@@ -3832,16 +3832,13 @@ fn createModule(
38323832 create_module.opts.link_libcpp = true;
38333833 continue;
38343834 }
3835 switch (target_util.classifyCompilerRtLibName(target, lib_name)) {
3835 switch (target_util.classifyCompilerRtLibName(lib_name)) {
38363836 .none => {},
38373837 .only_libunwind, .both => {
38383838 create_module.opts.link_libunwind = true;
38393839 continue;
38403840 },
3841 .only_compiler_rt => {
3842 warn("ignoring superfluous library '{s}': this dependency is fulfilled instead by compiler-rt which zig unconditionally provides", .{lib_name});
3843 continue;
3844 },
3841 .only_compiler_rt => continue,
38453842 }
38463843
38473844 if (target.isMinGW()) {
src/target.zig+10-4
......@@ -260,17 +260,23 @@ pub fn supportsReturnAddress(target: std.Target) bool {
260260
261261pub const CompilerRtClassification = enum { none, only_compiler_rt, only_libunwind, both };
262262
263pub fn classifyCompilerRtLibName(target: std.Target, name: []const u8) CompilerRtClassification {
264 if (target.abi.isGnu() and std.mem.eql(u8, name, "gcc_s")) {
263pub fn classifyCompilerRtLibName(name: []const u8) CompilerRtClassification {
264 if (std.mem.eql(u8, name, "gcc_s")) {
265265 // libgcc_s includes exception handling functions, so if linking this library
266266 // is requested, zig needs to instead link libunwind. Otherwise we end up with
267267 // the linker unable to find `_Unwind_RaiseException` and other related symbols.
268268 return .both;
269269 }
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 {
271275 return .only_compiler_rt;
272276 }
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 {
274280 return .only_libunwind;
275281 }
276282 return .none;