authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2022-05-19 16:36:01+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-19 20:21:07-04:00
log1d532f12b568c924baead9de78701f66a526e16b
tree648c562336582e2bb3c4c81a21db2876ca1a2679
parent7b63f98cd7d86337e8157afc9600e1e17c27db80

[Elf] add -z nocopyreloc

Warnings about non-implemented `-z nocopyreloc` are common when compiling go code (including Go's tests themselves). Let's just make it stop complaining.

7 files changed, 16 insertions(+), 6 deletions(-)

src/Compilation.zig+5-2
......@@ -764,6 +764,7 @@ pub const InitOptions = struct {
764764 linker_z_noexecstack: bool = false,
765765 linker_z_now: bool = false,
766766 linker_z_relro: bool = false,
767 linker_z_nocopyreloc: bool = false,
767768 linker_tsaware: bool = false,
768769 linker_nxcompat: bool = false,
769770 linker_dynamicbase: bool = false,
......@@ -1597,6 +1598,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15971598 .z_notext = options.linker_z_notext,
15981599 .z_defs = options.linker_z_defs,
15991600 .z_origin = options.linker_z_origin,
1601 .z_nocopyreloc = options.linker_z_nocopyreloc,
16001602 .z_noexecstack = options.linker_z_noexecstack,
16011603 .z_now = options.linker_z_now,
16021604 .z_relro = options.linker_z_relro,
......@@ -2255,7 +2257,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo
22552257/// to remind the programmer to update multiple related pieces of code that
22562258/// are in different locations. Bump this number when adding or deleting
22572259/// anything from the link cache manifest.
2258pub const link_hash_implementation_version = 2;
2260pub const link_hash_implementation_version = 3;
22592261
22602262fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifest) !void {
22612263 const gpa = comp.gpa;
......@@ -2265,7 +2267,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
22652267 defer arena_allocator.deinit();
22662268 const arena = arena_allocator.allocator();
22672269
2268 comptime assert(link_hash_implementation_version == 2);
2270 comptime assert(link_hash_implementation_version == 3);
22692271
22702272 if (comp.bin_file.options.module) |mod| {
22712273 const main_zig_file = try mod.main_pkg.root_src_directory.join(arena, &[_][]const u8{
......@@ -2333,6 +2335,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
23332335 man.hash.add(comp.bin_file.options.z_notext);
23342336 man.hash.add(comp.bin_file.options.z_defs);
23352337 man.hash.add(comp.bin_file.options.z_origin);
2338 man.hash.add(comp.bin_file.options.z_nocopyreloc);
23362339 man.hash.add(comp.bin_file.options.z_noexecstack);
23372340 man.hash.add(comp.bin_file.options.z_now);
23382341 man.hash.add(comp.bin_file.options.z_relro);
src/link.zig+1
......@@ -112,6 +112,7 @@ pub const Options = struct {
112112 z_notext: bool,
113113 z_defs: bool,
114114 z_origin: bool,
115 z_nocopyreloc: bool,
115116 z_noexecstack: bool,
116117 z_now: bool,
117118 z_relro: bool,
src/link/Coff.zig+1-1
......@@ -969,7 +969,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !
969969 man = comp.cache_parent.obtain();
970970 self.base.releaseLock();
971971
972 comptime assert(Compilation.link_hash_implementation_version == 2);
972 comptime assert(Compilation.link_hash_implementation_version == 3);
973973
974974 for (self.base.options.objects) |obj| {
975975 _ = try man.addFile(obj.path, null);
src/link/Elf.zig+6-1
......@@ -1294,7 +1294,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
12941294 // We are about to obtain this lock, so here we give other processes a chance first.
12951295 self.base.releaseLock();
12961296
1297 comptime assert(Compilation.link_hash_implementation_version == 2);
1297 comptime assert(Compilation.link_hash_implementation_version == 3);
12981298
12991299 try man.addOptionalFile(self.base.options.linker_script);
13001300 try man.addOptionalFile(self.base.options.version_script);
......@@ -1325,6 +1325,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
13251325 man.hash.add(self.base.options.z_notext);
13261326 man.hash.add(self.base.options.z_defs);
13271327 man.hash.add(self.base.options.z_origin);
1328 man.hash.add(self.base.options.z_nocopyreloc);
13281329 man.hash.add(self.base.options.z_noexecstack);
13291330 man.hash.add(self.base.options.z_now);
13301331 man.hash.add(self.base.options.z_relro);
......@@ -1496,6 +1497,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
14961497 try argv.append("-z");
14971498 try argv.append("origin");
14981499 }
1500 if (self.base.options.z_nocopyreloc) {
1501 try argv.append("-z");
1502 try argv.append("nocopyreloc");
1503 }
14991504 if (self.base.options.z_noexecstack) {
15001505 try argv.append("-z");
15011506 try argv.append("noexecstack");
src/link/MachO.zig+1-1
......@@ -527,7 +527,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
527527 // We are about to obtain this lock, so here we give other processes a chance first.
528528 self.base.releaseLock();
529529
530 comptime assert(Compilation.link_hash_implementation_version == 2);
530 comptime assert(Compilation.link_hash_implementation_version == 3);
531531
532532 for (self.base.options.objects) |obj| {
533533 _ = try man.addFile(obj.path, null);
src/link/Wasm.zig+1-1
......@@ -2274,7 +2274,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
22742274 // We are about to obtain this lock, so here we give other processes a chance first.
22752275 self.base.releaseLock();
22762276
2277 comptime assert(Compilation.link_hash_implementation_version == 2);
2277 comptime assert(Compilation.link_hash_implementation_version == 3);
22782278
22792279 for (self.base.options.objects) |obj| {
22802280 _ = try man.addFile(obj.path, null);
src/main.zig+1
......@@ -430,6 +430,7 @@ const usage_build_generic =
430430 \\ notext Permit read-only relocations in read-only segments
431431 \\ defs Force a fatal error if any undefined symbols remain
432432 \\ origin Indicate that the object must have its origin processed
433 \\ nocopyreloc Disable the creation of copy relocations
433434 \\ noexecstack Indicate that the object requires an executable stack
434435 \\ now Force all relocations to be processed on load
435436 \\ relro Force all relocations to be resolved and be read-only on load