Commit 162b92c93e

Michael Dusan <michael.dusan@gmail.com>
2021-06-16 06:35:20
netbsd: add args to limit number of PT_LOAD segs
NetBSD expects 2 PT_LOAD segments in a shared object, otherwise ld.elf_so fails to load, emitting a general "not found" error. Workaround issue by adding args `--no-rosegment` and `-znorelro`. see #9109
1 parent 8be2967
Changed files (1)
src
link
src/link/Elf.zig
@@ -1496,6 +1496,15 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
             try argv.append("-pie");
         }
 
+        if (self.base.options.link_mode == .Dynamic and target.os.tag == .netbsd) {
+            // Add options to produce shared objects with only 2 PT_LOAD segments.
+            // NetBSD expects 2 PT_LOAD segments in a shared object, otherwise
+            // ld.elf_so fails to load, emitting a general "not found" error.
+            // See https://github.com/ziglang/zig/issues/9109 .
+            try argv.append("--no-rosegment");
+            try argv.append("-znorelro");
+        }
+
         try argv.append("-o");
         try argv.append(full_out_path);