mirror of
https://github.com/ziglang/zig.git
synced 2024-11-14 16:13:24 +00:00
Merge pull request #20834 from ziglang/macho-boundary-typo-fix
macho: fix typo in boundary symbols handling
This commit is contained in:
commit
1fba9e1280
@ -1658,7 +1658,7 @@ fn initSyntheticSections(self: *MachO) !void {
|
||||
.maxprot = prot,
|
||||
});
|
||||
}
|
||||
} else if (eatPrefix(name, "segment$stop$")) |segname| {
|
||||
} else if (eatPrefix(name, "segment$end$")) |segname| {
|
||||
if (self.getSegmentByName(segname) == null) { // TODO check segname is valid
|
||||
const prot = getSegmentProt(segname);
|
||||
_ = try self.segments.append(gpa, .{
|
||||
@ -1675,7 +1675,7 @@ fn initSyntheticSections(self: *MachO) !void {
|
||||
if (self.getSectionByName(segname, sectname) == null) {
|
||||
_ = try self.addSection(segname, sectname, .{});
|
||||
}
|
||||
} else if (eatPrefix(name, "section$stop$")) |actual_name| {
|
||||
} else if (eatPrefix(name, "section$end$")) |actual_name| {
|
||||
const sep = mem.indexOfScalar(u8, actual_name, '$').?; // TODO error rather than a panic
|
||||
const segname = actual_name[0..sep]; // TODO check segname is valid
|
||||
const sectname = actual_name[sep + 1 ..]; // TODO check sectname is valid
|
||||
@ -2267,8 +2267,8 @@ fn allocateSyntheticSymbols(self: *MachO) void {
|
||||
const seg = self.segments.items[seg_id];
|
||||
sym.value = seg.vmaddr;
|
||||
}
|
||||
} else if (mem.startsWith(u8, name, "segment$stop$")) {
|
||||
const segname = name["segment$stop$".len..];
|
||||
} else if (mem.startsWith(u8, name, "segment$end$")) {
|
||||
const segname = name["segment$end$".len..];
|
||||
if (self.getSegmentByName(segname)) |seg_id| {
|
||||
const seg = self.segments.items[seg_id];
|
||||
sym.value = seg.vmaddr + seg.vmsize;
|
||||
@ -2283,8 +2283,8 @@ fn allocateSyntheticSymbols(self: *MachO) void {
|
||||
sym.value = sect.addr;
|
||||
sym.out_n_sect = sect_id;
|
||||
}
|
||||
} else if (mem.startsWith(u8, name, "section$stop$")) {
|
||||
const actual_name = name["section$stop$".len..];
|
||||
} else if (mem.startsWith(u8, name, "section$end$")) {
|
||||
const actual_name = name["section$end$".len..];
|
||||
const sep = mem.indexOfScalar(u8, actual_name, '$').?; // TODO error rather than a panic
|
||||
const segname = actual_name[0..sep];
|
||||
const sectname = actual_name[sep + 1 ..];
|
||||
|
@ -177,9 +177,9 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void {
|
||||
if (ref.getFile(macho_file) != null) continue;
|
||||
const name = sym.getName(macho_file);
|
||||
if (mem.startsWith(u8, name, "segment$start$") or
|
||||
mem.startsWith(u8, name, "segment$stop$") or
|
||||
mem.startsWith(u8, name, "segment$end$") or
|
||||
mem.startsWith(u8, name, "section$start$") or
|
||||
mem.startsWith(u8, name, "section$stop$"))
|
||||
mem.startsWith(u8, name, "section$end$"))
|
||||
{
|
||||
const gop = try boundary_symbols.getOrPut(name);
|
||||
if (!gop.found_existing) {
|
||||
|
@ -53,6 +53,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
|
||||
macho_step.dependOn(testRelocatable(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testRelocatableZig(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testSectionBoundarySymbols2(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testSymbolStabs(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testStackSize(b, .{ .target = default_target }));
|
||||
@ -1962,6 +1963,43 @@ fn testSectionBoundarySymbols(b: *Build, opts: Options) *Step {
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testSectionBoundarySymbols2(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "section-boundary-symbols-2", opts);
|
||||
|
||||
const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
|
||||
\\#include <stdio.h>
|
||||
\\struct pair { int a; int b; };
|
||||
\\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 };
|
||||
\\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 };
|
||||
\\extern struct pair pairs_start __asm("section$start$__DATA$__pairs");
|
||||
\\extern struct pair pairs_end __asm("section$end$__DATA$__pairs");
|
||||
\\int main() {
|
||||
\\ printf("%d,%d\n", first.a, first.b);
|
||||
\\ printf("%d,%d\n", second.a, second.b);
|
||||
\\ struct pair* p;
|
||||
\\ for (p = &pairs_start; p < &pairs_end; p++) {
|
||||
\\ p->a = 0;
|
||||
\\ }
|
||||
\\ printf("%d,%d\n", first.a, first.b);
|
||||
\\ printf("%d,%d\n", second.a, second.b);
|
||||
\\ return 0;
|
||||
\\}
|
||||
});
|
||||
|
||||
const run = b.addRunArtifact(exe);
|
||||
run.skip_foreign_checks = true;
|
||||
run.expectStdOutEqual(
|
||||
\\1,2
|
||||
\\3,4
|
||||
\\0,2
|
||||
\\0,4
|
||||
\\
|
||||
);
|
||||
test_step.dependOn(&run.step);
|
||||
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "segment-boundary-symbols", opts);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user