Skip to content

Commit 5685a10

Browse files
committed
libunwind: Pass -fPIC -funwind-tables via module options instead of CFLAGS.
1 parent eb14fd8 commit 5685a10

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/libunwind.zig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
4646
);
4747
return error.SubCompilationFailed;
4848
};
49+
const target = comp.root_mod.resolved_target.result;
4950
const root_mod = Module.create(arena, .{
5051
.global_cache_directory = comp.global_cache_directory,
5152
.paths = .{
@@ -63,8 +64,9 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
6364
.valgrind = false,
6465
.sanitize_c = false,
6566
.sanitize_thread = false,
66-
.unwind_tables = false,
67-
.pic = comp.root_mod.pic,
67+
// necessary so that libunwind can unwind through its own stack frames
68+
.unwind_tables = true,
69+
.pic = if (target_util.supports_fpic(target)) true else null,
6870
.optimize_mode = comp.compilerRtOptMode(),
6971
},
7072
.global = config,
@@ -83,7 +85,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
8385

8486
const root_name = "unwind";
8587
const link_mode = .static;
86-
const target = comp.root_mod.resolved_target.result;
8788
const basename = try std.zig.binNameAlloc(arena, .{
8889
.root_name = root_name,
8990
.target = target,
@@ -114,16 +115,11 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
114115
try cflags.append("-fno-exceptions");
115116
try cflags.append("-I");
116117
try cflags.append(try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libunwind", "include" }));
117-
if (target_util.supports_fpic(target)) {
118-
try cflags.append("-fPIC");
119-
}
120118
try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");
121119
try cflags.append("-Wa,--noexecstack");
122120
try cflags.append("-fvisibility=hidden");
123121
try cflags.append("-fvisibility-inlines-hidden");
124122
try cflags.append("-fvisibility-global-new-delete=force-hidden");
125-
// necessary so that libunwind can unwind through its own stack frames
126-
try cflags.append("-funwind-tables");
127123

128124
// This is intentionally always defined because the macro definition means, should it only
129125
// build for the target specified by compiler defines. Since we pass -target the compiler

0 commit comments

Comments
 (0)