Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions libwild/src/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ const LE: Endianness = Endianness::Little;
/// offsets right after that (1GiB).
pub(crate) const MACHO_START_MEM_ADDRESS: u64 = 0x1_0000_0000;

/// The command alignment is 8B for 64-bit platforms.
pub(crate) const MACHO_COMMAND_ALIGNMENT: usize = 8;

/// A path to the default dynamic linker.
pub(crate) const DYLINKER_PATH: &str = "/usr/lib/dyld";
pub(crate) const DYLINKER_PATH: &[u8] = b"/usr/lib/dyld";
pub(crate) const DEFAULT_SEGMENT_COUNT: usize = 4;
pub(crate) const CHAINED_FIXUP_TABLE_SIZE: u64 =
(size_of::<ChainedFixupsHeader>() + size_of::<u32>() * (DEFAULT_SEGMENT_COUNT + 1 + 1)) as u64;
Expand Down Expand Up @@ -729,9 +732,7 @@ impl platform::ProgramSegmentDef for ProgramSegmentDef {
| output_section_id::DYLD_CHAINED_FIXUPS => SegmentType::LoadCommands,
output_section_id::TEXT | output_section_id::CSTRING => SegmentType::TextSections,
output_section_id::DATA => SegmentType::DataSections,
output_section_id::CHAINED_FIXUP_TABLE | output_section_id::STRTAB => {
SegmentType::LinkeditSections
}
output_section_id::CHAINED_FIXUP_TABLE => SegmentType::LinkeditSections,
_ => SegmentType::Unused,
};

Expand Down Expand Up @@ -1167,7 +1168,8 @@ impl platform::Platform for MachO {
sizes.increment(part_id::ENTRY_POINT, size_of::<EntryPointCommand>() as u64);
sizes.increment(
part_id::INTERP,
((size_of::<DylinkerCommand>() + DYLINKER_PATH.len()).next_multiple_of(8)) as u64,
((size_of::<DylinkerCommand>() + DYLINKER_PATH.len())
.next_multiple_of(MACHO_COMMAND_ALIGNMENT)) as u64,
);
sizes.increment(
part_id::DYLD_CHAINED_FIXUPS,
Expand Down Expand Up @@ -1228,12 +1230,6 @@ impl platform::Platform for MachO {
symbol_db: &crate::symbol_db::SymbolDb<Self>,
) {
common.allocate(part_id::CHAINED_FIXUP_TABLE, CHAINED_FIXUP_TABLE_SIZE);
// TODO: Just a filler for now that will ensure the __LINKEDIT takes 16KiB - find a better
// solution.
common.allocate(
part_id::STRTAB,
MACHO_PAGE_ALIGNMENT.value() - CHAINED_FIXUP_TABLE_SIZE,
);
}

fn finalise_prelude_layout<'data>(
Expand Down Expand Up @@ -1292,7 +1288,6 @@ impl platform::Platform for MachO {
builder.add_section(output_section_id::CSTRING);
builder.add_section(output_section_id::DATA);
// The rest (e.g. symbol table, string table).
builder.add_section(output_section_id::STRTAB);
builder.add_section(output_section_id::CHAINED_FIXUP_TABLE);

builder.build()
Expand Down Expand Up @@ -1381,11 +1376,6 @@ const SECTION_DEFINITIONS: [BuiltInSectionDetails; NUM_BUILT_IN_SECTIONS] = {
target_segment_type: Some(SegmentType::LinkeditSections),
..DEFAULT_DEFS
};
defs[output_section_id::STRTAB.as_usize()] = BuiltInSectionDetails {
kind: SectionKind::Primary(SectionName(b"STRING_TABLE")),
target_segment_type: Some(SegmentType::LinkeditSections),
..DEFAULT_DEFS
};
// Multi-part generated sections
defs[output_section_id::SYMTAB_GLOBAL.as_usize()] = BuiltInSectionDetails {
kind: SectionKind::Secondary(output_section_id::SYMTAB_LOCAL),
Expand Down
Loading
Loading