authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-09-01 16:37:07+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-11-03 12:48:53+01:00
log938f9dea374193972be05b19b58dced54d79b1cb
tree3778a6e153a29ffa267c9ab3e6b64824466d6d25
parent58618afaee7c14feedad4f115e9a4468bac4c529
signaturelock-open Commit is signed but in an unrecognized format.

update linker tests

This updates all linker tests to include `no_entry` as well as changes all tests to executable so they do not need to be updated later when the in-house WebAssembly linker supports dynamic libraries.

14 files changed, 113 insertions(+), 93 deletions(-)

lib/std/Build/Step/Compile.zig+5-1
......@@ -1853,7 +1853,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
18531853 if (self.global_base) |global_base| {
18541854 try zig_args.append(b.fmt("--global-base={d}", .{global_base}));
18551855 }
1856 try addFlag(&zig_args, "entry", self.no_entry);
1856 // invert the value due to naming so when `no_entry` is set to 'true'
1857 // we actually emit the flag `-fno_entry`.
1858 if (self.no_entry) |no_entry| {
1859 try addFlag(&zig_args, "entry", !no_entry);
1860 }
18571861
18581862 if (self.code_model != .default) {
18591863 try zig_args.append("-mcmodel");
test/link/wasm/archive/build.zig+2-1
......@@ -15,12 +15,13 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 // The code in question will pull-in compiler-rt,
1717 // and therefore link with its archive file.
18 const lib = b.addSharedLibrary(.{
18 const lib = b.addExecutable(.{
1919 .name = "main",
2020 .root_source_file = .{ .path = "main.zig" },
2121 .optimize = optimize,
2222 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2323 });
24 lib.no_entry = true;
2425 lib.use_llvm = false;
2526 lib.use_lld = false;
2627 lib.strip = false;
test/link/wasm/basic-features/build.zig+2-1
......@@ -4,7 +4,7 @@ pub const requires_stage2 = true;
44
55pub fn build(b: *std.Build) void {
66 // Library with explicitly set cpu features
7 const lib = b.addSharedLibrary(.{
7 const lib = b.addExecutable(.{
88 .name = "lib",
99 .root_source_file = .{ .path = "main.zig" },
1010 .optimize = .Debug,
......@@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void {
1515 .os_tag = .freestanding,
1616 },
1717 });
18 lib.no_entry = true;
1819 lib.use_llvm = false;
1920 lib.use_lld = false;
2021
test/link/wasm/bss/build.zig+4-2
......@@ -14,12 +14,13 @@ pub fn build(b: *std.Build) void {
1414
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode, is_safe: bool) void {
1616 {
17 const lib = b.addSharedLibrary(.{
17 const lib = b.addExecutable(.{
1818 .name = "lib",
1919 .root_source_file = .{ .path = "lib.zig" },
2020 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2121 .optimize = optimize_mode,
2222 });
23 lib.no_entry = true;
2324 lib.use_llvm = false;
2425 lib.use_lld = false;
2526 lib.strip = false;
......@@ -60,12 +61,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
6061
6162 // verify zero'd declaration is stored in bss for all optimization modes.
6263 {
63 const lib = b.addSharedLibrary(.{
64 const lib = b.addExecutable(.{
6465 .name = "lib",
6566 .root_source_file = .{ .path = "lib2.zig" },
6667 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
6768 .optimize = optimize_mode,
6869 });
70 lib.no_entry = true;
6971 lib.use_llvm = false;
7072 lib.use_lld = false;
7173 lib.strip = false;
test/link/wasm/export-data/build.zig+2-1
......@@ -9,12 +9,13 @@ pub fn build(b: *std.Build) void {
99 return;
1010 }
1111
12 const lib = b.addSharedLibrary(.{
12 const lib = b.addExecutable(.{
1313 .name = "lib",
1414 .root_source_file = .{ .path = "lib.zig" },
1515 .optimize = .ReleaseSafe, // to make the output deterministic in address positions
1616 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
1717 });
18 lib.no_entry = true;
1819 lib.use_lld = false;
1920 lib.export_symbol_names = &.{ "foo", "bar" };
2021 lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse
test/link/wasm/export/build.zig+6-3
......@@ -13,31 +13,34 @@ pub fn build(b: *std.Build) void {
1313}
1414
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const no_export = b.addSharedLibrary(.{
16 const no_export = b.addExecutable(.{
1717 .name = "no-export",
1818 .root_source_file = .{ .path = "main.zig" },
1919 .optimize = optimize,
2020 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2121 });
22 no_export.no_entry = true;
2223 no_export.use_llvm = false;
2324 no_export.use_lld = false;
2425
25 const dynamic_export = b.addSharedLibrary(.{
26 const dynamic_export = b.addExecutable(.{
2627 .name = "dynamic",
2728 .root_source_file = .{ .path = "main.zig" },
2829 .optimize = optimize,
2930 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
3031 });
32 dynamic_export.no_entry = true;
3133 dynamic_export.rdynamic = true;
3234 dynamic_export.use_llvm = false;
3335 dynamic_export.use_lld = false;
3436
35 const force_export = b.addSharedLibrary(.{
37 const force_export = b.addExecutable(.{
3638 .name = "force",
3739 .root_source_file = .{ .path = "main.zig" },
3840 .optimize = optimize,
3941 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
4042 });
43 force_export.no_entry = true;
4144 force_export.export_symbol_names = &.{"foo"};
4245 force_export.use_llvm = false;
4346 force_export.use_lld = false;
test/link/wasm/extern-mangle/build.zig+2-1
......@@ -11,12 +11,13 @@ pub fn build(b: *std.Build) void {
1111}
1212
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14 const lib = b.addSharedLibrary(.{
14 const lib = b.addExecutable(.{
1515 .name = "lib",
1616 .root_source_file = .{ .path = "lib.zig" },
1717 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
1818 .optimize = optimize,
1919 });
20 lib.no_entry = true;
2021 lib.import_symbols = true; // import `a` and `b`
2122 lib.rdynamic = true; // export `foo`
2223
test/link/wasm/function-table/build.zig+6-3
......@@ -13,32 +13,35 @@ pub fn build(b: *std.Build) void {
1313}
1414
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const import_table = b.addSharedLibrary(.{
16 const import_table = b.addExecutable(.{
1717 .name = "import_table",
1818 .root_source_file = .{ .path = "lib.zig" },
1919 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2020 .optimize = optimize,
2121 });
22 import_table.no_entry = true;
2223 import_table.use_llvm = false;
2324 import_table.use_lld = false;
2425 import_table.import_table = true;
2526
26 const export_table = b.addSharedLibrary(.{
27 const export_table = b.addExecutable(.{
2728 .name = "export_table",
2829 .root_source_file = .{ .path = "lib.zig" },
2930 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
3031 .optimize = optimize,
3132 });
33 export_table.no_entry = true;
3234 export_table.use_llvm = false;
3335 export_table.use_lld = false;
3436 export_table.export_table = true;
3537
36 const regular_table = b.addSharedLibrary(.{
38 const regular_table = b.addExecutable(.{
3739 .name = "regular_table",
3840 .root_source_file = .{ .path = "lib.zig" },
3941 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
4042 .optimize = optimize,
4143 });
44 regular_table.no_entry = true;
4245 regular_table.use_llvm = false;
4346 regular_table.use_lld = false;
4447
test/link/wasm/infer-features/build.zig+2-1
......@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
1717
1818 // Wasm library that doesn't have any features specified. This will
1919 // infer its featureset from other linked object files.
20 const lib = b.addSharedLibrary(.{
20 const lib = b.addExecutable(.{
2121 .name = "lib",
2222 .root_source_file = .{ .path = "main.zig" },
2323 .optimize = .Debug,
......@@ -27,6 +27,7 @@ pub fn build(b: *std.Build) void {
2727 .os_tag = .freestanding,
2828 },
2929 });
30 lib.no_entry = true;
3031 lib.use_llvm = false;
3132 lib.use_lld = false;
3233 lib.addObject(c_obj);
test/link/wasm/producers/build.zig+2-1
......@@ -14,12 +14,13 @@ pub fn build(b: *std.Build) void {
1414}
1515
1616fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
17 const lib = b.addSharedLibrary(.{
17 const lib = b.addExecutable(.{
1818 .name = "lib",
1919 .root_source_file = .{ .path = "lib.zig" },
2020 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2121 .optimize = optimize,
2222 });
23 lib.no_entry = true;
2324 lib.use_llvm = false;
2425 lib.use_lld = false;
2526 lib.strip = false;
test/link/wasm/segments/build.zig+2-1
......@@ -13,12 +13,13 @@ pub fn build(b: *std.Build) void {
1313}
1414
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const lib = b.addSharedLibrary(.{
16 const lib = b.addExecutable(.{
1717 .name = "lib",
1818 .root_source_file = .{ .path = "lib.zig" },
1919 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2020 .optimize = optimize,
2121 });
22 lib.no_entry = true;
2223 lib.use_llvm = false;
2324 lib.use_lld = false;
2425 lib.strip = false;
test/link/wasm/shared-memory/build.zig+74-75
......@@ -11,88 +11,87 @@ pub fn build(b: *std.Build) void {
1111}
1212
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {
14 {
15 const lib = b.addSharedLibrary(.{
16 .name = "lib",
17 .root_source_file = .{ .path = "lib.zig" },
18 .target = .{
19 .cpu_arch = .wasm32,
20 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
21 .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
22 .os_tag = .freestanding,
23 },
24 .optimize = optimize_mode,
25 });
26 lib.use_lld = false;
27 lib.strip = false;
28 lib.import_memory = true;
29 lib.export_memory = true;
30 lib.shared_memory = true;
31 lib.max_memory = 67108864;
32 lib.single_threaded = false;
33 lib.export_symbol_names = &.{"foo"};
14 const lib = b.addExecutable(.{
15 .name = "lib",
16 .root_source_file = .{ .path = "lib.zig" },
17 .target = .{
18 .cpu_arch = .wasm32,
19 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
20 .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
21 .os_tag = .freestanding,
22 },
23 .optimize = optimize_mode,
24 });
25 lib.no_entry = true;
26 lib.use_lld = false;
27 lib.strip = false;
28 lib.import_memory = true;
29 lib.export_memory = true;
30 lib.shared_memory = true;
31 lib.max_memory = 67108864;
32 lib.single_threaded = false;
33 lib.export_symbol_names = &.{"foo"};
3434
35 const check_lib = lib.checkObject();
35 const check_lib = lib.checkObject();
3636
37 check_lib.checkStart("Section import");
38 check_lib.checkNext("entries 1");
39 check_lib.checkNext("module env");
40 check_lib.checkNext("name memory"); // ensure we are importing memory
37 check_lib.checkStart("Section import");
38 check_lib.checkNext("entries 1");
39 check_lib.checkNext("module env");
40 check_lib.checkNext("name memory"); // ensure we are importing memory
4141
42 check_lib.checkStart("Section export");
43 check_lib.checkNext("entries 2");
44 check_lib.checkNext("name memory"); // ensure we also export memory again
42 check_lib.checkStart("Section export");
43 check_lib.checkNext("entries 2");
44 check_lib.checkNext("name memory"); // ensure we also export memory again
4545
46 // This section *must* be emit as the start function is set to the index
47 // of __wasm_init_memory
48 // release modes will have the TLS segment optimized out in our test-case.
49 // This means we won't have __wasm_init_memory in such case, and therefore
50 // should also not have a section "start"
51 if (optimize_mode == .Debug) {
52 check_lib.checkStart("Section start");
53 }
54
55 // This section is only and *must* be emit when shared-memory is enabled
56 // release modes will have the TLS segment optimized out in our test-case.
57 if (optimize_mode == .Debug) {
58 check_lib.checkStart("Section data_count");
59 check_lib.checkNext("count 3");
60 }
46 // This section *must* be emit as the start function is set to the index
47 // of __wasm_init_memory
48 // release modes will have the TLS segment optimized out in our test-case.
49 // This means we won't have __wasm_init_memory in such case, and therefore
50 // should also not have a section "start"
51 if (optimize_mode == .Debug) {
52 check_lib.checkStart("Section start");
53 }
6154
62 check_lib.checkStart("Section custom");
63 check_lib.checkNext("name name");
64 check_lib.checkNext("type function");
65 if (optimize_mode == .Debug) {
66 check_lib.checkNext("name __wasm_init_memory");
67 }
68 check_lib.checkNext("name __wasm_init_tls");
69 check_lib.checkNext("type global");
55 // This section is only and *must* be emit when shared-memory is enabled
56 // release modes will have the TLS segment optimized out in our test-case.
57 if (optimize_mode == .Debug) {
58 check_lib.checkStart("Section data_count");
59 check_lib.checkNext("count 3");
60 }
7061
71 // In debug mode the symbol __tls_base is resolved to an undefined symbol
72 // from the object file, hence its placement differs than in release modes
73 // where the entire tls segment is optimized away, and tls_base will have
74 // its original position.
75 if (optimize_mode == .Debug) {
76 check_lib.checkNext("name __tls_size");
77 check_lib.checkNext("name __tls_align");
78 check_lib.checkNext("name __tls_base");
79 } else {
80 check_lib.checkNext("name __tls_base");
81 check_lib.checkNext("name __tls_size");
82 check_lib.checkNext("name __tls_align");
83 }
62 check_lib.checkStart("Section custom");
63 check_lib.checkNext("name name");
64 check_lib.checkNext("type function");
65 if (optimize_mode == .Debug) {
66 check_lib.checkNext("name __wasm_init_memory");
67 }
68 check_lib.checkNext("name __wasm_init_tls");
69 check_lib.checkNext("type global");
8470
85 check_lib.checkNext("type data_segment");
86 if (optimize_mode == .Debug) {
87 check_lib.checkNext("names 3");
88 check_lib.checkNext("index 0");
89 check_lib.checkNext("name .rodata");
90 check_lib.checkNext("index 1");
91 check_lib.checkNext("name .bss");
92 check_lib.checkNext("index 2");
93 check_lib.checkNext("name .tdata");
94 }
71 // In debug mode the symbol __tls_base is resolved to an undefined symbol
72 // from the object file, hence its placement differs than in release modes
73 // where the entire tls segment is optimized away, and tls_base will have
74 // its original position.
75 if (optimize_mode == .Debug) {
76 check_lib.checkNext("name __tls_size");
77 check_lib.checkNext("name __tls_align");
78 check_lib.checkNext("name __tls_base");
79 } else {
80 check_lib.checkNext("name __tls_base");
81 check_lib.checkNext("name __tls_size");
82 check_lib.checkNext("name __tls_align");
83 }
9584
96 test_step.dependOn(&check_lib.step);
85 check_lib.checkNext("type data_segment");
86 if (optimize_mode == .Debug) {
87 check_lib.checkNext("names 3");
88 check_lib.checkNext("index 0");
89 check_lib.checkNext("name .rodata");
90 check_lib.checkNext("index 1");
91 check_lib.checkNext("name .bss");
92 check_lib.checkNext("index 2");
93 check_lib.checkNext("name .tdata");
9794 }
95
96 test_step.dependOn(&check_lib.step);
9897}
test/link/wasm/stack_pointer/build.zig+2-1
......@@ -13,12 +13,13 @@ pub fn build(b: *std.Build) void {
1313}
1414
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const lib = b.addSharedLibrary(.{
16 const lib = b.addExecutable(.{
1717 .name = "lib",
1818 .root_source_file = .{ .path = "lib.zig" },
1919 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2020 .optimize = optimize,
2121 });
22 lib.no_entry = true;
2223 lib.use_llvm = false;
2324 lib.use_lld = false;
2425 lib.strip = false;
test/link/wasm/type/build.zig+2-1
......@@ -13,12 +13,13 @@ pub fn build(b: *std.Build) void {
1313}
1414
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const lib = b.addSharedLibrary(.{
16 const lib = b.addExecutable(.{
1717 .name = "lib",
1818 .root_source_file = .{ .path = "lib.zig" },
1919 .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
2020 .optimize = optimize,
2121 });
22 lib.no_entry = true;
2223 lib.use_llvm = false;
2324 lib.use_lld = false;
2425 lib.strip = false;