aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-06-11 23:06:43 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-06-11 23:06:43 +0200
commitac587744e30817df86b9c759b307d41fe7951832 (patch)
tree381dfc50274b71d2071c115e28e4a1cf527c6810 /src
parentb93fd4bb73506a8feb0b4c312c1afbf88cc9248d (diff)
downloadzig-ac587744e30817df86b9c759b307d41fe7951832.tar.gz
zig-ac587744e30817df86b9c759b307d41fe7951832.zip
zld: allow for existence of __DATA_CONST segments in objects
Up until now, we only expected old-fashioned objects which carried two basic segments by name: __TEXT and __DATA. Since macOS 11.1, there is a new segment __DATA_CONST, and we should expect and correctly parse sections designated to that segment explicitly as is the case in golang.
Diffstat (limited to 'src')
-rw-r--r--src/link/MachO/Zld.zig21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/link/MachO/Zld.zig b/src/link/MachO/Zld.zig
index 225f14fc4e..61c7863ad5 100644
--- a/src/link/MachO/Zld.zig
+++ b/src/link/MachO/Zld.zig
@@ -481,8 +481,7 @@ fn updateMetadata(self: *Zld) !void {
.reserved3 = 0,
});
}
- } else if (mem.eql(u8, segname, "__DATA")) {
- if (!mem.eql(u8, sectname, "__const")) continue;
+ } else if (mem.eql(u8, segname, "__DATA") or mem.eql(u8, segname, "__DATA_CONST")) {
if (self.data_const_section_index != null) continue;
self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len);
@@ -503,7 +502,6 @@ fn updateMetadata(self: *Zld) !void {
}
},
macho.S_CSTRING_LITERALS => {
- if (!mem.eql(u8, segname, "__TEXT")) continue;
if (self.cstring_section_index != null) continue;
self.cstring_section_index = @intCast(u16, text_seg.sections.items.len);
@@ -523,7 +521,6 @@ fn updateMetadata(self: *Zld) !void {
});
},
macho.S_MOD_INIT_FUNC_POINTERS => {
- if (!mem.eql(u8, segname, "__DATA")) continue;
if (self.mod_init_func_section_index != null) continue;
self.mod_init_func_section_index = @intCast(u16, data_const_seg.sections.items.len);
@@ -543,7 +540,6 @@ fn updateMetadata(self: *Zld) !void {
});
},
macho.S_MOD_TERM_FUNC_POINTERS => {
- if (!mem.eql(u8, segname, "__DATA")) continue;
if (self.mod_term_func_section_index != null) continue;
self.mod_term_func_section_index = @intCast(u16, data_const_seg.sections.items.len);
@@ -563,7 +559,6 @@ fn updateMetadata(self: *Zld) !void {
});
},
macho.S_ZEROFILL => {
- if (!mem.eql(u8, segname, "__DATA")) continue;
if (mem.eql(u8, sectname, "__common")) {
if (self.common_section_index != null) continue;
@@ -603,7 +598,6 @@ fn updateMetadata(self: *Zld) !void {
}
},
macho.S_THREAD_LOCAL_VARIABLES => {
- if (!mem.eql(u8, segname, "__DATA")) continue;
if (self.tlv_section_index != null) continue;
self.tlv_section_index = @intCast(u16, data_seg.sections.items.len);
@@ -623,7 +617,6 @@ fn updateMetadata(self: *Zld) !void {
});
},
macho.S_THREAD_LOCAL_REGULAR => {
- if (!mem.eql(u8, segname, "__DATA")) continue;
if (self.tlv_data_section_index != null) continue;
self.tlv_data_section_index = @intCast(u16, data_seg.sections.items.len);
@@ -643,7 +636,6 @@ fn updateMetadata(self: *Zld) !void {
});
},
macho.S_THREAD_LOCAL_ZEROFILL => {
- if (!mem.eql(u8, segname, "__DATA")) continue;
if (self.tlv_bss_section_index != null) continue;
self.tlv_bss_section_index = @intCast(u16, data_seg.sections.items.len);
@@ -863,6 +855,12 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection {
.sect = self.text_const_section_index.?,
};
}
+ if (mem.eql(u8, segname, "__DATA_CONST")) {
+ break :blk .{
+ .seg = self.data_const_segment_cmd_index.?,
+ .sect = self.data_const_section_index.?,
+ };
+ }
if (mem.eql(u8, segname, "__DATA")) {
if (mem.eql(u8, sectname, "__const")) {
break :blk .{
@@ -1900,7 +1898,12 @@ fn relocTargetAddr(self: *Zld, object: *const Object, target: reloc.Relocation.T
}
},
.section => |sect_id| {
+ log.debug(" | section offset", .{});
const source_sect = object.sections.items[sect_id];
+ log.debug(" | section '{s},{s}'", .{
+ parseName(&source_sect.inner.segname),
+ parseName(&source_sect.inner.sectname),
+ });
const target_map = source_sect.target_map orelse unreachable;
const target_seg = self.load_commands.items[target_map.segment_id].Segment;
const target_sect = target_seg.sections.items[target_map.section_id];