aboutsummaryrefslogtreecommitdiffstats
path: root/testing/zig/fix-build.zig.patch
blob: fa6f45448acd79a853d599d899be85a552deadd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
diff --git a/build.zig b/build.zig
index 390f1594..ca78bdf1 100644
--- a/build.zig
+++ b/build.zig
@@ -373,6 +373,7 @@ fn addLibUserlandStep(b: *Builder, mode: builtin.Mode) void {
     artifact.bundle_compiler_rt = true;
     artifact.setTarget(builtin.arch, builtin.os, builtin.abi);
     artifact.setBuildMode(mode);
+    artifact.force_pic = true;
     if (mode != .Debug) {
         artifact.strip = true;
     }
diff --git a/lib/std/build.zig b/lib/std/build.zig
index c640f6e8..cc062f3a 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -1488,6 +1488,9 @@ pub const LibExeObjStep = struct {
 
     dynamic_linker: ?[]const u8 = null,
 
+    /// Position Independent Code
+    force_pic: ?bool = null,
+
     const LinkObject = union(enum) {
         StaticPath: []const u8,
         OtherStep: *LibExeObjStep,
@@ -2314,6 +2317,14 @@ pub const LibExeObjStep = struct {
             try zig_args.append(builder.pathFromRoot(dir));
         }
 
+        if (self.force_pic) |pic| {
+            if (pic) {
+                try zig_args.append("-fPIC");
+            } else {
+                try zig_args.append("-fno-PIC");
+            }
+        }
+
         if (self.kind == Kind.Test) {
             try builder.spawnChild(zig_args.toSliceConst());
         } else {