authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-09 20:13:16+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:05+02:00
log898c87bd2ab7d49fbbcb1d01e6b72fec54bdfd09
treebcbec740dd475218a58e01e6905d521e8d13c782
parent1fe0fd69e059e19586290a450c2a48f9777cd4d4

elf: port more linker tests


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

test/link/elf.zig+63
...@@ -77,6 +77,7 @@ pub fn build(b: *Build) void {...@@ -77,6 +77,7 @@ pub fn build(b: *Build) void {
77 elf_step.dependOn(testPie(b, .{ .target = glibc_target }));77 elf_step.dependOn(testPie(b, .{ .target = glibc_target }));
78 elf_step.dependOn(testPltGot(b, .{ .target = glibc_target }));78 elf_step.dependOn(testPltGot(b, .{ .target = glibc_target }));
79 elf_step.dependOn(testPreinitArray(b, .{ .target = glibc_target }));79 elf_step.dependOn(testPreinitArray(b, .{ .target = glibc_target }));
80 elf_step.dependOn(testSharedAbsSymbol(b, .{ .target = glibc_target }));
80}81}
8182
82fn testAbsSymbols(b: *Build, opts: Options) *Step {83fn testAbsSymbols(b: *Build, opts: Options) *Step {
...@@ -1642,6 +1643,68 @@ fn testPreinitArray(b: *Build, opts: Options) *Step {...@@ -1642,6 +1643,68 @@ fn testPreinitArray(b: *Build, opts: Options) *Step {
1642 return test_step;1643 return test_step;
1643}1644}
16441645
1646fn testSharedAbsSymbol(b: *Build, opts: Options) *Step {
1647 const test_step = addTestStep(b, "shared-abs-symbol", opts);
1648
1649 const dso = addSharedLibrary(b, "a", opts);
1650 addAsmSourceBytes(dso,
1651 \\.globl foo
1652 \\foo = 3;
1653 );
1654
1655 const obj = addObject(b, "obj", opts);
1656 addCSourceBytes(obj,
1657 \\#include <stdio.h>
1658 \\extern char foo;
1659 \\int main() { printf("foo=%p\n", &foo); }
1660 , &.{});
1661 obj.force_pic = true;
1662 obj.linkLibC();
1663
1664 {
1665 const exe = addExecutable(b, "main1", opts);
1666 exe.addObject(obj);
1667 exe.linkLibrary(dso);
1668 exe.pie = true;
1669
1670 const run = addRunArtifact(exe);
1671 run.expectStdOutEqual("foo=0x3\n");
1672 test_step.dependOn(&run.step);
1673
1674 const check = exe.checkObject();
1675 check.checkStart();
1676 check.checkExact("header");
1677 check.checkExact("type DYN");
1678 // TODO fix/improve in CheckObject
1679 // check.checkInSymtab();
1680 // check.checkNotPresent("foo");
1681 test_step.dependOn(&check.step);
1682 }
1683
1684 // https://github.com/ziglang/zig/issues/17430
1685 // {
1686 // const exe = addExecutable(b, "main2", opts);
1687 // exe.addObject(obj);
1688 // exe.linkLibrary(dso);
1689 // exe.pie = false;
1690
1691 // const run = addRunArtifact(exe);
1692 // run.expectStdOutEqual("foo=0x3\n");
1693 // test_step.dependOn(&run.step);
1694
1695 // const check = exe.checkObject();
1696 // check.checkStart();
1697 // check.checkExact("header");
1698 // check.checkExact("type EXEC");
1699 // // TODO fix/improve in CheckObject
1700 // // check.checkInSymtab();
1701 // // check.checkNotPresent("foo");
1702 // test_step.dependOn(&check.step);
1703 // }
1704
1705 return test_step;
1706}
1707
1645fn testTlsStatic(b: *Build, opts: Options) *Step {1708fn testTlsStatic(b: *Build, opts: Options) *Step {
1646 const test_step = addTestStep(b, "tls-static", opts);1709 const test_step = addTestStep(b, "tls-static", opts);
16471710