1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-14 07:18:42 +03:00

[Mach-O] wip

This commit is contained in:
Rui Ueyama 2021-11-18 21:31:27 +09:00
parent 39676ef7a9
commit 1e4262753a
2 changed files with 11 additions and 6 deletions

View File

@ -46,6 +46,14 @@ static Relocation read_reloc(Context &ctx, ObjectFile &file,
if (r.p2size != 2 && r.p2size != 3)
Fatal(ctx) << file << ": invalid r.p2size: " << (u32)r.p2size;
if (r.is_pcrel) {
if (r.p2size != 2)
Fatal(ctx) << file << ": invalid PC-relative reloc: " << r.offset;
} else {
if (r.p2size != 3)
Fatal(ctx) << file << ": invalid non-PC-relative reloc: " << r.offset;
}
u8 *buf = (u8 *)file.mf->data + hdr.offset;
Relocation rel{r.offset, (u8)r.type, (u8)r.p2size, (bool)r.is_pcrel};
i64 addend = read_addend(buf, r);
@ -57,13 +65,10 @@ static Relocation read_reloc(Context &ctx, ObjectFile &file,
}
u32 addr;
if (r.is_pcrel) {
if (r.p2size != 2)
Fatal(ctx) << file << ": invalid PC-relative reloc: " << r.offset;
if (r.is_pcrel)
addr = hdr.addr + r.offset + 4 + addend;
} else {
else
addr = addend;
}
Subsection *target = file.find_subsection(ctx, addr);
if (!target)

View File

@ -506,7 +506,7 @@ void OutputRebaseSection::compute_size(Context &ctx) {
if (chunk->is_regular)
for (Subsection *subsec : ((OutputSection *)chunk)->members)
for (Relocation &rel : subsec->get_rels())
if (!rel.is_pcrel && rel.p2size == 3)
if (!rel.is_pcrel)
enc.add(seg->seg_idx,
subsec->get_addr(ctx) + rel.offset - seg->cmd.vmaddr);