authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-03-14 17:04:23+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-03-15 08:17:10+01:00
logd565c5dfcdcd6753ed0d00a7f6cccdc87d2b99a2
treeb2e93c0a33a7c9ec46e5a121bbc1ed6fd261762f
parent5193da3422f7a63bb7ff4395da08db3782908e33

macho: fix a sad typo in calculating the address of a TLV pointer


2 files changed, 67 insertions(+), 1 deletions(-)

src/link/MachO/synthetic.zig+1-1
......@@ -532,7 +532,7 @@ pub const TlvPtrSection = struct {
532532 pub fn getAddress(tlv: TlvPtrSection, index: Index, macho_file: *MachO) u64 {
533533 assert(index < tlv.symbols.items.len);
534534 const header = macho_file.sections.items(.header)[macho_file.tlv_ptr_sect_index.?];
535 return header.addr + index * @sizeOf(u64) * 3;
535 return header.addr + index * @sizeOf(u64);
536536 }
537537
538538 pub fn size(tlv: TlvPtrSection) usize {
test/link/macho.zig+66
......@@ -72,6 +72,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
7272 macho_step.dependOn(testSearchStrategy(b, .{ .target = default_target }));
7373 macho_step.dependOn(testTbdv3(b, .{ .target = default_target }));
7474 macho_step.dependOn(testTls(b, .{ .target = default_target }));
75 macho_step.dependOn(testTlsPointers(b, .{ .target = default_target }));
7576 macho_step.dependOn(testTwoLevelNamespace(b, .{ .target = default_target }));
7677 macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target }));
7778
......@@ -1654,6 +1655,71 @@ fn testTls(b: *Build, opts: Options) *Step {
16541655 return test_step;
16551656}
16561657
1658// https://github.com/ziglang/zig/issues/19221
1659fn testTlsPointers(b: *Build, opts: Options) *Step {
1660 const test_step = addTestStep(b, "tls-pointers", opts);
1661
1662 const foo_h = foo_h: {
1663 const wf = WriteFile.create(b);
1664 break :foo_h wf.add("foo.h",
1665 \\template<typename just4fun>
1666 \\struct Foo {
1667 \\
1668 \\public:
1669 \\ static int getVar() {
1670 \\ static int thread_local var = 0;
1671 \\ ++var;
1672 \\ return var;
1673 \\}
1674 \\};
1675 );
1676 };
1677
1678 const bar_o = addObject(b, opts, .{ .name = "bar", .cpp_source_bytes =
1679 \\#include "foo.h"
1680 \\int bar() {
1681 \\ int v1 = Foo<int>::getVar();
1682 \\ return v1;
1683 \\}
1684 });
1685 bar_o.root_module.addIncludePath(foo_h.dirname());
1686 bar_o.linkLibCpp();
1687
1688 const baz_o = addObject(b, opts, .{ .name = "baz", .cpp_source_bytes =
1689 \\#include "foo.h"
1690 \\int baz() {
1691 \\ int v1 = Foo<unsigned>::getVar();
1692 \\ return v1;
1693 \\}
1694 });
1695 baz_o.root_module.addIncludePath(foo_h.dirname());
1696 baz_o.linkLibCpp();
1697
1698 const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes =
1699 \\extern int bar();
1700 \\extern int baz();
1701 \\int main() {
1702 \\ int v1 = bar();
1703 \\ int v2 = baz();
1704 \\ return v1 != v2;
1705 \\}
1706 });
1707 main_o.root_module.addIncludePath(foo_h.dirname());
1708 main_o.linkLibCpp();
1709
1710 const exe = addExecutable(b, opts, .{ .name = "main" });
1711 exe.addObject(bar_o);
1712 exe.addObject(baz_o);
1713 exe.addObject(main_o);
1714 exe.linkLibCpp();
1715
1716 const run = addRunArtifact(exe);
1717 run.expectExitCode(0);
1718 test_step.dependOn(&run.step);
1719
1720 return test_step;
1721}
1722
16571723fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
16581724 const test_step = addTestStep(b, "tls-large-tbss", opts);
16591725