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.
This commit is contained in:
Luuk de Gram 2023-09-01 16:37:07 +02:00
parent 58618afaee
commit 938f9dea37
No known key found for this signature in database
GPG key ID: A8CFE58E4DC7D664
14 changed files with 117 additions and 97 deletions

View file

@ -1853,7 +1853,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
if (self.global_base) |global_base| {
try zig_args.append(b.fmt("--global-base={d}", .{global_base}));
}
try addFlag(&zig_args, "entry", self.no_entry);
// invert the value due to naming so when `no_entry` is set to 'true'
// we actually emit the flag `-fno_entry`.
if (self.no_entry) |no_entry| {
try addFlag(&zig_args, "entry", !no_entry);
}
if (self.code_model != .default) {
try zig_args.append("-mcmodel");

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;

View file

@ -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.no_entry = true;
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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;

View file

@ -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.no_entry = true;
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

View file

@ -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.no_entry = true;
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.no_entry = true;
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.no_entry = true;
force_export.export_symbol_names = &.{"foo"};
force_export.use_llvm = false;
force_export.use_lld = false;

View file

@ -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.no_entry = true;
lib.import_symbols = true; // import `a` and `b`
lib.rdynamic = true; // export `foo`

View file

@ -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.no_entry = true;
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.no_entry = true;
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.no_entry = true;
regular_table.use_llvm = false;
regular_table.use_lld = false;

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.addObject(c_obj);

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;

View file

@ -11,8 +11,7 @@ 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(.{
const lib = b.addExecutable(.{
.name = "lib",
.root_source_file = .{ .path = "lib.zig" },
.target = .{
@ -23,6 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
},
.optimize = optimize_mode,
});
lib.no_entry = true;
lib.use_lld = false;
lib.strip = false;
lib.import_memory = true;
@ -95,4 +95,3 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
test_step.dependOn(&check_lib.step);
}
}

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;

View file

@ -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.no_entry = true;
lib.use_llvm = false;
lib.use_lld = false;
lib.strip = false;