authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-14 13:15:30+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-15 12:14:03+02:00
log15ff0db794c92dd64c7b585fb5eed1adb4888c5e
tree9c873841e734706617e02bf1cbb7160842767015
parent96d3c4f54fb4d80a44d9319c0054b45f4b856cad

zld: handle __gcc_except_tab section


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

src/link/MachO/Zld.zig+28
......@@ -65,6 +65,9 @@ stub_helper_section_index: ?u16 = null,
6565text_const_section_index: ?u16 = null,
6666cstring_section_index: ?u16 = null,
6767ustring_section_index: ?u16 = null,
68gcc_except_tab: ?u16 = null,
69unwind_info: ?u16 = null,
70eh_frame: ?u16 = null,
6871
6972// __DATA_CONST segment sections
7073got_section_index: ?u16 = null,
......@@ -649,6 +652,7 @@ fn updateMetadata(self: *Zld) !void {
649652 });
650653 continue;
651654 }
655
652656 if (sect.isDebug()) {
653657 if (mem.eql(u8, "__LD", segname) and mem.eql(u8, "__compact_unwind", sectname)) {
654658 log.debug("TODO compact unwind section: type 0x{x}, name '{s},{s}'", .{
......@@ -677,6 +681,24 @@ fn updateMetadata(self: *Zld) !void {
677681 .reserved2 = 0,
678682 .reserved3 = 0,
679683 });
684 } else if (mem.eql(u8, sectname, "__gcc_except_tab")) {
685 if (self.gcc_except_tab != null) continue;
686
687 self.gcc_except_tab = @intCast(u16, text_seg.sections.items.len);
688 try text_seg.addSection(self.allocator, .{
689 .sectname = makeStaticString("__gcc_except_tab"),
690 .segname = makeStaticString("__TEXT"),
691 .addr = 0,
692 .size = 0,
693 .offset = 0,
694 .@"align" = 0,
695 .reloff = 0,
696 .nreloc = 0,
697 .flags = macho.S_REGULAR,
698 .reserved1 = 0,
699 .reserved2 = 0,
700 .reserved3 = 0,
701 });
680702 } else {
681703 if (self.text_const_section_index != null) continue;
682704
......@@ -975,6 +997,11 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) ?MatchingSection {
975997 .seg = self.text_segment_cmd_index.?,
976998 .sect = self.ustring_section_index.?,
977999 };
1000 } else if (mem.eql(u8, sectname, "__gcc_except_tab")) {
1001 break :blk .{
1002 .seg = self.text_segment_cmd_index.?,
1003 .sect = self.gcc_except_tab.?,
1004 };
9781005 } else {
9791006 break :blk .{
9801007 .seg = self.text_segment_cmd_index.?,
......@@ -1031,6 +1058,7 @@ fn sortSections(self: *Zld) !void {
10311058 &self.text_section_index,
10321059 &self.stubs_section_index,
10331060 &self.stub_helper_section_index,
1061 &self.gcc_except_tab,
10341062 &self.text_const_section_index,
10351063 &self.cstring_section_index,
10361064 &self.ustring_section_index,