Merge pull request #14771 from kcbanner/coff_dynamicbase

Allow dynamicbase to be disabled by CompileStep
This commit is contained in:
Jakub Konka 2023-03-28 20:18:25 +02:00 committed by GitHub
commit 2b80552603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View File

@ -140,6 +140,9 @@ link_function_sections: bool = false,
/// exported symbols.
link_gc_sections: ?bool = null,
/// (Windows) Whether or not to enable ASLR. Maps to the /DYNAMICBASE[:NO] linker argument.
linker_dynamicbase: bool = true,
linker_allow_shlib_undefined: ?bool = null,
/// 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 {
if (self.link_gc_sections) |x| {
try zig_args.append(if (x) "--gc-sections" else "--no-gc-sections");
}
if (!self.linker_dynamicbase) {
try zig_args.append("--no-dynamicbase");
}
if (self.linker_allow_shlib_undefined) |x| {
try zig_args.append(if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");
}

View File

@ -575,7 +575,7 @@ pub const InitOptions = struct {
linker_z_max_page_size: ?u64 = null,
linker_tsaware: bool = false,
linker_nxcompat: bool = false,
linker_dynamicbase: bool = false,
linker_dynamicbase: bool = true,
linker_optimization: ?u8 = null,
linker_compress_debug_sections: ?link.CompressDebugSections = null,
linker_module_definition_file: ?[]const u8 = null,

View File

@ -223,8 +223,8 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
if (self.base.options.nxcompat) {
try argv.append("-nxcompat");
}
if (self.base.options.dynamicbase) {
try argv.append("-dynamicbase");
if (!self.base.options.dynamicbase) {
try argv.append("-dynamicbase:NO");
}
try argv.append(try allocPrint(arena, "-OUT:{s}", .{full_out_path}));

View File

@ -778,7 +778,7 @@ fn buildOutputType(
var linker_z_max_page_size: ?u64 = null;
var linker_tsaware = false;
var linker_nxcompat = false;
var linker_dynamicbase = false;
var linker_dynamicbase = true;
var linker_optimization: ?u8 = null;
var linker_module_definition_file: ?[]const u8 = null;
var test_evented_io = false;
@ -1371,6 +1371,10 @@ fn buildOutputType(
linker_opt_bisect_limit = std.math.lossyCast(i32, parseIntSuffix(arg, "-fopt-bisect-limit=".len));
} else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
link_eh_frame_hdr = true;
} else if (mem.eql(u8, arg, "--dynamicbase")) {
linker_dynamicbase = true;
} else if (mem.eql(u8, arg, "--no-dynamicbase")) {
linker_dynamicbase = false;
} else if (mem.eql(u8, arg, "--emit-relocs")) {
link_emit_relocs = true;
} else if (mem.eql(u8, arg, "-fallow-shlib-undefined")) {
@ -2105,8 +2109,8 @@ fn buildOutputType(
linker_tsaware = true;
} else if (mem.eql(u8, arg, "--nxcompat")) {
linker_nxcompat = true;
} else if (mem.eql(u8, arg, "--dynamicbase")) {
linker_dynamicbase = true;
} else if (mem.eql(u8, arg, "--no-dynamicbase")) {
linker_dynamicbase = false;
} else if (mem.eql(u8, arg, "--high-entropy-va")) {
// This option does not do anything.
} else if (mem.eql(u8, arg, "--export-all-symbols")) {