authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-16 16:11:24+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-16 16:11:24+01:00
logb1730880894493d7cd9b1b7bc06e49c9120ca7b6
tree3beae3a691e12a88e1081884ccccaf1237e11de6
parent941090d94f6b6c7c5207f06917743e79ff06426f
parent85c0485fd9ccc89dae97a8fed6d503b0e8c9e519
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #18015 from ziglang/elf-tests

More ELF tests

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

test/link/elf.zig+79
...@@ -23,7 +23,9 @@ pub fn testAll(b: *Build) *Step {...@@ -23,7 +23,9 @@ pub fn testAll(b: *Build) *Step {
23 // Exercise linker in -r mode23 // Exercise linker in -r mode
24 elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target }));24 elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target }));
25 elf_step.dependOn(testEmitRelocatable(b, .{ .target = musl_target }));25 elf_step.dependOn(testEmitRelocatable(b, .{ .target = musl_target }));
26 elf_step.dependOn(testRelocatableArchive(b, .{ .target = musl_target }));
26 elf_step.dependOn(testRelocatableEhFrame(b, .{ .target = musl_target }));27 elf_step.dependOn(testRelocatableEhFrame(b, .{ .target = musl_target }));
28 elf_step.dependOn(testRelocatableNoEhFrame(b, .{ .target = musl_target }));
2729
28 // Exercise linker in ar mode30 // Exercise linker in ar mode
29 elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target }));31 elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target }));
...@@ -2141,6 +2143,56 @@ fn testPreinitArray(b: *Build, opts: Options) *Step {...@@ -2141,6 +2143,56 @@ fn testPreinitArray(b: *Build, opts: Options) *Step {
2141 return test_step;2143 return test_step;
2142}2144}
21432145
2146fn testRelocatableArchive(b: *Build, opts: Options) *Step {
2147 const test_step = addTestStep(b, "relocatable-archive", opts);
2148
2149 const obj1 = addObject(b, "obj1", opts);
2150 addCSourceBytes(obj1,
2151 \\void bar();
2152 \\void foo() {
2153 \\ bar();
2154 \\}
2155 , &.{});
2156
2157 const obj2 = addObject(b, "obj2", opts);
2158 addCSourceBytes(obj2,
2159 \\void bar() {}
2160 , &.{});
2161
2162 const obj3 = addObject(b, "obj3", opts);
2163 addCSourceBytes(obj3,
2164 \\void baz();
2165 , &.{});
2166
2167 const obj4 = addObject(b, "obj4", opts);
2168 addCSourceBytes(obj4,
2169 \\void foo();
2170 \\int main() {
2171 \\ foo();
2172 \\}
2173 , &.{});
2174
2175 const lib = addStaticLibrary(b, "lib", opts);
2176 lib.addObject(obj1);
2177 lib.addObject(obj2);
2178 lib.addObject(obj3);
2179
2180 const obj5 = addObject(b, "obj5", opts);
2181 obj5.addObject(obj4);
2182 obj5.linkLibrary(lib);
2183
2184 const check = obj5.checkObject();
2185 check.checkInSymtab();
2186 check.checkContains("foo");
2187 check.checkInSymtab();
2188 check.checkContains("bar");
2189 check.checkInSymtab();
2190 check.checkNotPresent("baz");
2191 test_step.dependOn(&check.step);
2192
2193 return test_step;
2194}
2195
2144fn testRelocatableEhFrame(b: *Build, opts: Options) *Step {2196fn testRelocatableEhFrame(b: *Build, opts: Options) *Step {
2145 const test_step = addTestStep(b, "relocatable-eh-frame", opts);2197 const test_step = addTestStep(b, "relocatable-eh-frame", opts);
21462198
...@@ -2224,6 +2276,33 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step {...@@ -2224,6 +2276,33 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step {
2224 return test_step;2276 return test_step;
2225}2277}
22262278
2279fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step {
2280 const test_step = addTestStep(b, "relocatable-no-eh-frame", opts);
2281
2282 const obj1 = addObject(b, "obj1", opts);
2283 addCSourceBytes(obj1, "int bar() { return 42; }", &.{
2284 "-fno-unwind-tables",
2285 "-fno-asynchronous-unwind-tables",
2286 });
2287
2288 const obj2 = addObject(b, "obj2", opts);
2289 obj2.addObject(obj1);
2290
2291 const check1 = obj1.checkObject();
2292 check1.checkStart();
2293 check1.checkExact("section headers");
2294 check1.checkNotPresent(".eh_frame");
2295 test_step.dependOn(&check1.step);
2296
2297 const check2 = obj2.checkObject();
2298 check2.checkStart();
2299 check2.checkExact("section headers");
2300 check2.checkNotPresent(".eh_frame");
2301 test_step.dependOn(&check2.step);
2302
2303 return test_step;
2304}
2305
2227fn testSharedAbsSymbol(b: *Build, opts: Options) *Step {2306fn testSharedAbsSymbol(b: *Build, opts: Options) *Step {
2228 const test_step = addTestStep(b, "shared-abs-symbol", opts);2307 const test_step = addTestStep(b, "shared-abs-symbol", opts);
22292308