From 399eaa3d410da35de6f5d1869932a7c0e8ca46b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 16 Aug 2026 14:59:34 +0200 Subject: [PATCH] compiler: default to PIC for objects and static libraries This makes it so that objects and static libraries produced by Zig can be linked into PIEs and shared libraries by default. This matches how almost all C/C++ toolchains are configured in Linux/BSD distros today. For cases where the user knows better and wants to squeeze out some (usually very minor) extra performance, they can just explicitly disable PIC when producing the object or static library. --- src/Module.zig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Module.zig b/src/Module.zig index a6054a9181278e73390f9a04e9ee19c96111fb05..5154b853641c4ed2af01fd0aed1b8c1f911204a6 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -195,10 +195,9 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Module { if (options.inherited.pic) |x| break :b x; if (options.parent) |p| break :b p.pic; - // Default to PIC on targets where we default to producing PIEs to make - // the common case of linking objects and static libraries into an - // executable work out of the box. - break :b target_util.defaultPie(target); + // Default to PIC for objects and static libraries to make the common + // cases of linking those into a PIE or a shared library just work. + break :b options.global.output_mode != .Exe; }; const red_zone = b: { -- 2.54.0