authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-16 09:38:30+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-07 09:50:37+02:00
log701cae9d6b54f180fb2e2d62e55a0d890af8b182
tree69239436dc2a8cdef4cf40b2bafe019917142d37
parent199d0b90294af4fbec6890b2675c3272da0be1cc
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: don't require PIC when linking libc

This allows linking statically against native libc with -fno-PIC.

2 files changed, 3 insertions(+), 5 deletions(-)

src/Module.zig+1-1
...@@ -174,7 +174,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Module {...@@ -174,7 +174,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Module {
174 };174 };
175175
176 const pic = b: {176 const pic = b: {
177 if (target_util.requiresPic(target, options.global.link_libc)) {177 if (target_util.requiresPic(target)) {
178 if (options.inherited.pic == false)178 if (options.inherited.pic == false)
179 return error.TargetRequiresPic;179 return error.TargetRequiresPic;
180 break :b true;180 break :b true;
src/target.zig+2-4
...@@ -72,10 +72,8 @@ pub fn requiresPie(target: *const std.Target, link_mode: std.lang.LinkMode) bool...@@ -72,10 +72,8 @@ pub fn requiresPie(target: *const std.Target, link_mode: std.lang.LinkMode) bool
72}72}
7373
74/// This function returns whether non-pic code is completely invalid on the given target.74/// This function returns whether non-pic code is completely invalid on the given target.
75pub fn requiresPic(target: *const std.Target, linking_libc: bool) bool {75pub fn requiresPic(target: *const std.Target) bool {
76 return ((target.os.tag == .windows or target.os.tag == .uefi) and (target.cpu.arch == .aarch64 or target.cpu.arch == .x86_64)) or76 return (target.os.tag == .windows or target.os.tag == .uefi) and (target.cpu.arch == .aarch64 or target.cpu.arch == .x86_64);
77 target.requiresLibC() or
78 (linking_libc and target.isGnuLibC());
79}77}
8078
81pub fn requiresPicForDynamicLink(target: *const std.Target) bool {79pub fn requiresPicForDynamicLink(target: *const std.Target) bool {