authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-10-19 17:33:30+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-10-22 07:59:23+02:00
log33d1942f2772af525ca46fa13d5a8719be9a7fb9
treeca02bcdf72ead93bc684f038bac6003169119fac
parente70adc7f1ae2160e9adf418c66a5f5b9e219810c

macho: always create __TEXT segment


1 files changed, 12 insertions(+), 3 deletions(-)

src/link/MachO/zld.zig+12-3
...@@ -1476,6 +1476,17 @@ pub const Zld = struct {...@@ -1476,6 +1476,17 @@ pub const Zld = struct {
1476 });1476 });
1477 }1477 }
14781478
1479 // __TEXT segment is non-optional
1480 {
1481 const protection = getSegmentMemoryProtection("__TEXT");
1482 try self.segments.append(self.gpa, .{
1483 .cmdsize = @sizeOf(macho.segment_command_64),
1484 .segname = makeStaticString("__TEXT"),
1485 .maxprot = protection,
1486 .initprot = protection,
1487 });
1488 }
1489
1479 for (self.sections.items(.header)) |header, sect_id| {1490 for (self.sections.items(.header)) |header, sect_id| {
1480 if (header.size == 0) continue; // empty section1491 if (header.size == 0) continue; // empty section
14811492
...@@ -1498,14 +1509,12 @@ pub const Zld = struct {...@@ -1498,14 +1509,12 @@ pub const Zld = struct {
1498 self.sections.items(.segment_index)[sect_id] = segment_id;1509 self.sections.items(.segment_index)[sect_id] = segment_id;
1499 }1510 }
15001511
1512 // __LINKEDIT always comes last
1501 {1513 {
1502 const protection = getSegmentMemoryProtection("__LINKEDIT");1514 const protection = getSegmentMemoryProtection("__LINKEDIT");
1503 const base = self.getSegmentAllocBase(@intCast(u8, self.segments.items.len));
1504 try self.segments.append(self.gpa, .{1515 try self.segments.append(self.gpa, .{
1505 .cmdsize = @sizeOf(macho.segment_command_64),1516 .cmdsize = @sizeOf(macho.segment_command_64),
1506 .segname = makeStaticString("__LINKEDIT"),1517 .segname = makeStaticString("__LINKEDIT"),
1507 .vmaddr = base.vmaddr,
1508 .fileoff = base.fileoff,
1509 .maxprot = protection,1518 .maxprot = protection,
1510 .initprot = protection,1519 .initprot = protection,
1511 });1520 });