authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-03-02 22:15:31-05:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-03-25 16:26:48-04:00
log113f80bcf793b2841635d136e561bcc0bbe89086
treec72baba10ceab70b4f5fc23e6cb99261347ba5a6
parent37f6f7990e882ac9869513cf920f8cd0c4850039

coff: change dynamicbase to default to true (to match lld), change it to pass the negation to lld, and add --no-dynamicbase

build: expose linker_dynamicbase on CompileStep and map it to emit --no-dynamicbase

3 files changed, 12 insertions(+), 5 deletions(-)

lib/std/Build/CompileStep.zig+5
...@@ -140,6 +140,8 @@ link_function_sections: bool = false,...@@ -140,6 +140,8 @@ link_function_sections: bool = false,
140/// exported symbols.140/// exported symbols.
141link_gc_sections: ?bool = null,141link_gc_sections: ?bool = null,
142142
143linker_dynamicbase: ?bool = null,
144
143linker_allow_shlib_undefined: ?bool = null,145linker_allow_shlib_undefined: ?bool = null,
144146
145/// Permit read-only relocations in read-only segments. Disallowed by default.147/// Permit read-only relocations in read-only segments. Disallowed by default.
...@@ -1474,6 +1476,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1474,6 +1476,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1474 if (self.link_gc_sections) |x| {1476 if (self.link_gc_sections) |x| {
1475 try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections");1477 try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections");
1476 }1478 }
1479 if (self.linker_dynamicbase) |x| {
1480 if (!x) try zig_args.append("--no-dynamicbase");
1481 }
1477 if (self.linker_allow_shlib_undefined) |x| {1482 if (self.linker_allow_shlib_undefined) |x| {
1478 try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");1483 try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");
1479 }1484 }
src/link/Coff/lld.zig+2-2
...@@ -223,8 +223,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -223,8 +223,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
223 if (self.base.options.nxcompat) {223 if (self.base.options.nxcompat) {
224 try argv.append("-nxcompat");224 try argv.append("-nxcompat");
225 }225 }
226 if (self.base.options.dynamicbase) {226 if (!self.base.options.dynamicbase) {
227 try argv.append("-dynamicbase");227 try argv.append("-dynamicbase:NO");
228 }228 }
229229
230 try argv.append(try allocPrint(arena, "-OUT:{s}", .{full_out_path}));230 try argv.append(try allocPrint(arena, "-OUT:{s}", .{full_out_path}));
src/main.zig+5-3
...@@ -778,7 +778,7 @@ fn buildOutputType(...@@ -778,7 +778,7 @@ fn buildOutputType(
778 var linker_z_max_page_size: ?u64 = null;778 var linker_z_max_page_size: ?u64 = null;
779 var linker_tsaware = false;779 var linker_tsaware = false;
780 var linker_nxcompat = false;780 var linker_nxcompat = false;
781 var linker_dynamicbase = false;781 var linker_dynamicbase = true;
782 var linker_optimization: ?u8 = null;782 var linker_optimization: ?u8 = null;
783 var linker_module_definition_file: ?[]const u8 = null;783 var linker_module_definition_file: ?[]const u8 = null;
784 var test_evented_io = false;784 var test_evented_io = false;
...@@ -1371,6 +1371,8 @@ fn buildOutputType(...@@ -1371,6 +1371,8 @@ fn buildOutputType(
1371 linker_opt_bisect_limit = std.math.lossyCast(i32, parseIntSuffix(arg, "-fopt-bisect-limit=".len));1371 linker_opt_bisect_limit = std.math.lossyCast(i32, parseIntSuffix(arg, "-fopt-bisect-limit=".len));
1372 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {1372 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
1373 link_eh_frame_hdr = true;1373 link_eh_frame_hdr = true;
1374 } else if (mem.eql(u8, arg, "--no-dynamicbase")) {
1375 linker_dynamicbase = false;
1374 } else if (mem.eql(u8, arg, "--emit-relocs")) {1376 } else if (mem.eql(u8, arg, "--emit-relocs")) {
1375 link_emit_relocs = true;1377 link_emit_relocs = true;
1376 } else if (mem.eql(u8, arg, "-fallow-shlib-undefined")) {1378 } else if (mem.eql(u8, arg, "-fallow-shlib-undefined")) {
...@@ -2105,8 +2107,8 @@ fn buildOutputType(...@@ -2105,8 +2107,8 @@ fn buildOutputType(
2105 linker_tsaware = true;2107 linker_tsaware = true;
2106 } else if (mem.eql(u8, arg, "--nxcompat")) {2108 } else if (mem.eql(u8, arg, "--nxcompat")) {
2107 linker_nxcompat = true;2109 linker_nxcompat = true;
2108 } else if (mem.eql(u8, arg, "--dynamicbase")) {2110 } else if (mem.eql(u8, arg, "--no-dynamicbase")) {
2109 linker_dynamicbase = true;2111 linker_dynamicbase = false;
2110 } else if (mem.eql(u8, arg, "--high-entropy-va")) {2112 } else if (mem.eql(u8, arg, "--high-entropy-va")) {
2111 // This option does not do anything.2113 // This option does not do anything.
2112 } else if (mem.eql(u8, arg, "--export-all-symbols")) {2114 } else if (mem.eql(u8, arg, "--export-all-symbols")) {