authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-28 20:18:25+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-03-28 20:18:25+02:00
log2b805526033b0446fba7f38990df707204e7e23a
tree27eb2a50726b9f8980add2b2c380b17e80a54842
parent43487eb3ef0933c1da53b917c44ba6070d8e5a21
parent43ff6c14f96187ec93bbc23432cdbb885f5ab8f1
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #14771 from kcbanner/coff_dynamicbase

Allow dynamicbase to be disabled by CompileStep

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

lib/std/Build/CompileStep.zig+6
...@@ -140,6 +140,9 @@ link_function_sections: bool = false,...@@ -140,6 +140,9 @@ link_function_sections: bool = false,
140/// exported symbols.140/// exported symbols.
141link_gc_sections: ?bool = null,141link_gc_sections: ?bool = null,
142142
143/// (Windows) Whether or not to enable ASLR. Maps to the /DYNAMICBASE[:NO] linker argument.
144linker_dynamicbase: bool = true,
145
143linker_allow_shlib_undefined: ?bool = null,146linker_allow_shlib_undefined: ?bool = null,
144147
145/// Permit read-only relocations in read-only segments. Disallowed by default.148/// Permit read-only relocations in read-only segments. Disallowed by default.
...@@ -1474,6 +1477,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1474,6 +1477,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1474 if (self.link_gc_sections) |x| {1477 if (self.link_gc_sections) |x| {
1475 try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections");1478 try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections");
1476 }1479 }
1480 if (!self.linker_dynamicbase) {
1481 try zig_args.append("--no-dynamicbase");
1482 }
1477 if (self.linker_allow_shlib_undefined) |x| {1483 if (self.linker_allow_shlib_undefined) |x| {
1478 try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");1484 try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");
1479 }1485 }
src/Compilation.zig+1-1
...@@ -575,7 +575,7 @@ pub const InitOptions = struct {...@@ -575,7 +575,7 @@ pub const InitOptions = struct {
575 linker_z_max_page_size: ?u64 = null,575 linker_z_max_page_size: ?u64 = null,
576 linker_tsaware: bool = false,576 linker_tsaware: bool = false,
577 linker_nxcompat: bool = false,577 linker_nxcompat: bool = false,
578 linker_dynamicbase: bool = false,578 linker_dynamicbase: bool = true,
579 linker_optimization: ?u8 = null,579 linker_optimization: ?u8 = null,
580 linker_compress_debug_sections: ?link.CompressDebugSections = null,580 linker_compress_debug_sections: ?link.CompressDebugSections = null,
581 linker_module_definition_file: ?[]const u8 = null,581 linker_module_definition_file: ?[]const u8 = null,
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+7-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,10 @@ fn buildOutputType(...@@ -1371,6 +1371,10 @@ 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, "--dynamicbase")) {
1375 linker_dynamicbase = true;
1376 } else if (mem.eql(u8, arg, "--no-dynamicbase")) {
1377 linker_dynamicbase = false;
1374 } else if (mem.eql(u8, arg, "--emit-relocs")) {1378 } else if (mem.eql(u8, arg, "--emit-relocs")) {
1375 link_emit_relocs = true;1379 link_emit_relocs = true;
1376 } else if (mem.eql(u8, arg, "-fallow-shlib-undefined")) {1380 } else if (mem.eql(u8, arg, "-fallow-shlib-undefined")) {
...@@ -2105,8 +2109,8 @@ fn buildOutputType(...@@ -2105,8 +2109,8 @@ fn buildOutputType(
2105 linker_tsaware = true;2109 linker_tsaware = true;
2106 } else if (mem.eql(u8, arg, "--nxcompat")) {2110 } else if (mem.eql(u8, arg, "--nxcompat")) {
2107 linker_nxcompat = true;2111 linker_nxcompat = true;
2108 } else if (mem.eql(u8, arg, "--dynamicbase")) {2112 } else if (mem.eql(u8, arg, "--no-dynamicbase")) {
2109 linker_dynamicbase = true;2113 linker_dynamicbase = false;
2110 } else if (mem.eql(u8, arg, "--high-entropy-va")) {2114 } else if (mem.eql(u8, arg, "--high-entropy-va")) {
2111 // This option does not do anything.2115 // This option does not do anything.
2112 } else if (mem.eql(u8, arg, "--export-all-symbols")) {2116 } else if (mem.eql(u8, arg, "--export-all-symbols")) {