| ... | @@ -1476,6 +1476,17 @@ pub const Zld = struct { | ... | @@ -1476,6 +1476,17 @@ pub const Zld = struct { |
| 1476 | }); | 1476 | }); |
| 1477 | } | 1477 | } |
| 1478 | | 1478 | |
| | 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 section | 1491 | if (header.size == 0) continue; // empty section |
| 1481 | | 1492 | |
| ... | @@ -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 | } |
| 1500 | | 1511 | |
| | 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 | }); |