authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-24 22:48:55+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-24 22:48:55+02:00
logbc9ab3a613e809e5111eef0e3f78963c76fc2b3c
tree56ed3325b2b4367d25aeb405179ff57ec204030e
parentc9c210a4e74986a2bd1d0576d22ac9458d523d68

elf: test mismatched cpu architecture error


1 files changed, 31 insertions(+), 3 deletions(-)

test/link/elf.zig+31-3
......@@ -77,6 +77,7 @@ pub fn build(b: *Build) void {
7777 elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target }));
7878 elf_step.dependOn(testLdScript(b, .{ .target = glibc_target }));
7979 elf_step.dependOn(testLdScriptPathErrors(b, .{ .target = glibc_target }));
80 elf_step.dependOn(testMismatchedCpuArchitectureError(b, .{ .target = glibc_target }));
8081 // https://github.com/ziglang/zig/issues/17451
8182 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target }));
8283 elf_step.dependOn(testPie(b, .{ .target = glibc_target }));
......@@ -100,7 +101,7 @@ pub fn build(b: *Build) void {
100101 elf_step.dependOn(testTlsOffsetAlignment(b, .{ .target = glibc_target }));
101102 elf_step.dependOn(testTlsPic(b, .{ .target = glibc_target }));
102103 elf_step.dependOn(testTlsSmallAlignment(b, .{ .target = glibc_target }));
103 elf_step.dependOn(testUnresolved(b, .{ .target = glibc_target }));
104 elf_step.dependOn(testUnresolvedErrors(b, .{ .target = glibc_target }));
104105 elf_step.dependOn(testWeakExports(b, .{ .target = glibc_target }));
105106 elf_step.dependOn(testWeakUndefsDso(b, .{ .target = glibc_target }));
106107 elf_step.dependOn(testZNow(b, .{ .target = glibc_target }));
......@@ -1624,6 +1625,33 @@ fn testLdScriptPathErrors(b: *Build, opts: Options) *Step {
16241625 return test_step;
16251626}
16261627
1628fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step {
1629 const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts);
1630
1631 const obj = addObject(b, "a", .{
1632 .target = .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu },
1633 });
1634 addCSourceBytes(obj, "int foo;", &.{});
1635 obj.strip = true;
1636
1637 const exe = addExecutable(b, "main", opts);
1638 addCSourceBytes(exe,
1639 \\extern int foo;
1640 \\int main() {
1641 \\ return foo;
1642 \\}
1643 , &.{});
1644 exe.addObject(obj);
1645 exe.linkLibC();
1646
1647 expectLinkErrors(exe, test_step, &.{
1648 "invalid cpu architecture: expected 'x86_64', but found 'aarch64'",
1649 "note: while parsing /?/a.o",
1650 });
1651
1652 return test_step;
1653}
1654
16271655fn testLinkingC(b: *Build, opts: Options) *Step {
16281656 const test_step = addTestStep(b, "linking-c", opts);
16291657
......@@ -2806,8 +2834,8 @@ fn testTlsStatic(b: *Build, opts: Options) *Step {
28062834 return test_step;
28072835}
28082836
2809fn testUnresolved(b: *Build, opts: Options) *Step {
2810 const test_step = addTestStep(b, "unresolved", opts);
2837fn testUnresolvedErrors(b: *Build, opts: Options) *Step {
2838 const test_step = addTestStep(b, "unresolved-errors", opts);
28112839
28122840 const obj1 = addObject(b, "a", opts);
28132841 addCSourceBytes(obj1,