authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-21 14:31:20+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-24 18:56:17+02:00
logd1fcb998484c8dec6e931b51a89ce4b2999254f5
tree14b61163ed9d8c8482eeea520073c8529949f1a0
parenta480ae6e37199a3b210a4029f3d3c728e959a21d

zld+macho: populate segname from SegmentCommand when adding section


4 files changed, 52 insertions(+), 51 deletions(-)

src/link/MachO.zig+6-6
......@@ -1825,7 +1825,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
18251825
18261826 log.debug("found __text section free space 0x{x} to 0x{x}", .{ off, off + needed_size });
18271827
1828 try text_segment.addSection(self.base.allocator, "__text", "__TEXT", .{
1828 try text_segment.addSection(self.base.allocator, "__text", .{
18291829 .addr = text_segment.inner.vmaddr + off,
18301830 .size = @intCast(u32, needed_size),
18311831 .offset = @intCast(u32, off),
......@@ -1856,7 +1856,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
18561856
18571857 log.debug("found __stubs section free space 0x{x} to 0x{x}", .{ off, off + needed_size });
18581858
1859 try text_segment.addSection(self.base.allocator, "__stubs", "__TEXT", .{
1859 try text_segment.addSection(self.base.allocator, "__stubs", .{
18601860 .addr = text_segment.inner.vmaddr + off,
18611861 .size = needed_size,
18621862 .offset = @intCast(u32, off),
......@@ -1883,7 +1883,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
18831883
18841884 log.debug("found __stub_helper section free space 0x{x} to 0x{x}", .{ off, off + needed_size });
18851885
1886 try text_segment.addSection(self.base.allocator, "__stub_helper", "__TEXT", .{
1886 try text_segment.addSection(self.base.allocator, "__stub_helper", .{
18871887 .addr = text_segment.inner.vmaddr + off,
18881888 .size = needed_size,
18891889 .offset = @intCast(u32, off),
......@@ -1928,7 +1928,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
19281928
19291929 log.debug("found __got section free space 0x{x} to 0x{x}", .{ off, off + needed_size });
19301930
1931 try dc_segment.addSection(self.base.allocator, "__got", "__DATA_CONST", .{
1931 try dc_segment.addSection(self.base.allocator, "__got", .{
19321932 .addr = dc_segment.inner.vmaddr + off - dc_segment.inner.fileoff,
19331933 .size = needed_size,
19341934 .offset = @intCast(u32, off),
......@@ -1973,7 +1973,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
19731973
19741974 log.debug("found __la_symbol_ptr section free space 0x{x} to 0x{x}", .{ off, off + needed_size });
19751975
1976 try data_segment.addSection(self.base.allocator, "__la_symbol_ptr", "__DATA", .{
1976 try data_segment.addSection(self.base.allocator, "__la_symbol_ptr", .{
19771977 .addr = data_segment.inner.vmaddr + off - data_segment.inner.fileoff,
19781978 .size = needed_size,
19791979 .offset = @intCast(u32, off),
......@@ -1993,7 +1993,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
19931993
19941994 log.debug("found __data section free space 0x{x} to 0x{x}", .{ off, off + needed_size });
19951995
1996 try data_segment.addSection(self.base.allocator, "__data", "__DATA", .{
1996 try data_segment.addSection(self.base.allocator, "__data", .{
19971997 .addr = data_segment.inner.vmaddr + off - data_segment.inner.fileoff,
19981998 .size = needed_size,
19991999 .offset = @intCast(u32, off),
src/link/MachO/DebugSymbols.zig+5-5
......@@ -226,7 +226,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void
226226 self.debug_str_section_index = @intCast(u16, dwarf_segment.sections.items.len);
227227 assert(self.debug_string_table.items.len == 0);
228228
229 try dwarf_segment.addSection(allocator, "__debug_str", "__DWARF", .{
229 try dwarf_segment.addSection(allocator, "__debug_str", .{
230230 .addr = dwarf_segment.inner.vmaddr,
231231 .size = @intCast(u32, self.debug_string_table.items.len),
232232 .offset = @intCast(u32, dwarf_segment.inner.fileoff),
......@@ -246,7 +246,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void
246246
247247 log.debug("found dSym __debug_info free space 0x{x} to 0x{x}", .{ off, off + file_size_hint });
248248
249 try dwarf_segment.addSection(allocator, "__debug_info", "__DWARF", .{
249 try dwarf_segment.addSection(allocator, "__debug_info", .{
250250 .addr = dwarf_segment.inner.vmaddr + off - dwarf_segment.inner.fileoff,
251251 .size = file_size_hint,
252252 .offset = @intCast(u32, off),
......@@ -266,7 +266,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void
266266
267267 log.debug("found dSym __debug_abbrev free space 0x{x} to 0x{x}", .{ off, off + file_size_hint });
268268
269 try dwarf_segment.addSection(allocator, "__debug_abbrev", "__DWARF", .{
269 try dwarf_segment.addSection(allocator, "__debug_abbrev", .{
270270 .addr = dwarf_segment.inner.vmaddr + off - dwarf_segment.inner.fileoff,
271271 .size = file_size_hint,
272272 .offset = @intCast(u32, off),
......@@ -286,7 +286,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void
286286
287287 log.debug("found dSym __debug_aranges free space 0x{x} to 0x{x}", .{ off, off + file_size_hint });
288288
289 try dwarf_segment.addSection(allocator, "__debug_aranges", "__DWARF", .{
289 try dwarf_segment.addSection(allocator, "__debug_aranges", .{
290290 .addr = dwarf_segment.inner.vmaddr + off - dwarf_segment.inner.fileoff,
291291 .size = file_size_hint,
292292 .offset = @intCast(u32, off),
......@@ -306,7 +306,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void
306306
307307 log.debug("found dSym __debug_line free space 0x{x} to 0x{x}", .{ off, off + file_size_hint });
308308
309 try dwarf_segment.addSection(allocator, "__debug_line", "__DWARF", .{
309 try dwarf_segment.addSection(allocator, "__debug_line", .{
310310 .addr = dwarf_segment.inner.vmaddr + off - dwarf_segment.inner.fileoff,
311311 .size = file_size_hint,
312312 .offset = @intCast(u32, off),
src/link/MachO/Zld.zig+36-36
......@@ -540,7 +540,7 @@ fn updateMetadata(self: *Zld) !void {
540540 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
541541 const common_section_index = self.common_section_index orelse ind: {
542542 self.common_section_index = @intCast(u16, data_seg.sections.items.len);
543 try data_seg.addSection(self.allocator, "__common", "__DATA", .{
543 try data_seg.addSection(self.allocator, "__common", .{
544544 .flags = macho.S_ZEROFILL,
545545 });
546546 break :ind self.common_section_index.?;
......@@ -627,7 +627,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
627627 macho.S_4BYTE_LITERALS, macho.S_8BYTE_LITERALS, macho.S_16BYTE_LITERALS => {
628628 if (self.text_const_section_index == null) {
629629 self.text_const_section_index = @intCast(u16, text_seg.sections.items.len);
630 try text_seg.addSection(self.allocator, "__const", "__TEXT", .{});
630 try text_seg.addSection(self.allocator, "__const", .{});
631631 }
632632
633633 break :blk .{
......@@ -641,7 +641,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
641641 // on merging the sections' contents.
642642 if (self.objc_methname_section_index == null) {
643643 self.objc_methname_section_index = @intCast(u16, text_seg.sections.items.len);
644 try text_seg.addSection(self.allocator, "__objc_methname", "__TEXT", .{
644 try text_seg.addSection(self.allocator, "__objc_methname", .{
645645 .flags = macho.S_CSTRING_LITERALS,
646646 });
647647 }
......@@ -653,7 +653,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
653653 } else if (mem.eql(u8, sectname, "__objc_methtype")) {
654654 if (self.objc_methtype_section_index == null) {
655655 self.objc_methtype_section_index = @intCast(u16, text_seg.sections.items.len);
656 try text_seg.addSection(self.allocator, "__objc_methtype", "__TEXT", .{
656 try text_seg.addSection(self.allocator, "__objc_methtype", .{
657657 .flags = macho.S_CSTRING_LITERALS,
658658 });
659659 }
......@@ -665,7 +665,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
665665 } else if (mem.eql(u8, sectname, "__objc_classname")) {
666666 if (self.objc_classname_section_index == null) {
667667 self.objc_classname_section_index = @intCast(u16, text_seg.sections.items.len);
668 try text_seg.addSection(self.allocator, "__objc_classname", "__TEXT", .{});
668 try text_seg.addSection(self.allocator, "__objc_classname", .{});
669669 }
670670
671671 break :blk .{
......@@ -676,7 +676,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
676676
677677 if (self.cstring_section_index == null) {
678678 self.cstring_section_index = @intCast(u16, text_seg.sections.items.len);
679 try text_seg.addSection(self.allocator, "__cstring", "__TEXT", .{
679 try text_seg.addSection(self.allocator, "__cstring", .{
680680 .flags = macho.S_CSTRING_LITERALS,
681681 });
682682 }
......@@ -690,7 +690,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
690690 if (mem.eql(u8, segname, "__DATA") and mem.eql(u8, sectname, "__objc_selrefs")) {
691691 if (self.objc_selrefs_section_index == null) {
692692 self.objc_selrefs_section_index = @intCast(u16, data_seg.sections.items.len);
693 try data_seg.addSection(self.allocator, "__objc_selrefs", "__DATA", .{
693 try data_seg.addSection(self.allocator, "__objc_selrefs", .{
694694 .flags = macho.S_LITERAL_POINTERS,
695695 });
696696 }
......@@ -707,7 +707,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
707707 macho.S_MOD_INIT_FUNC_POINTERS => {
708708 if (self.mod_init_func_section_index == null) {
709709 self.mod_init_func_section_index = @intCast(u16, data_const_seg.sections.items.len);
710 try data_const_seg.addSection(self.allocator, "__mod_init_func", "__DATA_CONST", .{
710 try data_const_seg.addSection(self.allocator, "__mod_init_func", .{
711711 .flags = macho.S_MOD_INIT_FUNC_POINTERS,
712712 });
713713 }
......@@ -720,7 +720,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
720720 macho.S_MOD_TERM_FUNC_POINTERS => {
721721 if (self.mod_term_func_section_index == null) {
722722 self.mod_term_func_section_index = @intCast(u16, data_const_seg.sections.items.len);
723 try data_const_seg.addSection(self.allocator, "__mod_term_func", "__DATA_CONST", .{
723 try data_const_seg.addSection(self.allocator, "__mod_term_func", .{
724724 .flags = macho.S_MOD_TERM_FUNC_POINTERS,
725725 });
726726 }
......@@ -734,7 +734,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
734734 if (mem.eql(u8, sectname, "__common")) {
735735 if (self.common_section_index == null) {
736736 self.common_section_index = @intCast(u16, data_seg.sections.items.len);
737 try data_seg.addSection(self.allocator, "__common", "__DATA", .{
737 try data_seg.addSection(self.allocator, "__common", .{
738738 .flags = macho.S_ZEROFILL,
739739 });
740740 }
......@@ -746,7 +746,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
746746 } else {
747747 if (self.bss_section_index == null) {
748748 self.bss_section_index = @intCast(u16, data_seg.sections.items.len);
749 try data_seg.addSection(self.allocator, "__bss", "__DATA", .{
749 try data_seg.addSection(self.allocator, "__bss", .{
750750 .flags = macho.S_ZEROFILL,
751751 });
752752 }
......@@ -760,7 +760,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
760760 macho.S_THREAD_LOCAL_VARIABLES => {
761761 if (self.tlv_section_index == null) {
762762 self.tlv_section_index = @intCast(u16, data_seg.sections.items.len);
763 try data_seg.addSection(self.allocator, "__thread_vars", "__DATA", .{
763 try data_seg.addSection(self.allocator, "__thread_vars", .{
764764 .flags = macho.S_THREAD_LOCAL_VARIABLES,
765765 });
766766 }
......@@ -773,7 +773,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
773773 macho.S_THREAD_LOCAL_REGULAR => {
774774 if (self.tlv_data_section_index == null) {
775775 self.tlv_data_section_index = @intCast(u16, data_seg.sections.items.len);
776 try data_seg.addSection(self.allocator, "__thread_data", "__DATA", .{
776 try data_seg.addSection(self.allocator, "__thread_data", .{
777777 .flags = macho.S_THREAD_LOCAL_REGULAR,
778778 });
779779 }
......@@ -786,7 +786,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
786786 macho.S_THREAD_LOCAL_ZEROFILL => {
787787 if (self.tlv_bss_section_index == null) {
788788 self.tlv_bss_section_index = @intCast(u16, data_seg.sections.items.len);
789 try data_seg.addSection(self.allocator, "__thread_bss", "__DATA", .{
789 try data_seg.addSection(self.allocator, "__thread_bss", .{
790790 .flags = macho.S_THREAD_LOCAL_ZEROFILL,
791791 });
792792 }
......@@ -802,7 +802,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
802802 // in the latest ld64 output.
803803 if (self.eh_frame_section_index == null) {
804804 self.eh_frame_section_index = @intCast(u16, text_seg.sections.items.len);
805 try text_seg.addSection(self.allocator, "__eh_frame", "__TEXT", .{});
805 try text_seg.addSection(self.allocator, "__eh_frame", .{});
806806 }
807807
808808 break :blk .{
......@@ -814,7 +814,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
814814 // TODO audit this: is this the right mapping?
815815 if (self.data_const_section_index == null) {
816816 self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len);
817 try data_const_seg.addSection(self.allocator, "__const", "__DATA_CONST", .{});
817 try data_const_seg.addSection(self.allocator, "__const", .{});
818818 }
819819
820820 break :blk .{
......@@ -826,7 +826,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
826826 if (sect.isCode()) {
827827 if (self.text_section_index == null) {
828828 self.text_section_index = @intCast(u16, text_seg.sections.items.len);
829 try text_seg.addSection(self.allocator, "__text", "__TEXT", .{
829 try text_seg.addSection(self.allocator, "__text", .{
830830 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
831831 });
832832 }
......@@ -850,7 +850,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
850850 if (mem.eql(u8, sectname, "__ustring")) {
851851 if (self.ustring_section_index == null) {
852852 self.ustring_section_index = @intCast(u16, text_seg.sections.items.len);
853 try text_seg.addSection(self.allocator, "__ustring", "__TEXT", .{});
853 try text_seg.addSection(self.allocator, "__ustring", .{});
854854 }
855855
856856 break :blk .{
......@@ -860,7 +860,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
860860 } else if (mem.eql(u8, sectname, "__gcc_except_tab")) {
861861 if (self.gcc_except_tab_section_index == null) {
862862 self.gcc_except_tab_section_index = @intCast(u16, text_seg.sections.items.len);
863 try text_seg.addSection(self.allocator, "__gcc_except_tab", "__TEXT", .{});
863 try text_seg.addSection(self.allocator, "__gcc_except_tab", .{});
864864 }
865865
866866 break :blk .{
......@@ -870,7 +870,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
870870 } else if (mem.eql(u8, sectname, "__objc_methlist")) {
871871 if (self.objc_methlist_section_index == null) {
872872 self.objc_methlist_section_index = @intCast(u16, text_seg.sections.items.len);
873 try text_seg.addSection(self.allocator, "__objc_methlist", "__TEXT", .{});
873 try text_seg.addSection(self.allocator, "__objc_methlist", .{});
874874 }
875875
876876 break :blk .{
......@@ -880,7 +880,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
880880 } else {
881881 if (self.text_const_section_index == null) {
882882 self.text_const_section_index = @intCast(u16, text_seg.sections.items.len);
883 try text_seg.addSection(self.allocator, "__const", "__TEXT", .{});
883 try text_seg.addSection(self.allocator, "__const", .{});
884884 }
885885
886886 break :blk .{
......@@ -893,7 +893,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
893893 if (mem.eql(u8, segname, "__DATA_CONST")) {
894894 if (self.data_const_section_index == null) {
895895 self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len);
896 try data_const_seg.addSection(self.allocator, "__const", "__DATA_CONST", .{});
896 try data_const_seg.addSection(self.allocator, "__const", .{});
897897 }
898898
899899 break :blk .{
......@@ -906,7 +906,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
906906 if (mem.eql(u8, sectname, "__const")) {
907907 if (self.data_const_section_index == null) {
908908 self.data_const_section_index = @intCast(u16, data_const_seg.sections.items.len);
909 try data_const_seg.addSection(self.allocator, "__const", "__DATA_CONST", .{});
909 try data_const_seg.addSection(self.allocator, "__const", .{});
910910 }
911911
912912 break :blk .{
......@@ -916,7 +916,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
916916 } else if (mem.eql(u8, sectname, "__cfstring")) {
917917 if (self.objc_cfstring_section_index == null) {
918918 self.objc_cfstring_section_index = @intCast(u16, data_const_seg.sections.items.len);
919 try data_const_seg.addSection(self.allocator, "__cfstring", "__DATA_CONST", .{});
919 try data_const_seg.addSection(self.allocator, "__cfstring", .{});
920920 }
921921
922922 break :blk .{
......@@ -926,7 +926,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
926926 } else if (mem.eql(u8, sectname, "__objc_classlist")) {
927927 if (self.objc_classlist_section_index == null) {
928928 self.objc_classlist_section_index = @intCast(u16, data_const_seg.sections.items.len);
929 try data_const_seg.addSection(self.allocator, "__objc_classlist", "__DATA_CONST", .{});
929 try data_const_seg.addSection(self.allocator, "__objc_classlist", .{});
930930 }
931931
932932 break :blk .{
......@@ -936,7 +936,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
936936 } else if (mem.eql(u8, sectname, "__objc_imageinfo")) {
937937 if (self.objc_imageinfo_section_index == null) {
938938 self.objc_imageinfo_section_index = @intCast(u16, data_const_seg.sections.items.len);
939 try data_const_seg.addSection(self.allocator, "__objc_imageinfo", "__DATA_CONST", .{});
939 try data_const_seg.addSection(self.allocator, "__objc_imageinfo", .{});
940940 }
941941
942942 break :blk .{
......@@ -946,7 +946,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
946946 } else if (mem.eql(u8, sectname, "__objc_const")) {
947947 if (self.objc_const_section_index == null) {
948948 self.objc_const_section_index = @intCast(u16, data_seg.sections.items.len);
949 try data_seg.addSection(self.allocator, "__objc_const", "__DATA", .{});
949 try data_seg.addSection(self.allocator, "__objc_const", .{});
950950 }
951951
952952 break :blk .{
......@@ -956,7 +956,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
956956 } else if (mem.eql(u8, sectname, "__objc_classrefs")) {
957957 if (self.objc_classrefs_section_index == null) {
958958 self.objc_classrefs_section_index = @intCast(u16, data_seg.sections.items.len);
959 try data_seg.addSection(self.allocator, "__objc_classrefs", "__DATA", .{});
959 try data_seg.addSection(self.allocator, "__objc_classrefs", .{});
960960 }
961961
962962 break :blk .{
......@@ -966,7 +966,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
966966 } else if (mem.eql(u8, sectname, "__objc_data")) {
967967 if (self.objc_data_section_index == null) {
968968 self.objc_data_section_index = @intCast(u16, data_seg.sections.items.len);
969 try data_seg.addSection(self.allocator, "__objc_data", "__DATA", .{});
969 try data_seg.addSection(self.allocator, "__objc_data", .{});
970970 }
971971
972972 break :blk .{
......@@ -976,7 +976,7 @@ fn getMatchingSection(self: *Zld, sect: Object.Section) !?MatchingSection {
976976 } else {
977977 if (self.data_section_index == null) {
978978 self.data_section_index = @intCast(u16, data_seg.sections.items.len);
979 try data_seg.addSection(self.allocator, "__data", "__DATA", .{});
979 try data_seg.addSection(self.allocator, "__data", .{});
980980 }
981981
982982 break :blk .{
......@@ -2124,7 +2124,7 @@ fn populateMetadata(self: *Zld) !void {
21242124 .aarch64 => 2,
21252125 else => unreachable, // unhandled architecture type
21262126 };
2127 try text_seg.addSection(self.allocator, "__text", "__TEXT", .{
2127 try text_seg.addSection(self.allocator, "__text", .{
21282128 .@"align" = alignment,
21292129 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
21302130 });
......@@ -2143,7 +2143,7 @@ fn populateMetadata(self: *Zld) !void {
21432143 .aarch64 => 3 * @sizeOf(u32),
21442144 else => unreachable, // unhandled architecture type
21452145 };
2146 try text_seg.addSection(self.allocator, "__stubs", "__TEXT", .{
2146 try text_seg.addSection(self.allocator, "__stubs", .{
21472147 .@"align" = alignment,
21482148 .flags = macho.S_SYMBOL_STUBS | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
21492149 .reserved2 = stub_size,
......@@ -2163,7 +2163,7 @@ fn populateMetadata(self: *Zld) !void {
21632163 .aarch64 => 6 * @sizeOf(u32),
21642164 else => unreachable,
21652165 };
2166 try text_seg.addSection(self.allocator, "__stub_helper", "__TEXT", .{
2166 try text_seg.addSection(self.allocator, "__stub_helper", .{
21672167 .size = stub_helper_size,
21682168 .@"align" = alignment,
21692169 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
......@@ -2183,7 +2183,7 @@ fn populateMetadata(self: *Zld) !void {
21832183 if (self.got_section_index == null) {
21842184 const data_const_seg = &self.load_commands.items[self.data_const_segment_cmd_index.?].Segment;
21852185 self.got_section_index = @intCast(u16, data_const_seg.sections.items.len);
2186 try data_const_seg.addSection(self.allocator, "__got", "__DATA_CONST", .{
2186 try data_const_seg.addSection(self.allocator, "__got", .{
21872187 .@"align" = 3, // 2^3 = @sizeOf(u64)
21882188 .flags = macho.S_NON_LAZY_SYMBOL_POINTERS,
21892189 });
......@@ -2202,7 +2202,7 @@ fn populateMetadata(self: *Zld) !void {
22022202 if (self.la_symbol_ptr_section_index == null) {
22032203 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
22042204 self.la_symbol_ptr_section_index = @intCast(u16, data_seg.sections.items.len);
2205 try data_seg.addSection(self.allocator, "__la_symbol_ptr", "__DATA", .{
2205 try data_seg.addSection(self.allocator, "__la_symbol_ptr", .{
22062206 .@"align" = 3, // 2^3 = @sizeOf(u64)
22072207 .flags = macho.S_LAZY_SYMBOL_POINTERS,
22082208 });
......@@ -2211,7 +2211,7 @@ fn populateMetadata(self: *Zld) !void {
22112211 if (self.data_section_index == null) {
22122212 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
22132213 self.data_section_index = @intCast(u16, data_seg.sections.items.len);
2214 try data_seg.addSection(self.allocator, "__data", "__DATA", .{
2214 try data_seg.addSection(self.allocator, "__data", .{
22152215 .@"align" = 3, // 2^3 = @sizeOf(u64)
22162216 });
22172217 }
src/link/MachO/commands.zig+5-4
......@@ -233,12 +233,11 @@ pub const SegmentCommand = struct {
233233 self: *SegmentCommand,
234234 alloc: *Allocator,
235235 comptime sectname: []const u8,
236 comptime segname: []const u8,
237236 opts: SectionOptions,
238237 ) !void {
239 try self.sections.append(alloc, .{
238 var section = macho.section_64{
240239 .sectname = makeStaticString(sectname),
241 .segname = makeStaticString(segname),
240 .segname = undefined,
242241 .addr = opts.addr,
243242 .size = opts.size,
244243 .offset = opts.offset,
......@@ -249,7 +248,9 @@ pub const SegmentCommand = struct {
249248 .reserved1 = opts.reserved1,
250249 .reserved2 = opts.reserved2,
251250 .reserved3 = opts.reserved3,
252 });
251 };
252 mem.copy(u8, &section.segname, &self.inner.segname);
253 try self.sections.append(alloc, section);
253254 self.inner.cmdsize += @sizeOf(macho.section_64);
254255 self.inner.nsects += 1;
255256 }