authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-28 00:04:18+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-28 06:59:21+02:00
log58defeeaa633d67ad4361b032f5d4a5c626af219
tree9afdb06e341bb90535307dccec65e38861f34716
parent77476a03e8926f011e93104bc998118b3cde8d58

macho: test section$end$ boundary symbol handling


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

test/link/macho.zig+38
......@@ -53,6 +53,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
5353 macho_step.dependOn(testRelocatable(b, .{ .target = default_target }));
5454 macho_step.dependOn(testRelocatableZig(b, .{ .target = default_target }));
5555 macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target }));
56 macho_step.dependOn(testSectionBoundarySymbols2(b, .{ .target = default_target }));
5657 macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target }));
5758 macho_step.dependOn(testSymbolStabs(b, .{ .target = default_target }));
5859 macho_step.dependOn(testStackSize(b, .{ .target = default_target }));
......@@ -1962,6 +1963,43 @@ fn testSectionBoundarySymbols(b: *Build, opts: Options) *Step {
19621963 return test_step;
19631964}
19641965
1966fn testSectionBoundarySymbols2(b: *Build, opts: Options) *Step {
1967 const test_step = addTestStep(b, "section-boundary-symbols-2", opts);
1968
1969 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
1970 \\#include <stdio.h>
1971 \\struct pair { int a; int b; };
1972 \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 };
1973 \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 };
1974 \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs");
1975 \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs");
1976 \\int main() {
1977 \\ printf("%d,%d\n", first.a, first.b);
1978 \\ printf("%d,%d\n", second.a, second.b);
1979 \\ struct pair* p;
1980 \\ for (p = &pairs_start; p < &pairs_end; p++) {
1981 \\ p->a = 0;
1982 \\ }
1983 \\ printf("%d,%d\n", first.a, first.b);
1984 \\ printf("%d,%d\n", second.a, second.b);
1985 \\ return 0;
1986 \\}
1987 });
1988
1989 const run = b.addRunArtifact(exe);
1990 run.skip_foreign_checks = true;
1991 run.expectStdOutEqual(
1992 \\1,2
1993 \\3,4
1994 \\0,2
1995 \\0,4
1996 \\
1997 );
1998 test_step.dependOn(&run.step);
1999
2000 return test_step;
2001}
2002
19652003fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step {
19662004 const test_step = addTestStep(b, "segment-boundary-symbols", opts);
19672005