commit bc9ab3a613e809e5111eef0e3f78963c76fc2b3c (tree)
parent c9c210a4e74986a2bd1d0576d22ac9458d523d68
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Tue, 24 Oct 2023 22:48:55 +0200
elf: test mismatched cpu architecture error
Diffstat:
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/test/link/elf.zig b/test/link/elf.zig
@@ -77,6 +77,7 @@ pub fn build(b: *Build) void {
elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target }));
elf_step.dependOn(testLdScript(b, .{ .target = glibc_target }));
elf_step.dependOn(testLdScriptPathErrors(b, .{ .target = glibc_target }));
+ elf_step.dependOn(testMismatchedCpuArchitectureError(b, .{ .target = glibc_target }));
// https://github.com/ziglang/zig/issues/17451
// elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target }));
elf_step.dependOn(testPie(b, .{ .target = glibc_target }));
@@ -100,7 +101,7 @@ pub fn build(b: *Build) void {
elf_step.dependOn(testTlsOffsetAlignment(b, .{ .target = glibc_target }));
elf_step.dependOn(testTlsPic(b, .{ .target = glibc_target }));
elf_step.dependOn(testTlsSmallAlignment(b, .{ .target = glibc_target }));
- elf_step.dependOn(testUnresolved(b, .{ .target = glibc_target }));
+ elf_step.dependOn(testUnresolvedErrors(b, .{ .target = glibc_target }));
elf_step.dependOn(testWeakExports(b, .{ .target = glibc_target }));
elf_step.dependOn(testWeakUndefsDso(b, .{ .target = glibc_target }));
elf_step.dependOn(testZNow(b, .{ .target = glibc_target }));
@@ -1624,6 +1625,33 @@ fn testLdScriptPathErrors(b: *Build, opts: Options) *Step {
return test_step;
}
+fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts);
+
+ const obj = addObject(b, "a", .{
+ .target = .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
+ });
+ addCSourceBytes(obj, "int foo;", &.{});
+ obj.strip = true;
+
+ const exe = addExecutable(b, "main", opts);
+ addCSourceBytes(exe,
+ \\extern int foo;
+ \\int main() {
+ \\ return foo;
+ \\}
+ , &.{});
+ exe.addObject(obj);
+ exe.linkLibC();
+
+ expectLinkErrors(exe, test_step, &.{
+ "invalid cpu architecture: expected 'x86_64', but found 'aarch64'",
+ "note: while parsing /?/a.o",
+ });
+
+ return test_step;
+}
+
fn testLinkingC(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "linking-c", opts);
@@ -2806,8 +2834,8 @@ fn testTlsStatic(b: *Build, opts: Options) *Step {
return test_step;
}
-fn testUnresolved(b: *Build, opts: Options) *Step {
- const test_step = addTestStep(b, "unresolved", opts);
+fn testUnresolvedErrors(b: *Build, opts: Options) *Step {
+ const test_step = addTestStep(b, "unresolved-errors", opts);
const obj1 = addObject(b, "a", opts);
addCSourceBytes(obj1,