authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-24 23:11:50+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-24 23:11:50+02:00
log55c7a6d99d7897dec8562174803c1ad73f1d0b38
tree554159d7c1bdfc822cb2f53016e2662cde4b4731
parentbc9ab3a613e809e5111eef0e3f78963c76fc2b3c

elf: test unknown file type error


1 files changed, 35 insertions(+), 6 deletions(-)

test/link/elf.zig+35-6
......@@ -76,7 +76,7 @@ pub fn build(b: *Build) void {
7676 elf_step.dependOn(testLargeBss(b, .{ .target = glibc_target }));
7777 elf_step.dependOn(testLinkOrder(b, .{ .target = glibc_target }));
7878 elf_step.dependOn(testLdScript(b, .{ .target = glibc_target }));
79 elf_step.dependOn(testLdScriptPathErrors(b, .{ .target = glibc_target }));
79 elf_step.dependOn(testLdScriptPathError(b, .{ .target = glibc_target }));
8080 elf_step.dependOn(testMismatchedCpuArchitectureError(b, .{ .target = glibc_target }));
8181 // https://github.com/ziglang/zig/issues/17451
8282 // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = glibc_target }));
......@@ -101,7 +101,8 @@ pub fn build(b: *Build) void {
101101 elf_step.dependOn(testTlsOffsetAlignment(b, .{ .target = glibc_target }));
102102 elf_step.dependOn(testTlsPic(b, .{ .target = glibc_target }));
103103 elf_step.dependOn(testTlsSmallAlignment(b, .{ .target = glibc_target }));
104 elf_step.dependOn(testUnresolvedErrors(b, .{ .target = glibc_target }));
104 elf_step.dependOn(testUnknownFileTypeError(b, .{ .target = glibc_target }));
105 elf_step.dependOn(testUnresolvedError(b, .{ .target = glibc_target }));
105106 elf_step.dependOn(testWeakExports(b, .{ .target = glibc_target }));
106107 elf_step.dependOn(testWeakUndefsDso(b, .{ .target = glibc_target }));
107108 elf_step.dependOn(testZNow(b, .{ .target = glibc_target }));
......@@ -1604,8 +1605,8 @@ fn testLdScript(b: *Build, opts: Options) *Step {
16041605 return test_step;
16051606}
16061607
1607fn testLdScriptPathErrors(b: *Build, opts: Options) *Step {
1608 const test_step = addTestStep(b, "ld-script-path-errors", opts);
1608fn testLdScriptPathError(b: *Build, opts: Options) *Step {
1609 const test_step = addTestStep(b, "ld-script-path-error", opts);
16091610
16101611 const scripts = WriteFile.create(b);
16111612 _ = scripts.add("liba.so", "INPUT(libfoo.so)");
......@@ -2834,8 +2835,36 @@ fn testTlsStatic(b: *Build, opts: Options) *Step {
28342835 return test_step;
28352836}
28362837
2837fn testUnresolvedErrors(b: *Build, opts: Options) *Step {
2838 const test_step = addTestStep(b, "unresolved-errors", opts);
2838fn testUnknownFileTypeError(b: *Build, opts: Options) *Step {
2839 const test_step = addTestStep(b, "unknown-file-type-error", opts);
2840
2841 const dylib = addSharedLibrary(b, "a", .{
2842 .target = .{ .cpu_arch = .x86_64, .os_tag = .macos },
2843 });
2844 addZigSourceBytes(dylib, "export var foo: i32 = 0;");
2845
2846 const exe = addExecutable(b, "main", opts);
2847 addCSourceBytes(exe,
2848 \\extern int foo;
2849 \\int main() {
2850 \\ return foo;
2851 \\}
2852 , &.{});
2853 exe.linkLibrary(dylib);
2854 exe.linkLibC();
2855
2856 expectLinkErrors(exe, test_step, &.{
2857 "unknown file type",
2858 "note: while parsing /?/liba.dylib",
2859 "undefined symbol: foo",
2860 "note: referenced by /?/a.o:.text",
2861 });
2862
2863 return test_step;
2864}
2865
2866fn testUnresolvedError(b: *Build, opts: Options) *Step {
2867 const test_step = addTestStep(b, "unresolved-error", opts);
28392868
28402869 const obj1 = addObject(b, "a", opts);
28412870 addCSourceBytes(obj1,