From 85d87c9ca1f0c0c7fe9efa5ab54e306c6a309de3 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Mon, 21 Oct 2024 20:24:58 -0400 Subject: [PATCH] coff: fix incorrect default `image_base` values and re-enable shared library tests on Windows This was the cause of aarch64-windows shared libraries causing "bad image" errors during load-time linking. I also re-enabled the tests that were surfacing this bug. --- src/link/Coff.zig | 10 +++++++--- test/standalone/c_compiler/build.zig | 5 ----- test/standalone/coff_dwarf/build.zig | 5 ----- test/standalone/load_dynamic_library/build.zig | 5 ----- test/standalone/shared_library/build.zig | 5 ----- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 1b25ee5e0952f151a3f0cca0375632a95a3d36a4..eb2c0d6fb5e9e24b20704df27bee66f6f6dc0f46 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -274,11 +274,15 @@ pub fn createEmpty( .image_base = options.image_base orelse switch (output_mode) { .Exe => switch (target.cpu.arch) { - .aarch64 => 0x140000000, - .thumb, .x86_64, .x86 => 0x400000, + .aarch64, .x86_64 => 0x140000000, + .thumb, .x86 => 0x400000, + else => unreachable, + }, + .Lib => switch (target.cpu.arch) { + .aarch64, .x86_64 => 0x180000000, + .thumb, .x86 => 0x10000000, else => unreachable, }, - .Lib => 0x10000000, .Obj => 0, }, diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig index d4fcde119870af276bb0f7f20fb9f4daca0f36fe..5328d6e01d0e49e98bda6dc4c1b74cec1ad3500e 100644 --- a/test/standalone/c_compiler/build.zig +++ b/test/standalone/c_compiler/build.zig @@ -5,11 +5,6 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test it"); b.default_step = test_step; - if (builtin.os.tag == .windows) { - // https://github.com/ziglang/zig/issues/16965 - return; - } - add(b, test_step, "test_c_Debug", "test_cpp_Debug", .Debug); add(b, test_step, "test_c_ReleaseFast", "test_cpp_ReleaseFast", .ReleaseFast); add(b, test_step, "test_c_ReleaseSmall", "test_cpp_ReleaseSmall", .ReleaseSmall); diff --git a/test/standalone/coff_dwarf/build.zig b/test/standalone/coff_dwarf/build.zig index 26a8a87da8c9afe38aec7ae616af81b59e632848..bb9879d089ddb8f188036025efc68015ce6b63ca 100644 --- a/test/standalone/coff_dwarf/build.zig +++ b/test/standalone/coff_dwarf/build.zig @@ -12,11 +12,6 @@ pub fn build(b: *std.Build) void { else b.resolveTargetQuery(.{ .os_tag = .windows }); - if (builtin.cpu.arch == .aarch64) { - // https://github.com/ziglang/zig/issues/18427 - return; - } - const exe = b.addExecutable(.{ .name = "main", .root_source_file = b.path("main.zig"), diff --git a/test/standalone/load_dynamic_library/build.zig b/test/standalone/load_dynamic_library/build.zig index 1fe7d6141f4a8a33fc439662cb0b6191f8eacf84..f484d2a6e6fff88e06f31a7ac7c33fbd05336f5a 100644 --- a/test/standalone/load_dynamic_library/build.zig +++ b/test/standalone/load_dynamic_library/build.zig @@ -10,11 +10,6 @@ pub fn build(b: *std.Build) void { if (builtin.os.tag == .wasi) return; - if (builtin.os.tag == .windows) { - // https://github.com/ziglang/zig/issues/16960 - return; - } - const lib = b.addSharedLibrary(.{ .name = "add", .root_source_file = b.path("add.zig"), diff --git a/test/standalone/shared_library/build.zig b/test/standalone/shared_library/build.zig index c23efd0e922a3dc46820b5f3c35ac1eaf872fa44..28c1bdb13e1d81f328246325cd1e7508b0fd21de 100644 --- a/test/standalone/shared_library/build.zig +++ b/test/standalone/shared_library/build.zig @@ -4,11 +4,6 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test it"); b.default_step = test_step; - if (@import("builtin").os.tag == .windows) { - // https://github.com/ziglang/zig/issues/16959 - return; - } - const optimize: std.builtin.OptimizeMode = .Debug; const target = b.graph.host; const lib = b.addSharedLibrary(.{ -- 2.54.0