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...@@ -46,6 +46,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
46 );46 );
47 return error.SubCompilationFailed;47 return error.SubCompilationFailed;
48 };48 };
49 const target = comp.root_mod.resolved_target.result;
49 const root_mod = Module.create(arena, .{50 const root_mod = Module.create(arena, .{
50 .global_cache_directory = comp.global_cache_directory,51 .global_cache_directory = comp.global_cache_directory,
51 .paths = .{52 .paths = .{
...@@ -63,8 +64,9 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -63,8 +64,9 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
63 .valgrind = false,64 .valgrind = false,
64 .sanitize_c = false,65 .sanitize_c = false,
65 .sanitize_thread = false,66 .sanitize_thread = false,
66 .unwind_tables = false,67 // necessary so that libunwind can unwind through its own stack frames
67 .pic = comp.root_mod.pic,68 .unwind_tables = true,
69 .pic = if (target_util.supports_fpic(target)) true else null,
68 .optimize_mode = comp.compilerRtOptMode(),70 .optimize_mode = comp.compilerRtOptMode(),
69 },71 },
70 .global = config,72 .global = config,
...@@ -83,7 +85,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -83,7 +85,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
8385
84 const root_name = "unwind";86 const root_name = "unwind";
85 const link_mode = .static;87 const link_mode = .static;
86 const target = comp.root_mod.resolved_target.result;
87 const basename = try std.zig.binNameAlloc(arena, .{88 const basename = try std.zig.binNameAlloc(arena, .{
88 .root_name = root_name,89 .root_name = root_name,
89 .target = target,90 .target = target,
...@@ -114,16 +115,11 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -114,16 +115,11 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
114 try cflags.append("-fno-exceptions");115 try cflags.append("-fno-exceptions");
115 try cflags.append("-I");116 try cflags.append("-I");
116 try cflags.append(try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libunwind", "include" }));117 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 }
120 try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");118 try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");
121 try cflags.append("-Wa,--noexecstack");119 try cflags.append("-Wa,--noexecstack");
122 try cflags.append("-fvisibility=hidden");120 try cflags.append("-fvisibility=hidden");
123 try cflags.append("-fvisibility-inlines-hidden");121 try cflags.append("-fvisibility-inlines-hidden");
124 try cflags.append("-fvisibility-global-new-delete=force-hidden");122 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
128 // This is intentionally always defined because the macro definition means, should it only124 // This is intentionally always defined because the macro definition means, should it only
129 // build for the target specified by compiler defines. Since we pass -target the compiler125 // build for the target specified by compiler defines. Since we pass -target the compiler