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 {...@@ -764,6 +764,7 @@ pub const InitOptions = struct {
764 linker_z_noexecstack: bool = false,764 linker_z_noexecstack: bool = false,
765 linker_z_now: bool = false,765 linker_z_now: bool = false,
766 linker_z_relro: bool = false,766 linker_z_relro: bool = false,
767 linker_z_nocopyreloc: bool = false,
767 linker_tsaware: bool = false,768 linker_tsaware: bool = false,
768 linker_nxcompat: bool = false,769 linker_nxcompat: bool = false,
769 linker_dynamicbase: bool = false,770 linker_dynamicbase: bool = false,
...@@ -1597,6 +1598,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1597,6 +1598,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1597 .z_notext = options.linker_z_notext,1598 .z_notext = options.linker_z_notext,
1598 .z_defs = options.linker_z_defs,1599 .z_defs = options.linker_z_defs,
1599 .z_origin = options.linker_z_origin,1600 .z_origin = options.linker_z_origin,
1601 .z_nocopyreloc = options.linker_z_nocopyreloc,
1600 .z_noexecstack = options.linker_z_noexecstack,1602 .z_noexecstack = options.linker_z_noexecstack,
1601 .z_now = options.linker_z_now,1603 .z_now = options.linker_z_now,
1602 .z_relro = options.linker_z_relro,1604 .z_relro = options.linker_z_relro,
...@@ -2255,7 +2257,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo...@@ -2255,7 +2257,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo
2255/// to remind the programmer to update multiple related pieces of code that2257/// to remind the programmer to update multiple related pieces of code that
2256/// are in different locations. Bump this number when adding or deleting2258/// are in different locations. Bump this number when adding or deleting
2257/// anything from the link cache manifest.2259/// anything from the link cache manifest.
2258pub const link_hash_implementation_version = 2;2260pub const link_hash_implementation_version = 3;
22592261
2260fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifest) !void {2262fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifest) !void {
2261 const gpa = comp.gpa;2263 const gpa = comp.gpa;
...@@ -2265,7 +2267,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2265,7 +2267,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2265 defer arena_allocator.deinit();2267 defer arena_allocator.deinit();
2266 const arena = arena_allocator.allocator();2268 const arena = arena_allocator.allocator();
22672269
2268 comptime assert(link_hash_implementation_version == 2);2270 comptime assert(link_hash_implementation_version == 3);
22692271
2270 if (comp.bin_file.options.module) |mod| {2272 if (comp.bin_file.options.module) |mod| {
2271 const main_zig_file = try mod.main_pkg.root_src_directory.join(arena, &[_][]const u8{2273 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...@@ -2333,6 +2335,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2333 man.hash.add(comp.bin_file.options.z_notext);2335 man.hash.add(comp.bin_file.options.z_notext);
2334 man.hash.add(comp.bin_file.options.z_defs);2336 man.hash.add(comp.bin_file.options.z_defs);
2335 man.hash.add(comp.bin_file.options.z_origin);2337 man.hash.add(comp.bin_file.options.z_origin);
2338 man.hash.add(comp.bin_file.options.z_nocopyreloc);
2336 man.hash.add(comp.bin_file.options.z_noexecstack);2339 man.hash.add(comp.bin_file.options.z_noexecstack);
2337 man.hash.add(comp.bin_file.options.z_now);2340 man.hash.add(comp.bin_file.options.z_now);
2338 man.hash.add(comp.bin_file.options.z_relro);2341 man.hash.add(comp.bin_file.options.z_relro);
src/link.zig+1
...@@ -112,6 +112,7 @@ pub const Options = struct {...@@ -112,6 +112,7 @@ pub const Options = struct {
112 z_notext: bool,112 z_notext: bool,
113 z_defs: bool,113 z_defs: bool,
114 z_origin: bool,114 z_origin: bool,
115 z_nocopyreloc: bool,
115 z_noexecstack: bool,116 z_noexecstack: bool,
116 z_now: bool,117 z_now: bool,
117 z_relro: bool,118 z_relro: bool,
src/link/Coff.zig+1-1
...@@ -969,7 +969,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -969,7 +969,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !
969 man = comp.cache_parent.obtain();969 man = comp.cache_parent.obtain();
970 self.base.releaseLock();970 self.base.releaseLock();
971971
972 comptime assert(Compilation.link_hash_implementation_version == 2);972 comptime assert(Compilation.link_hash_implementation_version == 3);
973973
974 for (self.base.options.objects) |obj| {974 for (self.base.options.objects) |obj| {
975 _ = try man.addFile(obj.path, null);975 _ = 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...@@ -1294,7 +1294,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1294 // We are about to obtain this lock, so here we give other processes a chance first.1294 // We are about to obtain this lock, so here we give other processes a chance first.
1295 self.base.releaseLock();1295 self.base.releaseLock();
12961296
1297 comptime assert(Compilation.link_hash_implementation_version == 2);1297 comptime assert(Compilation.link_hash_implementation_version == 3);
12981298
1299 try man.addOptionalFile(self.base.options.linker_script);1299 try man.addOptionalFile(self.base.options.linker_script);
1300 try man.addOptionalFile(self.base.options.version_script);1300 try man.addOptionalFile(self.base.options.version_script);
...@@ -1325,6 +1325,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -1325,6 +1325,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1325 man.hash.add(self.base.options.z_notext);1325 man.hash.add(self.base.options.z_notext);
1326 man.hash.add(self.base.options.z_defs);1326 man.hash.add(self.base.options.z_defs);
1327 man.hash.add(self.base.options.z_origin);1327 man.hash.add(self.base.options.z_origin);
1328 man.hash.add(self.base.options.z_nocopyreloc);
1328 man.hash.add(self.base.options.z_noexecstack);1329 man.hash.add(self.base.options.z_noexecstack);
1329 man.hash.add(self.base.options.z_now);1330 man.hash.add(self.base.options.z_now);
1330 man.hash.add(self.base.options.z_relro);1331 man.hash.add(self.base.options.z_relro);
...@@ -1496,6 +1497,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -1496,6 +1497,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1496 try argv.append("-z");1497 try argv.append("-z");
1497 try argv.append("origin");1498 try argv.append("origin");
1498 }1499 }
1500 if (self.base.options.z_nocopyreloc) {
1501 try argv.append("-z");
1502 try argv.append("nocopyreloc");
1503 }
1499 if (self.base.options.z_noexecstack) {1504 if (self.base.options.z_noexecstack) {
1500 try argv.append("-z");1505 try argv.append("-z");
1501 try argv.append("noexecstack");1506 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...@@ -527,7 +527,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
527 // We are about to obtain this lock, so here we give other processes a chance first.527 // We are about to obtain this lock, so here we give other processes a chance first.
528 self.base.releaseLock();528 self.base.releaseLock();
529529
530 comptime assert(Compilation.link_hash_implementation_version == 2);530 comptime assert(Compilation.link_hash_implementation_version == 3);
531531
532 for (self.base.options.objects) |obj| {532 for (self.base.options.objects) |obj| {
533 _ = try man.addFile(obj.path, null);533 _ = 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) !...@@ -2274,7 +2274,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
2274 // We are about to obtain this lock, so here we give other processes a chance first.2274 // We are about to obtain this lock, so here we give other processes a chance first.
2275 self.base.releaseLock();2275 self.base.releaseLock();
22762276
2277 comptime assert(Compilation.link_hash_implementation_version == 2);2277 comptime assert(Compilation.link_hash_implementation_version == 3);
22782278
2279 for (self.base.options.objects) |obj| {2279 for (self.base.options.objects) |obj| {
2280 _ = try man.addFile(obj.path, null);2280 _ = try man.addFile(obj.path, null);
src/main.zig+1
...@@ -430,6 +430,7 @@ const usage_build_generic =...@@ -430,6 +430,7 @@ const usage_build_generic =
430 \\ notext Permit read-only relocations in read-only segments430 \\ notext Permit read-only relocations in read-only segments
431 \\ defs Force a fatal error if any undefined symbols remain431 \\ defs Force a fatal error if any undefined symbols remain
432 \\ origin Indicate that the object must have its origin processed432 \\ origin Indicate that the object must have its origin processed
433 \\ nocopyreloc Disable the creation of copy relocations
433 \\ noexecstack Indicate that the object requires an executable stack434 \\ noexecstack Indicate that the object requires an executable stack
434 \\ now Force all relocations to be processed on load435 \\ now Force all relocations to be processed on load
435 \\ relro Force all relocations to be resolved and be read-only on load436 \\ relro Force all relocations to be resolved and be read-only on load