authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2022-06-09 00:06:16+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-09 18:51:43-04:00
log5816d3eaec3f3bb04e70c89aa402ba9e0e5e7b2c
tree2cccbd1ac1b95a10823fdd092d3d38ee84b76e8d
parentf1cff4fa4a28d42ac9055f94ee9a8f7fd2831cd7

linker: remove `-z noexecstack` option

Note that the current documentation for the `-z noexecstack` is incorrect. This indicates that an object *does not* require an executable stack. This is actually the default of LLD, and there has never been a way to override this default by passing `-z execstack` to LLD. This commit removes the redundant `-z noexecstack` option from zig build-exe/build-lib/build-obj and ignores the option if passed to zig cc for compatibility. As far as I can tell, there is no reason for code to require an executable stack. This option only exists because the stack was originally executable by default and some programs came to depend on that behavior. Instead, mprotect(2) may be used to make memory pages executable.

4 files changed, 1 insertions(+), 15 deletions(-)

src/Compilation.zig-3
......@@ -762,7 +762,6 @@ pub const InitOptions = struct {
762762 linker_z_notext: bool = false,
763763 linker_z_defs: bool = false,
764764 linker_z_origin: bool = false,
765 linker_z_noexecstack: bool = false,
766765 linker_z_now: bool = true,
767766 linker_z_relro: bool = true,
768767 linker_z_nocopyreloc: bool = false,
......@@ -1602,7 +1601,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16021601 .z_defs = options.linker_z_defs,
16031602 .z_origin = options.linker_z_origin,
16041603 .z_nocopyreloc = options.linker_z_nocopyreloc,
1605 .z_noexecstack = options.linker_z_noexecstack,
16061604 .z_now = options.linker_z_now,
16071605 .z_relro = options.linker_z_relro,
16081606 .tsaware = options.linker_tsaware,
......@@ -2350,7 +2348,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
23502348 man.hash.add(comp.bin_file.options.z_defs);
23512349 man.hash.add(comp.bin_file.options.z_origin);
23522350 man.hash.add(comp.bin_file.options.z_nocopyreloc);
2353 man.hash.add(comp.bin_file.options.z_noexecstack);
23542351 man.hash.add(comp.bin_file.options.z_now);
23552352 man.hash.add(comp.bin_file.options.z_relro);
23562353 man.hash.add(comp.bin_file.options.hash_style);
src/link.zig-1
......@@ -113,7 +113,6 @@ pub const Options = struct {
113113 z_defs: bool,
114114 z_origin: bool,
115115 z_nocopyreloc: bool,
116 z_noexecstack: bool,
117116 z_now: bool,
118117 z_relro: bool,
119118 tsaware: bool,
src/link/Elf.zig-5
......@@ -1333,7 +1333,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
13331333 man.hash.add(self.base.options.z_defs);
13341334 man.hash.add(self.base.options.z_origin);
13351335 man.hash.add(self.base.options.z_nocopyreloc);
1336 man.hash.add(self.base.options.z_noexecstack);
13371336 man.hash.add(self.base.options.z_now);
13381337 man.hash.add(self.base.options.z_relro);
13391338 man.hash.add(self.base.options.hash_style);
......@@ -1512,10 +1511,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
15121511 try argv.append("-z");
15131512 try argv.append("nocopyreloc");
15141513 }
1515 if (self.base.options.z_noexecstack) {
1516 try argv.append("-z");
1517 try argv.append("noexecstack");
1518 }
15191514 if (self.base.options.z_now) {
15201515 // LLD defaults to -zlazy
15211516 try argv.append("-znow");
src/main.zig+1-6
......@@ -433,7 +433,6 @@ const usage_build_generic =
433433 \\ defs Force a fatal error if any undefined symbols remain
434434 \\ origin Indicate that the object must have its origin processed
435435 \\ nocopyreloc Disable the creation of copy relocations
436 \\ noexecstack Indicate that the object requires an executable stack
437436 \\ now (default) Force all relocations to be processed on load
438437 \\ lazy Don't force all relocations to be processed on load
439438 \\ relro (default) Force all relocations to be read-only after processing
......@@ -656,7 +655,6 @@ fn buildOutputType(
656655 var linker_z_notext = false;
657656 var linker_z_defs = false;
658657 var linker_z_origin = false;
659 var linker_z_noexecstack = false;
660658 var linker_z_now = true;
661659 var linker_z_relro = true;
662660 var linker_tsaware = false;
......@@ -1207,8 +1205,6 @@ fn buildOutputType(
12071205 linker_z_defs = true;
12081206 } else if (mem.eql(u8, z_arg, "origin")) {
12091207 linker_z_origin = true;
1210 } else if (mem.eql(u8, z_arg, "noexecstack")) {
1211 linker_z_noexecstack = true;
12121208 } else if (mem.eql(u8, z_arg, "now")) {
12131209 linker_z_now = true;
12141210 } else if (mem.eql(u8, z_arg, "lazy")) {
......@@ -1694,7 +1690,7 @@ fn buildOutputType(
16941690 } else if (mem.eql(u8, z_arg, "origin")) {
16951691 linker_z_origin = true;
16961692 } else if (mem.eql(u8, z_arg, "noexecstack")) {
1697 linker_z_noexecstack = true;
1693 // noexecstack is the default when linking with LLD
16981694 } else if (mem.eql(u8, z_arg, "now")) {
16991695 linker_z_now = true;
17001696 } else if (mem.eql(u8, z_arg, "lazy")) {
......@@ -2719,7 +2715,6 @@ fn buildOutputType(
27192715 .linker_z_notext = linker_z_notext,
27202716 .linker_z_defs = linker_z_defs,
27212717 .linker_z_origin = linker_z_origin,
2722 .linker_z_noexecstack = linker_z_noexecstack,
27232718 .linker_z_now = linker_z_now,
27242719 .linker_z_relro = linker_z_relro,
27252720 .linker_tsaware = linker_tsaware,