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
This commit is contained in:
Michael Dusan
2021-06-16 00:35:20 -04:00
committed by Andrew Kelley
parent 8be29674a9
commit 162b92c93e

View File

@@ -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);