aboutsummaryrefslogtreecommitdiff
path: root/src/target.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-02-23 13:25:10 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-02-23 13:25:10 -0700
commit88d1258e08e668e620d5f8f4681315e555acbcd2 (patch)
tree930e8dabe93e60af9fc4f0e54c17e07db2672aa1 /src/target.zig
parentacec06cfaf9a82ec8037a23993ff36fa72eb6e82 (diff)
downloadzig-88d1258e08e668e620d5f8f4681315e555acbcd2.tar.gz
zig-88d1258e08e668e620d5f8f4681315e555acbcd2.zip
stage2: make -lgcc_s additionally link libunwind
Previously, Zig ignored -lgcc_s with a warning that this dependency is redundant because it is satisfied by compiler-rt. However, sfackler pointed out that it also provides exception handling functions. So if Zig sees -lgcc_s on the linker line, it needs to fulfill this dependency with libunwind. I also made link_libc inferred to be on if libunwind is linked since libunwind depends on libc.
Diffstat (limited to 'src/target.zig')
-rw-r--r--src/target.zig16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/target.zig b/src/target.zig
index 63bd1db0b5..aec37b6394 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -427,14 +427,22 @@ 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 {
+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")) {
- return true;
+ // 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")) {
- return true;
+ return .only_compiler_rt;
}
- return false;
+ if (std.mem.eql(u8, name, "unwind")) {
+ return .only_libunwind;
+ }
+ return .none;
}
pub fn hasDebugInfo(target: std.Target) bool {