authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-24 22:07:07+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-24 22:08:36+02:00
log403e539669deae8d4aeb11baa5f30aad5dfe6589
tree82cd8f613eb8452a8ca1c053fcfbb966f2f11915
parent89563f07e3956a44e37eb59e618d926bd401055c

elf: test unresolved symbol reference error


1 files changed, 45 insertions(+), 0 deletions(-)

test/link/elf.zig+45
......@@ -99,6 +99,7 @@ pub fn build(b: *Build) void {
9999 elf_step.dependOn(testTlsOffsetAlignment(b, .{ .target = glibc_target }));
100100 elf_step.dependOn(testTlsPic(b, .{ .target = glibc_target }));
101101 elf_step.dependOn(testTlsSmallAlignment(b, .{ .target = glibc_target }));
102 elf_step.dependOn(testUnresolved(b, .{ .target = glibc_target }));
102103 elf_step.dependOn(testWeakExports(b, .{ .target = glibc_target }));
103104 elf_step.dependOn(testWeakUndefsDso(b, .{ .target = glibc_target }));
104105 elf_step.dependOn(testZNow(b, .{ .target = glibc_target }));
......@@ -2783,6 +2784,44 @@ fn testTlsStatic(b: *Build, opts: Options) *Step {
27832784 return test_step;
27842785}
27852786
2787fn testUnresolved(b: *Build, opts: Options) *Step {
2788 const test_step = addTestStep(b, "unresolved", opts);
2789
2790 const obj1 = addObject(b, "a", opts);
2791 addCSourceBytes(obj1,
2792 \\#include <stdio.h>
2793 \\int foo();
2794 \\int bar() {
2795 \\ return foo() + 1;
2796 \\}
2797 , &.{"-ffunction-sections"});
2798 obj1.linkLibC();
2799
2800 const obj2 = addObject(b, "b", opts);
2801 addCSourceBytes(obj2,
2802 \\#include <stdio.h>
2803 \\int foo();
2804 \\int bar();
2805 \\int main() {
2806 \\ return foo() + bar();
2807 \\}
2808 , &.{"-ffunction-sections"});
2809 obj2.linkLibC();
2810
2811 const exe = addExecutable(b, "main", opts);
2812 exe.addObject(obj1);
2813 exe.addObject(obj2);
2814 exe.linkLibC();
2815
2816 expectLinkErrors(exe, test_step, &.{
2817 "error: undefined symbol: foo",
2818 "note: referenced by /?/a.o:.text.bar",
2819 "note: referenced by /?/b.o:.text.main",
2820 });
2821
2822 return test_step;
2823}
2824
27862825fn testWeakExports(b: *Build, opts: Options) *Step {
27872826 const test_step = addTestStep(b, "weak-exports", opts);
27882827
......@@ -3081,6 +3120,12 @@ fn addAsmSourceBytes(comp: *Compile, bytes: []const u8) void {
30813120 comp.addAssemblyFile(file);
30823121}
30833122
3123fn expectLinkErrors(comp: *Compile, test_step: *Step, expected_errors: []const []const u8) void {
3124 comp.expect_errors = expected_errors;
3125 const bin_file = comp.getEmittedBin();
3126 bin_file.addStepDependencies(test_step);
3127}
3128
30843129const std = @import("std");
30853130
30863131const Build = std.Build;