| author | |
| committer | |
| log | 1fba9e1280efb935e935f09a196ae35d5391ed48 |
| tree | ae2d71856c6d2093c575a9995ae271ab2e3c5390 |
| parent | a84951465b409495095a9598db0cae745f34fa7b |
| parent | 58defeeaa633d67ad4361b032f5d4a5c626af219 |
| signature |
macho: fix typo in boundary symbols handling3 files changed, 46 insertions(+), 8 deletions(-)
src/link/MachO.zig+6-6| ... | @@ -1658,7 +1658,7 @@ fn initSyntheticSections(self: *MachO) !void { | ... | @@ -1658,7 +1658,7 @@ fn initSyntheticSections(self: *MachO) !void { |
| 1658 | .maxprot = prot, | 1658 | .maxprot = prot, |
| 1659 | }); | 1659 | }); |
| 1660 | } | 1660 | } |
| 1661 | } else if (eatPrefix(name, "segment$stop$")) |segname| { | 1661 | } else if (eatPrefix(name, "segment$end$")) |segname| { |
| 1662 | if (self.getSegmentByName(segname) == null) { // TODO check segname is valid | 1662 | if (self.getSegmentByName(segname) == null) { // TODO check segname is valid |
| 1663 | const prot = getSegmentProt(segname); | 1663 | const prot = getSegmentProt(segname); |
| 1664 | _ = try self.segments.append(gpa, .{ | 1664 | _ = try self.segments.append(gpa, .{ |
| ... | @@ -1675,7 +1675,7 @@ fn initSyntheticSections(self: *MachO) !void { | ... | @@ -1675,7 +1675,7 @@ fn initSyntheticSections(self: *MachO) !void { |
| 1675 | if (self.getSectionByName(segname, sectname) == null) { | 1675 | if (self.getSectionByName(segname, sectname) == null) { |
| 1676 | _ = try self.addSection(segname, sectname, .{}); | 1676 | _ = try self.addSection(segname, sectname, .{}); |
| 1677 | } | 1677 | } |
| 1678 | } else if (eatPrefix(name, "section$stop$")) |actual_name| { | 1678 | } else if (eatPrefix(name, "section$end$")) |actual_name| { |
| 1679 | const sep = mem.indexOfScalar(u8, actual_name, '$').?; // TODO error rather than a panic | 1679 | const sep = mem.indexOfScalar(u8, actual_name, '$').?; // TODO error rather than a panic |
| 1680 | const segname = actual_name[0..sep]; // TODO check segname is valid | 1680 | const segname = actual_name[0..sep]; // TODO check segname is valid |
| 1681 | const sectname = actual_name[sep + 1 ..]; // TODO check sectname is valid | 1681 | const sectname = actual_name[sep + 1 ..]; // TODO check sectname is valid |
| ... | @@ -2267,8 +2267,8 @@ fn allocateSyntheticSymbols(self: *MachO) void { | ... | @@ -2267,8 +2267,8 @@ fn allocateSyntheticSymbols(self: *MachO) void { |
| 2267 | const seg = self.segments.items[seg_id]; | 2267 | const seg = self.segments.items[seg_id]; |
| 2268 | sym.value = seg.vmaddr; | 2268 | sym.value = seg.vmaddr; |
| 2269 | } | 2269 | } |
| 2270 | } else if (mem.startsWith(u8, name, "segment$stop$")) { | 2270 | } else if (mem.startsWith(u8, name, "segment$end$")) { |
| 2271 | const segname = name["segment$stop$".len..]; | 2271 | const segname = name["segment$end$".len..]; |
| 2272 | if (self.getSegmentByName(segname)) |seg_id| { | 2272 | if (self.getSegmentByName(segname)) |seg_id| { |
| 2273 | const seg = self.segments.items[seg_id]; | 2273 | const seg = self.segments.items[seg_id]; |
| 2274 | sym.value = seg.vmaddr + seg.vmsize; | 2274 | sym.value = seg.vmaddr + seg.vmsize; |
| ... | @@ -2283,8 +2283,8 @@ fn allocateSyntheticSymbols(self: *MachO) void { | ... | @@ -2283,8 +2283,8 @@ fn allocateSyntheticSymbols(self: *MachO) void { |
| 2283 | sym.value = sect.addr; | 2283 | sym.value = sect.addr; |
| 2284 | sym.out_n_sect = sect_id; | 2284 | sym.out_n_sect = sect_id; |
| 2285 | } | 2285 | } |
| 2286 | } else if (mem.startsWith(u8, name, "section$stop$")) { | 2286 | } else if (mem.startsWith(u8, name, "section$end$")) { |
| 2287 | const actual_name = name["section$stop$".len..]; | 2287 | const actual_name = name["section$end$".len..]; |
| 2288 | const sep = mem.indexOfScalar(u8, actual_name, '$').?; // TODO error rather than a panic | 2288 | const sep = mem.indexOfScalar(u8, actual_name, '$').?; // TODO error rather than a panic |
| 2289 | const segname = actual_name[0..sep]; | 2289 | const segname = actual_name[0..sep]; |
| 2290 | const sectname = actual_name[sep + 1 ..]; | 2290 | const sectname = actual_name[sep + 1 ..]; |
src/link/MachO/InternalObject.zig+2-2| ... | @@ -177,9 +177,9 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { | ... | @@ -177,9 +177,9 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void { |
| 177 | if (ref.getFile(macho_file) != null) continue; | 177 | if (ref.getFile(macho_file) != null) continue; |
| 178 | const name = sym.getName(macho_file); | 178 | const name = sym.getName(macho_file); |
| 179 | if (mem.startsWith(u8, name, "segment$start$") or | 179 | if (mem.startsWith(u8, name, "segment$start$") or |
| 180 | mem.startsWith(u8, name, "segment$stop$") or | 180 | mem.startsWith(u8, name, "segment$end$") or |
| 181 | mem.startsWith(u8, name, "section$start$") or | 181 | mem.startsWith(u8, name, "section$start$") or |
| 182 | mem.startsWith(u8, name, "section$stop$")) | 182 | mem.startsWith(u8, name, "section$end$")) |
| 183 | { | 183 | { |
| 184 | const gop = try boundary_symbols.getOrPut(name); | 184 | const gop = try boundary_symbols.getOrPut(name); |
| 185 | if (!gop.found_existing) { | 185 | if (!gop.found_existing) { |
test/link/macho.zig+38| ... | @@ -53,6 +53,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { | ... | @@ -53,6 +53,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 53 | macho_step.dependOn(testRelocatable(b, .{ .target = default_target })); | 53 | macho_step.dependOn(testRelocatable(b, .{ .target = default_target })); |
| 54 | macho_step.dependOn(testRelocatableZig(b, .{ .target = default_target })); | 54 | macho_step.dependOn(testRelocatableZig(b, .{ .target = default_target })); |
| 55 | macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); | 55 | macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); |
| 56 | macho_step.dependOn(testSectionBoundarySymbols2(b, .{ .target = default_target })); | ||
| 56 | macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); | 57 | macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); |
| 57 | macho_step.dependOn(testSymbolStabs(b, .{ .target = default_target })); | 58 | macho_step.dependOn(testSymbolStabs(b, .{ .target = default_target })); |
| 58 | macho_step.dependOn(testStackSize(b, .{ .target = default_target })); | 59 | macho_step.dependOn(testStackSize(b, .{ .target = default_target })); |
| ... | @@ -1962,6 +1963,43 @@ fn testSectionBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -1962,6 +1963,43 @@ fn testSectionBoundarySymbols(b: *Build, opts: Options) *Step { |
| 1962 | return test_step; | 1963 | return test_step; |
| 1963 | } | 1964 | } |
| 1964 | 1965 | ||
| 1966 | fn 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 | |||
| 1965 | fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { | 2003 | fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { |
| 1966 | const test_step = addTestStep(b, "segment-boundary-symbols", opts); | 2004 | const test_step = addTestStep(b, "segment-boundary-symbols", opts); |
| 1967 | 2005 |