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 {...@@ -77,6 +77,7 @@ pub fn build(b: *Build) void {
77 elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target }));77 elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target }));
78 elf_step.dependOn(testLdScript(b, .{ .target = glibc_target }));78 elf_step.dependOn(testLdScript(b, .{ .target = glibc_target }));
79 elf_step.dependOn(testLdScriptPathErrors(b, .{ .target = glibc_target }));79 elf_step.dependOn(testLdScriptPathErrors(b, .{ .target = glibc_target }));
80 elf_step.dependOn(testMismatchedCpuArchitectureError(b, .{ .target = glibc_target }));
80 // https://github.com/ziglang/zig/issues/1745181 // https://github.com/ziglang/zig/issues/17451
81 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target }));82 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target }));
82 elf_step.dependOn(testPie(b, .{ .target = glibc_target }));83 elf_step.dependOn(testPie(b, .{ .target = glibc_target }));
...@@ -100,7 +101,7 @@ pub fn build(b: *Build) void {...@@ -100,7 +101,7 @@ pub fn build(b: *Build) void {
100 elf_step.dependOn(testTlsOffsetAlignment(b, .{ .target = glibc_target }));101 elf_step.dependOn(testTlsOffsetAlignment(b, .{ .target = glibc_target }));
101 elf_step.dependOn(testTlsPic(b, .{ .target = glibc_target }));102 elf_step.dependOn(testTlsPic(b, .{ .target = glibc_target }));
102 elf_step.dependOn(testTlsSmallAlignment(b, .{ .target = glibc_target }));103 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 }));
104 elf_step.dependOn(testWeakExports(b, .{ .target = glibc_target }));105 elf_step.dependOn(testWeakExports(b, .{ .target = glibc_target }));
105 elf_step.dependOn(testWeakUndefsDso(b, .{ .target = glibc_target }));106 elf_step.dependOn(testWeakUndefsDso(b, .{ .target = glibc_target }));
106 elf_step.dependOn(testZNow(b, .{ .target = glibc_target }));107 elf_step.dependOn(testZNow(b, .{ .target = glibc_target }));
...@@ -1624,6 +1625,33 @@ fn testLdScriptPathErrors(b: *Build, opts: Options) *Step {...@@ -1624,6 +1625,33 @@ fn testLdScriptPathErrors(b: *Build, opts: Options) *Step {
1624 return test_step;1625 return test_step;
1625}1626}
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
1627fn testLinkingC(b: *Build, opts: Options) *Step {1655fn testLinkingC(b: *Build, opts: Options) *Step {
1628 const test_step = addTestStep(b, "linking-c", opts);1656 const test_step = addTestStep(b, "linking-c", opts);
16291657
...@@ -2806,8 +2834,8 @@ fn testTlsStatic(b: *Build, opts: Options) *Step {...@@ -2806,8 +2834,8 @@ fn testTlsStatic(b: *Build, opts: Options) *Step {
2806 return test_step;2834 return test_step;
2807}2835}
28082836
2809fn testUnresolved(b: *Build, opts: Options) *Step {2837fn testUnresolvedErrors(b: *Build, opts: Options) *Step {
2810 const test_step = addTestStep(b, "unresolved", opts);2838 const test_step = addTestStep(b, "unresolved-errors", opts);
28112839
2812 const obj1 = addObject(b, "a", opts);2840 const obj1 = addObject(b, "a", opts);
2813 addCSourceBytes(obj1,2841 addCSourceBytes(obj1,