From 5685a10ded2dbb64070c8f43911a05584901c5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 5 Nov 2024 15:26:05 +0100 Subject: [PATCH] libunwind: Pass -fPIC -funwind-tables via module options instead of CFLAGS. --- src/libunwind.zig | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libunwind.zig b/src/libunwind.zig index d7b22e2067..1e101da229 100644 --- a/src/libunwind.zig +++ b/src/libunwind.zig @@ -46,6 +46,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr ); return error.SubCompilationFailed; }; + const target = comp.root_mod.resolved_target.result; const root_mod = Module.create(arena, .{ .global_cache_directory = comp.global_cache_directory, .paths = .{ @@ -63,8 +64,9 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .valgrind = false, .sanitize_c = false, .sanitize_thread = false, - .unwind_tables = false, - .pic = comp.root_mod.pic, + // necessary so that libunwind can unwind through its own stack frames + .unwind_tables = true, + .pic = if (target_util.supports_fpic(target)) true else null, .optimize_mode = comp.compilerRtOptMode(), }, .global = config, @@ -83,7 +85,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr const root_name = "unwind"; const link_mode = .static; - const target = comp.root_mod.resolved_target.result; const basename = try std.zig.binNameAlloc(arena, .{ .root_name = root_name, .target = target, @@ -114,16 +115,11 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr try cflags.append("-fno-exceptions"); try cflags.append("-I"); try cflags.append(try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libunwind", "include" })); - if (target_util.supports_fpic(target)) { - try cflags.append("-fPIC"); - } try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS"); try cflags.append("-Wa,--noexecstack"); try cflags.append("-fvisibility=hidden"); try cflags.append("-fvisibility-inlines-hidden"); try cflags.append("-fvisibility-global-new-delete=force-hidden"); - // necessary so that libunwind can unwind through its own stack frames - try cflags.append("-funwind-tables"); // This is intentionally always defined because the macro definition means, should it only // build for the target specified by compiler defines. Since we pass -target the compiler