authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-05 15:26:05+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-05 22:41:09+01:00
log5685a10ded2dbb64070c8f43911a05584901c5eb
treeae5a2586b52f39f218b0b4410f7036632c9eff9f
parenteb14fd8806885b43dd98492f0a6720038d8176c8
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libunwind: Pass -fPIC -funwind-tables via module options instead of CFLAGS.


1 files changed, 4 insertions(+), 8 deletions(-)

src/libunwind.zig+4-8
......@@ -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