elf: test linking against empty C object

This commit is contained in:
Jakub Konka 2023-09-25 19:50:12 +02:00
parent eb497c50e3
commit b01b972999

View File

@ -12,35 +12,27 @@ pub fn build(b: *Build) void {
.abi = .musl,
};
elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = true }));
// Exercise linker with self-hosted backend (no LLVM)
elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false }));
elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = true }));
// elf_step.dependOn(testLinkingC(b, .{ .target = musl_target, .use_llvm = false })); // TODO arocc
// Exercise linker with LLVM backend
elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target }));
elf_step.dependOn(testLinkingC(b, .{ .target = musl_target }));
elf_step.dependOn(testLinkingZig(b, .{}));
}
fn testLinkingZig(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "linking-zig-static", opts);
fn testEmptyObject(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "empty-object", opts);
const exe = addExecutable(b, opts);
addZigSourceBytes(exe,
\\pub fn main() void {
\\ @import("std").debug.print("Hello World!\n", .{});
\\}
);
addCSourceBytes(exe, "int main() { return 0; }");
addCSourceBytes(exe, "");
exe.is_linking_libc = true;
const run = b.addRunArtifact(exe);
run.expectStdErrEqual("Hello World!\n");
run.expectExitCode(0);
test_step.dependOn(&run.step);
const check = exe.checkObject();
check.checkStart();
check.checkExact("header");
check.checkExact("type EXEC");
check.checkStart();
check.checkExact("section headers");
check.checkNotPresent("name .dynamic");
test_step.dependOn(&check.step);
return test_step;
}
@ -73,6 +65,32 @@ fn testLinkingC(b: *Build, opts: Options) *Step {
return test_step;
}
fn testLinkingZig(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "linking-zig-static", opts);
const exe = addExecutable(b, opts);
addZigSourceBytes(exe,
\\pub fn main() void {
\\ @import("std").debug.print("Hello World!\n", .{});
\\}
);
const run = b.addRunArtifact(exe);
run.expectStdErrEqual("Hello World!\n");
test_step.dependOn(&run.step);
const check = exe.checkObject();
check.checkStart();
check.checkExact("header");
check.checkExact("type EXEC");
check.checkStart();
check.checkExact("section headers");
check.checkNotPresent("name .dynamic");
test_step.dependOn(&check.step);
return test_step;
}
const Options = struct {
target: CrossTarget = .{ .cpu_arch = .x86_64, .os_tag = .linux },
optimize: std.builtin.OptimizeMode = .Debug,