aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-11-05 18:44:12 -0500
committerGitHub <noreply@github.com>2023-11-05 18:44:12 -0500
commit702b809ea3e9b9dbdc1fd6efe9306442487e7103 (patch)
treebd639378ad2931013ff49789aadfc2104093261c /test
parentbec36aa7c028f2eaec94a2358f3e1326fcb9a30c (diff)
parentc893f837151d4764fd34911376836a01192b4d75 (diff)
downloadzig-702b809ea3e9b9dbdc1fd6efe9306442487e7103.tar.gz
zig-702b809ea3e9b9dbdc1fd6efe9306442487e7103.zip
Merge pull request #17815 from Luukdegram/wasm-no-entry
wasm-linker: implement `-fno-entry` and correctly pass `--shared` and `--pie` when given
Diffstat (limited to 'test')
-rw-r--r--test/link/elf.zig4
-rw-r--r--test/link/macho/entry/build.zig2
-rw-r--r--test/link/macho/entry_in_dylib/build.zig2
-rw-r--r--test/link/wasm/archive/build.zig3
-rw-r--r--test/link/wasm/basic-features/build.zig3
-rw-r--r--test/link/wasm/bss/build.zig6
-rw-r--r--test/link/wasm/export-data/build.zig3
-rw-r--r--test/link/wasm/export/build.zig9
-rw-r--r--test/link/wasm/extern-mangle/build.zig3
-rw-r--r--test/link/wasm/function-table/build.zig9
-rw-r--r--test/link/wasm/infer-features/build.zig3
-rw-r--r--test/link/wasm/producers/build.zig3
-rw-r--r--test/link/wasm/segments/build.zig3
-rw-r--r--test/link/wasm/shared-memory/build.zig149
-rw-r--r--test/link/wasm/stack_pointer/build.zig3
-rw-r--r--test/link/wasm/type/build.zig3
16 files changed, 112 insertions, 96 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig
index 75cc34ec32..0402637348 100644
--- a/test/link/elf.zig
+++ b/test/link/elf.zig
@@ -658,7 +658,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step {
const exe = addExecutable(b, "main", opts);
exe.addObject(a_o);
exe.addObject(b_o);
- exe.entry_symbol_name = "foo";
+ exe.entry = .{ .symbol_name = "foo" };
const check = exe.checkObject();
check.checkStart();
@@ -674,7 +674,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step {
const exe = addExecutable(b, "other", opts);
exe.addObject(a_o);
exe.addObject(b_o);
- exe.entry_symbol_name = "bar";
+ exe.entry = .{ .symbol_name = "bar" };
const check = exe.checkObject();
check.checkStart();
diff --git a/test/link/macho/entry/build.zig b/test/link/macho/entry/build.zig
index fcba02cd9a..9f493d2715 100644
--- a/test/link/macho/entry/build.zig
+++ b/test/link/macho/entry/build.zig
@@ -20,7 +20,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibC();
- exe.entry_symbol_name = "_non_main";
+ exe.entry = .{ .symbol_name = "_non_main" };
const check_exe = exe.checkObject();
diff --git a/test/link/macho/entry_in_dylib/build.zig b/test/link/macho/entry_in_dylib/build.zig
index 97ffa917b4..eb036abe6a 100644
--- a/test/link/macho/entry_in_dylib/build.zig
+++ b/test/link/macho/entry_in_dylib/build.zig
@@ -30,7 +30,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibrary(lib);
exe.linkLibC();
- exe.entry_symbol_name = "_bootstrap";
+ exe.entry = .{ .symbol_name = "_bootstrap" };
exe.forceUndefinedSymbol("_my_main");
const check_exe = exe.checkObject();
diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig
index d87b8e973e..3da284ac8f 100644
--- a/test/link/wasm/archive/build.zig
+++ b/test/link/wasm/archive/build.zig
@@ -15,12 +15,13 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
// The code in question will pull-in compiler-rt,
// and therefore link with its archive file.
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "main",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;
diff --git a/test/link/wasm/basic-features/build.zig b/test/link/wasm/basic-features/build.zig
index 703bd13feb..0566fbe2c1 100644
--- a/test/link/wasm/basic-features/build.zig
+++ b/test/link/wasm/basic-features/build.zig
@@ -4,7 +4,7 @@ pub const requires_stage2 = true;
pub fn build(b: *std.Build) void {
// Library with explicitly set cpu features
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "main.zig" },
.optimize = .Debug,
@@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void {
.os_tag = .freestanding,
},
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
diff --git a/test/link/wasm/bss/build.zig b/test/link/wasm/bss/build.zig
index e6cb9d4f3d..1bc059acde 100644
--- a/test/link/wasm/bss/build.zig
+++ b/test/link/wasm/bss/build.zig
@@ -14,12 +14,13 @@ pub fn build(b: *std.Build) void {
fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode, is_safe: bool) void {
{
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize_mode,
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;
@@ -60,12 +61,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
// verify zero'd declaration is stored in bss for all optimization modes.
{
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib2.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize_mode,
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;
diff --git a/test/link/wasm/export-data/build.zig b/test/link/wasm/export-data/build.zig
index 7e3128aa76..58a8795390 100644
--- a/test/link/wasm/export-data/build.zig
+++ b/test/link/wasm/export-data/build.zig
@@ -9,12 +9,13 @@ pub fn build(b: *std.Build) void {
return;
}
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.optimize = .ReleaseSafe, // to make the output deterministic in address positions
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
+ lib.entry = .disabled;
lib.use_lld = false;
lib.export_symbol_names = &.{ "foo", "bar" };
lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse
diff --git a/test/link/wasm/export/build.zig b/test/link/wasm/export/build.zig
index 5afe2df768..5c0306335d 100644
--- a/test/link/wasm/export/build.zig
+++ b/test/link/wasm/export/build.zig
@@ -13,31 +13,34 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const no_export = b.addSharedLibrary(.{
+ const no_export = b.addExecutable(.{
.name = "no-export",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
+ no_export.entry = .disabled;
no_export.use_llvm = false;
no_export.use_lld = false;
- const dynamic_export = b.addSharedLibrary(.{
+ const dynamic_export = b.addExecutable(.{
.name = "dynamic",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
+ dynamic_export.entry = .disabled;
dynamic_export.rdynamic = true;
dynamic_export.use_llvm = false;
dynamic_export.use_lld = false;
- const force_export = b.addSharedLibrary(.{
+ const force_export = b.addExecutable(.{
.name = "force",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
+ force_export.entry = .disabled;
force_export.export_symbol_names = &.{"foo"};
force_export.use_llvm = false;
force_export.use_lld = false;
diff --git a/test/link/wasm/extern-mangle/build.zig b/test/link/wasm/extern-mangle/build.zig
index 841d118efd..9f450c2dcc 100644
--- a/test/link/wasm/extern-mangle/build.zig
+++ b/test/link/wasm/extern-mangle/build.zig
@@ -11,12 +11,13 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ lib.entry = .disabled;
lib.import_symbols = true; // import `a` and `b`
lib.rdynamic = true; // export `foo`
diff --git a/test/link/wasm/function-table/build.zig b/test/link/wasm/function-table/build.zig
index 796ba670ad..906a255642 100644
--- a/test/link/wasm/function-table/build.zig
+++ b/test/link/wasm/function-table/build.zig
@@ -13,32 +13,35 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const import_table = b.addSharedLibrary(.{
+ const import_table = b.addExecutable(.{
.name = "import_table",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ import_table.entry = .disabled;
import_table.use_llvm = false;
import_table.use_lld = false;
import_table.import_table = true;
- const export_table = b.addSharedLibrary(.{
+ const export_table = b.addExecutable(.{
.name = "export_table",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ export_table.entry = .disabled;
export_table.use_llvm = false;
export_table.use_lld = false;
export_table.export_table = true;
- const regular_table = b.addSharedLibrary(.{
+ const regular_table = b.addExecutable(.{
.name = "regular_table",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ regular_table.entry = .disabled;
regular_table.use_llvm = false;
regular_table.use_lld = false;
diff --git a/test/link/wasm/infer-features/build.zig b/test/link/wasm/infer-features/build.zig
index 6264edfba9..5c7fa57447 100644
--- a/test/link/wasm/infer-features/build.zig
+++ b/test/link/wasm/infer-features/build.zig
@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
// Wasm library that doesn't have any features specified. This will
// infer its featureset from other linked object files.
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "main.zig" },
.optimize = .Debug,
@@ -27,6 +27,7 @@ pub fn build(b: *std.Build) void {
.os_tag = .freestanding,
},
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.addObject(c_obj);
diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig
index f541a1c8ec..e2bd95f450 100644
--- a/test/link/wasm/producers/build.zig
+++ b/test/link/wasm/producers/build.zig
@@ -14,12 +14,13 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;
diff --git a/test/link/wasm/segments/build.zig b/test/link/wasm/segments/build.zig
index d01c34f90d..21b954a902 100644
--- a/test/link/wasm/segments/build.zig
+++ b/test/link/wasm/segments/build.zig
@@ -13,12 +13,13 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;
diff --git a/test/link/wasm/shared-memory/build.zig b/test/link/wasm/shared-memory/build.zig
index cf84ad7528..a1d660d135 100644
--- a/test/link/wasm/shared-memory/build.zig
+++ b/test/link/wasm/shared-memory/build.zig
@@ -11,88 +11,87 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {
- {
- const lib = b.addSharedLibrary(.{
- .name = "lib",
- .root_source_file = .{ .path = "lib.zig" },
- .target = .{
- .cpu_arch = .wasm32,
- .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
- .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
- .os_tag = .freestanding,
- },
- .optimize = optimize_mode,
- });
- lib.use_lld = false;
- lib.strip = false;
- lib.import_memory = true;
- lib.export_memory = true;
- lib.shared_memory = true;
- lib.max_memory = 67108864;
- lib.single_threaded = false;
- lib.export_symbol_names = &.{"foo"};
+ const lib = b.addExecutable(.{
+ .name = "lib",
+ .root_source_file = .{ .path = "lib.zig" },
+ .target = .{
+ .cpu_arch = .wasm32,
+ .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
+ .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
+ .os_tag = .freestanding,
+ },
+ .optimize = optimize_mode,
+ });
+ lib.entry = .disabled;
+ lib.use_lld = false;
+ lib.strip = false;
+ lib.import_memory = true;
+ lib.export_memory = true;
+ lib.shared_memory = true;
+ lib.max_memory = 67108864;
+ lib.single_threaded = false;
+ lib.export_symbol_names = &.{"foo"};
- const check_lib = lib.checkObject();
+ const check_lib = lib.checkObject();
- check_lib.checkStart("Section import");
- check_lib.checkNext("entries 1");
- check_lib.checkNext("module env");
- check_lib.checkNext("name memory"); // ensure we are importing memory
+ check_lib.checkStart("Section import");
+ check_lib.checkNext("entries 1");
+ check_lib.checkNext("module env");
+ check_lib.checkNext("name memory"); // ensure we are importing memory
- check_lib.checkStart("Section export");
- check_lib.checkNext("entries 2");
- check_lib.checkNext("name memory"); // ensure we also export memory again
+ check_lib.checkStart("Section export");
+ check_lib.checkNext("entries 2");
+ check_lib.checkNext("name memory"); // ensure we also export memory again
- // This section *must* be emit as the start function is set to the index
- // of __wasm_init_memory
- // release modes will have the TLS segment optimized out in our test-case.
- // This means we won't have __wasm_init_memory in such case, and therefore
- // should also not have a section "start"
- if (optimize_mode == .Debug) {
- check_lib.checkStart("Section start");
- }
-
- // This section is only and *must* be emit when shared-memory is enabled
- // release modes will have the TLS segment optimized out in our test-case.
- if (optimize_mode == .Debug) {
- check_lib.checkStart("Section data_count");
- check_lib.checkNext("count 3");
- }
+ // This section *must* be emit as the start function is set to the index
+ // of __wasm_init_memory
+ // release modes will have the TLS segment optimized out in our test-case.
+ // This means we won't have __wasm_init_memory in such case, and therefore
+ // should also not have a section "start"
+ if (optimize_mode == .Debug) {
+ check_lib.checkStart("Section start");
+ }
- check_lib.checkStart("Section custom");
- check_lib.checkNext("name name");
- check_lib.checkNext("type function");
- if (optimize_mode == .Debug) {
- check_lib.checkNext("name __wasm_init_memory");
- }
- check_lib.checkNext("name __wasm_init_tls");
- check_lib.checkNext("type global");
+ // This section is only and *must* be emit when shared-memory is enabled
+ // release modes will have the TLS segment optimized out in our test-case.
+ if (optimize_mode == .Debug) {
+ check_lib.checkStart("Section data_count");
+ check_lib.checkNext("count 3");
+ }
- // In debug mode the symbol __tls_base is resolved to an undefined symbol
- // from the object file, hence its placement differs than in release modes
- // where the entire tls segment is optimized away, and tls_base will have
- // its original position.
- if (optimize_mode == .Debug) {
- check_lib.checkNext("name __tls_size");
- check_lib.checkNext("name __tls_align");
- check_lib.checkNext("name __tls_base");
- } else {
- check_lib.checkNext("name __tls_base");
- check_lib.checkNext("name __tls_size");
- check_lib.checkNext("name __tls_align");
- }
+ check_lib.checkStart("Section custom");
+ check_lib.checkNext("name name");
+ check_lib.checkNext("type function");
+ if (optimize_mode == .Debug) {
+ check_lib.checkNext("name __wasm_init_memory");
+ }
+ check_lib.checkNext("name __wasm_init_tls");
+ check_lib.checkNext("type global");
- check_lib.checkNext("type data_segment");
- if (optimize_mode == .Debug) {
- check_lib.checkNext("names 3");
- check_lib.checkNext("index 0");
- check_lib.checkNext("name .rodata");
- check_lib.checkNext("index 1");
- check_lib.checkNext("name .bss");
- check_lib.checkNext("index 2");
- check_lib.checkNext("name .tdata");
- }
+ // In debug mode the symbol __tls_base is resolved to an undefined symbol
+ // from the object file, hence its placement differs than in release modes
+ // where the entire tls segment is optimized away, and tls_base will have
+ // its original position.
+ if (optimize_mode == .Debug) {
+ check_lib.checkNext("name __tls_size");
+ check_lib.checkNext("name __tls_align");
+ check_lib.checkNext("name __tls_base");
+ } else {
+ check_lib.checkNext("name __tls_base");
+ check_lib.checkNext("name __tls_size");
+ check_lib.checkNext("name __tls_align");
+ }
- test_step.dependOn(&check_lib.step);
+ check_lib.checkNext("type data_segment");
+ if (optimize_mode == .Debug) {
+ check_lib.checkNext("names 3");
+ check_lib.checkNext("index 0");
+ check_lib.checkNext("name .rodata");
+ check_lib.checkNext("index 1");
+ check_lib.checkNext("name .bss");
+ check_lib.checkNext("index 2");
+ check_lib.checkNext("name .tdata");
}
+
+ test_step.dependOn(&check_lib.step);
}
diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig
index ce724e5736..00ef54c052 100644
--- a/test/link/wasm/stack_pointer/build.zig
+++ b/test/link/wasm/stack_pointer/build.zig
@@ -13,12 +13,13 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;
diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig
index 7110f465f4..de574e36e4 100644
--- a/test/link/wasm/type/build.zig
+++ b/test/link/wasm/type/build.zig
@@ -13,12 +13,13 @@ pub fn build(b: *std.Build) void {
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
- const lib = b.addSharedLibrary(.{
+ const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
.optimize = optimize,
});
+ lib.entry = .disabled;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;