authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-25 18:20:59+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-25 20:32:58+02:00
log49b3986417378278cef4157e71c38a817726ddc8
tree18bccd44b9919cfcc3e7d20a017bf59d79700ce5
parent411f9c60b1cb30aec8706ffac75992ac8cc59cba

zld: fix section mapping for Go specific sections

which include: * `__TEXT,__rodata` => `__DATA_CONST,__const` * `__TEXT,__typelink` => `__DATA_CONST,__const` * `__TEXT,__itablink` => `__DATA_CONST,__const` * `__TEXT,__gosymtab` => `__DATA_CONST,__const` * `__TEXT,__gopclntab` => `__DATA_CONST,__const` Also, we treat section as containing machine code and mapping it to `__TEXT,__text` if it is `S_REGULAR` and contains either `S_ATTR_PURE_INSTRUCTIONS` or `S_ATTR_SOME_INSTRUCTIONS` or both.

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

src/link/MachO/Object.zig+1-1
......@@ -94,7 +94,7 @@ pub const Section = struct {
9494
9595 pub fn isCode(self: Section) bool {
9696 const attr = self.sectionAttrs();
97 return attr & macho.S_ATTR_PURE_INSTRUCTIONS != 0 and attr & macho.S_ATTR_SOME_INSTRUCTIONS != 0;
97 return attr & macho.S_ATTR_PURE_INSTRUCTIONS != 0 or attr & macho.S_ATTR_SOME_INSTRUCTIONS != 0;
9898 }
9999
100100 pub fn isDebug(self: Section) bool {
src/link/MachO/Zld.zig+16
......@@ -367,6 +367,7 @@ fn mapAndUpdateSections(
367367 offset,
368368 offset + size,
369369 });
370 log.debug(" | flags 0x{x}", .{source_sect.inner.flags});
370371
371372 source_sect.target_map = .{
372373 .segment_id = target_seg_id,
......@@ -740,6 +741,21 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
740741 .seg = self.text_segment_cmd_index.?,
741742 .sect = self.objc_methlist_section_index.?,
742743 };
744 } else if (mem.eql(u8, sectname, "__rodata") or
745 mem.eql(u8, sectname, "__typelink") or
746 mem.eql(u8, sectname, "__itablink") or
747 mem.eql(u8, sectname, "__gosymtab") or
748 mem.eql(u8, sectname, "__gopclntab"))
749 {
750 if (self.data_const_section_index == null) {
751 self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len);
752 try data_const_seg.addSection(self.allocator, "__const", .{});
753 }
754
755 break :blk .{
756 .seg = self.data_const_segment_cmd_index.?,
757 .sect = self.data_const_section_index.?,
758 };
743759 } else {
744760 if (self.text_const_section_index == null) {
745761 self.text_const_section_index = @intCast(u16, text_seg.sections.items.len);