mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 09:57:18 +03:00
[Mach-O] wip
This commit is contained in:
parent
a861f192ec
commit
46d3e12946
@ -26,11 +26,11 @@ Subsection *InputSection::find_subsection(Context &ctx, u32 addr) {
|
||||
return &*(it - 1);
|
||||
}
|
||||
|
||||
static u64 read_addend(u8 *buf, u32 offset, u32 p2size) {
|
||||
static i64 read_addend(u8 *buf, u32 offset, u32 p2size) {
|
||||
switch (p2size) {
|
||||
case 0: return buf[offset];
|
||||
case 1: return *(u16 *)(buf + offset);
|
||||
case 2: return *(u32 *)(buf + offset);
|
||||
case 0: return *(i8 *)(buf + offset);
|
||||
case 1: return *(i16 *)(buf + offset);
|
||||
case 2: return *(i32 *)(buf + offset);
|
||||
case 3: return *(i64 *)(buf + offset);
|
||||
}
|
||||
unreachable();
|
||||
@ -42,7 +42,7 @@ void InputSection::parse_relocations(Context &ctx) {
|
||||
MachRel *rel = (MachRel *)(file.mf->data + hdr.reloff);
|
||||
for (i64 i = 0; i < hdr.nreloc; i++) {
|
||||
MachRel &r = rel[i];
|
||||
u64 addend = read_addend((u8 *)contents.data(), r.offset, r.p2size);
|
||||
i64 addend = read_addend((u8 *)contents.data(), r.offset, r.p2size);
|
||||
|
||||
if (r.is_extern) {
|
||||
rels.push_back({r.offset, addend, file.syms[r.idx], nullptr});
|
||||
|
@ -42,7 +42,7 @@ std::ostream &operator<<(std::ostream &out, const ObjectFile &file);
|
||||
|
||||
struct Relocation {
|
||||
u32 offset = 0;
|
||||
u64 addend = 0;
|
||||
i64 addend = 0;
|
||||
Symbol *sym = nullptr;
|
||||
Subsection *subsec = nullptr;
|
||||
};
|
||||
|
@ -54,8 +54,12 @@ void ObjectFile::parse(Context &ctx) {
|
||||
p += lc.cmdsize;
|
||||
}
|
||||
|
||||
for (std::unique_ptr<InputSection> &sec : sections)
|
||||
for (std::unique_ptr<InputSection> &sec : sections) {
|
||||
sec->parse_relocations(ctx);
|
||||
for (Relocation &rel : sec->rels)
|
||||
SyncOut(ctx) << *sec << ": " << rel.offset << " " << rel.addend
|
||||
<< " " << rel.sym << " " << rel.subsec;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mold::macho
|
||||
|
Loading…
Reference in New Issue
Block a user