diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-04 13:06:26 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-16 19:33:04 +0200 |
| commit | f1b9c365f2bcf4e2e00e221d34f43bb343367c4d (patch) | |
| tree | 5c5706e7d80f7dfc88c38e0df6fd11a2d9e33708 /test | |
| parent | 976d4f51ccae088044ac90a89c3840db94f4ceb2 (diff) | |
| download | zig-f1b9c365f2bcf4e2e00e221d34f43bb343367c4d.tar.gz zig-f1b9c365f2bcf4e2e00e221d34f43bb343367c4d.zip | |
elf: add incomplete handling of build-obj -fllvm -fno-lld
Diffstat (limited to 'test')
| -rw-r--r-- | test/link/elf.zig | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/test/link/elf.zig b/test/link/elf.zig index 8b70249ad8..6c8e03a21c 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -17,6 +17,7 @@ pub fn build(b: *Build) void { // Exercise linker with LLVM backend elf_step.dependOn(testEmptyObject(b, .{ .target = musl_target })); + elf_step.dependOn(testGcSections(b, .{ .target = musl_target })); elf_step.dependOn(testLinkingC(b, .{ .target = musl_target })); elf_step.dependOn(testLinkingCpp(b, .{ .target = musl_target })); elf_step.dependOn(testLinkingZig(b, .{ .target = musl_target })); @@ -38,6 +39,93 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { return test_step; } +fn testGcSections(b: *Build, opts: Options) *Step { + const test_step = addTestStep(b, "gc-sections", opts); + + const obj = addObject(b, opts); + addCppSourceBytes(obj, + \\#include <stdio.h> + \\int two() { return 2; } + \\int live_var1 = 1; + \\int live_var2 = two(); + \\int dead_var1 = 3; + \\int dead_var2 = 4; + \\void live_fn1() {} + \\void live_fn2() { live_fn1(); } + \\void dead_fn1() {} + \\void dead_fn2() { dead_fn1(); } + \\int main() { + \\ printf("%d %d\n", live_var1, live_var2); + \\ live_fn2(); + \\} + ); + obj.link_function_sections = true; + obj.is_linking_libc = true; + obj.is_linking_libcpp = true; + + { + const exe = addExecutable(b, opts); + exe.addObject(obj); + exe.link_gc_sections = false; + exe.is_linking_libc = true; + exe.is_linking_libcpp = true; + + const run = addRunArtifact(exe); + run.expectStdOutEqual("1 2\n"); + test_step.dependOn(&run.step); + + const check = exe.checkObject(); + check.checkInSymtab(); + check.checkContains("live_var1"); + check.checkInSymtab(); + check.checkContains("live_var2"); + check.checkInSymtab(); + check.checkContains("dead_var1"); + check.checkInSymtab(); + check.checkContains("dead_var2"); + check.checkInSymtab(); + check.checkContains("live_fn1"); + check.checkInSymtab(); + check.checkContains("live_fn2"); + check.checkInSymtab(); + check.checkContains("dead_fn1"); + check.checkInSymtab(); + check.checkContains("dead_fn2"); + test_step.dependOn(&check.step); + } + + // { + // const exe = cc(b, opts); + // exe.addFileSource(obj_out.file); + // exe.addArg("-Wl,-gc-sections"); + + // const run = exe.run(); + // run.expectStdOutEqual("1 2\n"); + // test_step.dependOn(run.step()); + + // const check = exe.check(); + // check.checkInSymtab(); + // check.checkContains("live_var1"); + // check.checkInSymtab(); + // check.checkContains("live_var2"); + // check.checkInSymtab(); + // check.checkNotPresent("dead_var1"); + // check.checkInSymtab(); + // check.checkNotPresent("dead_var2"); + // check.checkInSymtab(); + // check.checkContains("live_fn1"); + // check.checkInSymtab(); + // check.checkContains("live_fn2"); + // check.checkInSymtab(); + // check.checkNotPresent("dead_fn1"); + // check.checkInSymtab(); + // check.checkNotPresent("dead_fn2"); + // test_step.dependOn(&check.step); + // } + + return test_step; +} + fn testLinkingC(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "linking-c", opts); @@ -182,6 +270,16 @@ fn addExecutable(b: *Build, opts: Options) *Compile { }); } +fn addObject(b: *Build, opts: Options) *Compile { + return b.addObject(.{ + .name = "a.o", + .target = opts.target, + .optimize = opts.optimize, + .use_llvm = opts.use_llvm, + .use_lld = false, + }); +} + fn addRunArtifact(comp: *Compile) *Run { const b = comp.step.owner; const run = b.addRunArtifact(comp); |
