| ... | @@ -39,6 +39,7 @@ pub fn build(b: *Build) void { | ... | @@ -39,6 +39,7 @@ pub fn build(b: *Build) void { |
| 39 | // https://github.com/ziglang/zig/issues/17451 | 39 | // https://github.com/ziglang/zig/issues/17451 |
| 40 | // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = musl_target })); | 40 | // elf_step.dependOn(testNoEhFrameHdr(b, .{ .target = musl_target })); |
| 41 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); | 41 | elf_step.dependOn(testTlsStatic(b, .{ .target = musl_target })); |
| | 42 | elf_step.dependOn(testStrip(b, .{ .target = musl_target })); |
| 42 | | 43 | |
| 43 | // glibc tests | 44 | // glibc tests |
| 44 | elf_step.dependOn(testAsNeeded(b, .{ .target = glibc_target })); | 45 | elf_step.dependOn(testAsNeeded(b, .{ .target = glibc_target })); |
| ... | @@ -78,6 +79,9 @@ pub fn build(b: *Build) void { | ... | @@ -78,6 +79,9 @@ pub fn build(b: *Build) void { |
| 78 | elf_step.dependOn(testPltGot(b, .{ .target = glibc_target })); | 79 | elf_step.dependOn(testPltGot(b, .{ .target = glibc_target })); |
| 79 | elf_step.dependOn(testPreinitArray(b, .{ .target = glibc_target })); | 80 | elf_step.dependOn(testPreinitArray(b, .{ .target = glibc_target })); |
| 80 | elf_step.dependOn(testSharedAbsSymbol(b, .{ .target = glibc_target })); | 81 | elf_step.dependOn(testSharedAbsSymbol(b, .{ .target = glibc_target })); |
| | 82 | elf_step.dependOn(testTlsDfStaticTls(b, .{ .target = glibc_target })); |
| | 83 | elf_step.dependOn(testTlsDso(b, .{ .target = glibc_target })); |
| | 84 | elf_step.dependOn(testTlsGd(b, .{ .target = glibc_target })); |
| 81 | } | 85 | } |
| 82 | | 86 | |
| 83 | fn testAbsSymbols(b: *Build, opts: Options) *Step { | 87 | fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| ... | @@ -1417,7 +1421,6 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { | ... | @@ -1417,7 +1421,6 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1417 | // exe.addLibraryPath(lib.getEmittedBinDirectory()); | 1421 | // exe.addLibraryPath(lib.getEmittedBinDirectory()); |
| 1418 | // exe.addRPath(lib.getEmittedBinDirectory()); | 1422 | // exe.addRPath(lib.getEmittedBinDirectory()); |
| 1419 | // exe.linkLibC(); | 1423 | // exe.linkLibC(); |
| 1420 | // exe.verbose_link = true; | | |
| 1421 | | 1424 | |
| 1422 | // const check = exe.checkObject(); | 1425 | // const check = exe.checkObject(); |
| 1423 | // check.checkInDynamicSection(); | 1426 | // check.checkInDynamicSection(); |
| ... | @@ -1435,7 +1438,6 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { | ... | @@ -1435,7 +1438,6 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1435 | exe.addLibraryPath(dso.getEmittedBinDirectory()); | 1438 | exe.addLibraryPath(dso.getEmittedBinDirectory()); |
| 1436 | exe.addRPath(dso.getEmittedBinDirectory()); | 1439 | exe.addRPath(dso.getEmittedBinDirectory()); |
| 1437 | exe.linkLibC(); | 1440 | exe.linkLibC(); |
| 1438 | exe.verbose_link = true; | | |
| 1439 | | 1441 | |
| 1440 | const check = exe.checkObject(); | 1442 | const check = exe.checkObject(); |
| 1441 | check.checkInDynamicSection(); | 1443 | check.checkInDynamicSection(); |
| ... | @@ -1705,6 +1707,223 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { | ... | @@ -1705,6 +1707,223 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 1705 | return test_step; | 1707 | return test_step; |
| 1706 | } | 1708 | } |
| 1707 | | 1709 | |
| | 1710 | fn testStrip(b: *Build, opts: Options) *Step { |
| | 1711 | const test_step = addTestStep(b, "strip", opts); |
| | 1712 | |
| | 1713 | const obj = addObject(b, "obj", opts); |
| | 1714 | addCSourceBytes(obj, |
| | 1715 | \\#include <stdio.h> |
| | 1716 | \\int main() { |
| | 1717 | \\ printf("Hello!\n"); |
| | 1718 | \\ return 0; |
| | 1719 | \\} |
| | 1720 | , &.{}); |
| | 1721 | obj.linkLibC(); |
| | 1722 | |
| | 1723 | { |
| | 1724 | const exe = addExecutable(b, "main1", opts); |
| | 1725 | exe.addObject(obj); |
| | 1726 | exe.strip = false; |
| | 1727 | exe.linkLibC(); |
| | 1728 | |
| | 1729 | const check = exe.checkObject(); |
| | 1730 | check.checkStart(); |
| | 1731 | check.checkExact("section headers"); |
| | 1732 | check.checkExact("name .debug_info"); |
| | 1733 | test_step.dependOn(&check.step); |
| | 1734 | } |
| | 1735 | |
| | 1736 | { |
| | 1737 | const exe = addExecutable(b, "main2", opts); |
| | 1738 | exe.addObject(obj); |
| | 1739 | exe.strip = true; |
| | 1740 | exe.linkLibC(); |
| | 1741 | |
| | 1742 | const check = exe.checkObject(); |
| | 1743 | check.checkStart(); |
| | 1744 | check.checkExact("section headers"); |
| | 1745 | check.checkNotPresent("name .debug_info"); |
| | 1746 | test_step.dependOn(&check.step); |
| | 1747 | } |
| | 1748 | |
| | 1749 | return test_step; |
| | 1750 | } |
| | 1751 | |
| | 1752 | fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| | 1753 | const test_step = addTestStep(b, "tls-df-static-tls", opts); |
| | 1754 | |
| | 1755 | const obj = addObject(b, "obj", opts); |
| | 1756 | addCSourceBytes(obj, |
| | 1757 | \\static _Thread_local int foo = 5; |
| | 1758 | \\void mutate() { ++foo; } |
| | 1759 | \\int bar() { return foo; } |
| | 1760 | , &.{"-ftls-model=initial-exec"}); |
| | 1761 | obj.force_pic = true; |
| | 1762 | |
| | 1763 | { |
| | 1764 | const dso = addSharedLibrary(b, "a", opts); |
| | 1765 | dso.addObject(obj); |
| | 1766 | // dso.link_relax = true; |
| | 1767 | |
| | 1768 | const check = dso.checkObject(); |
| | 1769 | check.checkInDynamicSection(); |
| | 1770 | check.checkContains("STATIC_TLS"); |
| | 1771 | test_step.dependOn(&check.step); |
| | 1772 | } |
| | 1773 | |
| | 1774 | // TODO add -Wl,--no-relax |
| | 1775 | // { |
| | 1776 | // const dso = addSharedLibrary(b, "a", opts); |
| | 1777 | // dso.addObject(obj); |
| | 1778 | // dso.link_relax = false; |
| | 1779 | |
| | 1780 | // const check = dso.checkObject(); |
| | 1781 | // check.checkInDynamicSection(); |
| | 1782 | // check.checkContains("STATIC_TLS"); |
| | 1783 | // test_step.dependOn(&check.step); |
| | 1784 | // } |
| | 1785 | |
| | 1786 | return test_step; |
| | 1787 | } |
| | 1788 | |
| | 1789 | fn testTlsDso(b: *Build, opts: Options) *Step { |
| | 1790 | const test_step = addTestStep(b, "tls-dso", opts); |
| | 1791 | |
| | 1792 | const dso = addSharedLibrary(b, "a", opts); |
| | 1793 | addCSourceBytes(dso, |
| | 1794 | \\extern _Thread_local int foo; |
| | 1795 | \\_Thread_local int bar; |
| | 1796 | \\int get_foo1() { return foo; } |
| | 1797 | \\int get_bar1() { return bar; } |
| | 1798 | , &.{}); |
| | 1799 | |
| | 1800 | const exe = addExecutable(b, "main", opts); |
| | 1801 | addCSourceBytes(exe, |
| | 1802 | \\#include <stdio.h> |
| | 1803 | \\_Thread_local int foo; |
| | 1804 | \\extern _Thread_local int bar; |
| | 1805 | \\int get_foo1(); |
| | 1806 | \\int get_bar1(); |
| | 1807 | \\int get_foo2() { return foo; } |
| | 1808 | \\int get_bar2() { return bar; } |
| | 1809 | \\int main() { |
| | 1810 | \\ foo = 5; |
| | 1811 | \\ bar = 3; |
| | 1812 | \\ printf("%d %d %d %d %d %d\n", |
| | 1813 | \\ foo, bar, |
| | 1814 | \\ get_foo1(), get_bar1(), |
| | 1815 | \\ get_foo2(), get_bar2()); |
| | 1816 | \\ return 0; |
| | 1817 | \\} |
| | 1818 | , &.{}); |
| | 1819 | exe.linkLibrary(dso); |
| | 1820 | exe.linkLibC(); |
| | 1821 | |
| | 1822 | const run = addRunArtifact(exe); |
| | 1823 | run.expectStdOutEqual("5 3 5 3 5 3\n"); |
| | 1824 | test_step.dependOn(&run.step); |
| | 1825 | |
| | 1826 | return test_step; |
| | 1827 | } |
| | 1828 | |
| | 1829 | fn testTlsGd(b: *Build, opts: Options) *Step { |
| | 1830 | const test_step = addTestStep(b, "tls-gd", opts); |
| | 1831 | |
| | 1832 | const main_o = addObject(b, "main", opts); |
| | 1833 | addCSourceBytes(main_o, |
| | 1834 | \\#include <stdio.h> |
| | 1835 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| | 1836 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; |
| | 1837 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int x3; |
| | 1838 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int x4; |
| | 1839 | \\int get_x5(); |
| | 1840 | \\int get_x6(); |
| | 1841 | \\int main() { |
| | 1842 | \\ x2 = 2; |
| | 1843 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); |
| | 1844 | \\ return 0; |
| | 1845 | \\} |
| | 1846 | , &.{}); |
| | 1847 | main_o.linkLibC(); |
| | 1848 | main_o.force_pic = true; |
| | 1849 | |
| | 1850 | const a_o = addObject(b, "a", opts); |
| | 1851 | addCSourceBytes(a_o, |
| | 1852 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; |
| | 1853 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; |
| | 1854 | \\int get_x5() { return x5; } |
| | 1855 | , &.{}); |
| | 1856 | a_o.force_pic = true; |
| | 1857 | |
| | 1858 | const b_o = addObject(b, "b", opts); |
| | 1859 | addCSourceBytes(b_o, |
| | 1860 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; |
| | 1861 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; |
| | 1862 | \\int get_x6() { return x6; } |
| | 1863 | , &.{}); |
| | 1864 | b_o.force_pic = true; |
| | 1865 | |
| | 1866 | const exp_stdout = "1 2 3 4 5 6\n"; |
| | 1867 | |
| | 1868 | const dso1 = addSharedLibrary(b, "a", opts); |
| | 1869 | dso1.addObject(a_o); |
| | 1870 | |
| | 1871 | const dso2 = addSharedLibrary(b, "b", opts); |
| | 1872 | dso2.addObject(b_o); |
| | 1873 | // dso2.link_relax = false; // TODO |
| | 1874 | |
| | 1875 | { |
| | 1876 | const exe = addExecutable(b, "main1", opts); |
| | 1877 | exe.addObject(main_o); |
| | 1878 | exe.linkLibrary(dso1); |
| | 1879 | exe.linkLibrary(dso2); |
| | 1880 | |
| | 1881 | const run = addRunArtifact(exe); |
| | 1882 | run.expectStdOutEqual(exp_stdout); |
| | 1883 | test_step.dependOn(&run.step); |
| | 1884 | } |
| | 1885 | |
| | 1886 | { |
| | 1887 | const exe = addExecutable(b, "main2", opts); |
| | 1888 | exe.addObject(main_o); |
| | 1889 | // exe.link_relax = false; // TODO |
| | 1890 | exe.linkLibrary(dso1); |
| | 1891 | exe.linkLibrary(dso2); |
| | 1892 | |
| | 1893 | const run = addRunArtifact(exe); |
| | 1894 | run.expectStdOutEqual(exp_stdout); |
| | 1895 | test_step.dependOn(&run.step); |
| | 1896 | } |
| | 1897 | |
| | 1898 | // https://github.com/ziglang/zig/issues/17430 ?? |
| | 1899 | // { |
| | 1900 | // const exe = addExecutable(b, "main3", opts); |
| | 1901 | // exe.addObject(main_o); |
| | 1902 | // exe.linkLibrary(dso1); |
| | 1903 | // exe.linkLibrary(dso2); |
| | 1904 | // exe.linkage = .static; |
| | 1905 | |
| | 1906 | // const run = addRunArtifact(exe); |
| | 1907 | // run.expectStdOutEqual(exp_stdout); |
| | 1908 | // test_step.dependOn(&run.step); |
| | 1909 | // } |
| | 1910 | |
| | 1911 | // { |
| | 1912 | // const exe = addExecutable(b, "main4", opts); |
| | 1913 | // exe.addObject(main_o); |
| | 1914 | // // exe.link_relax = false; // TODO |
| | 1915 | // exe.linkLibrary(dso1); |
| | 1916 | // exe.linkLibrary(dso2); |
| | 1917 | // exe.linkage = .static; |
| | 1918 | |
| | 1919 | // const run = addRunArtifact(exe); |
| | 1920 | // run.expectStdOutEqual(exp_stdout); |
| | 1921 | // test_step.dependOn(&run.step); |
| | 1922 | // } |
| | 1923 | |
| | 1924 | return test_step; |
| | 1925 | } |
| | 1926 | |
| 1708 | fn testTlsStatic(b: *Build, opts: Options) *Step { | 1927 | fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 1709 | const test_step = addTestStep(b, "tls-static", opts); | 1928 | const test_step = addTestStep(b, "tls-static", opts); |
| 1710 | | 1929 | |