diff --git a/macho/input-sections.cc b/macho/input-sections.cc index 4d12102c..6d60e8ca 100644 --- a/macho/input-sections.cc +++ b/macho/input-sections.cc @@ -6,6 +6,14 @@ InputSection::InputSection(Context &ctx, ObjectFile &file, const MachSection &hd : file(file), hdr(hdr) { contents = file.mf->get_contents().substr(hdr.offset, hdr.size); subsections.push_back({*this, 0, (u32)contents.size()}); + + rels.reserve(hdr.nreloc); + + MachRel *rel = (MachRel *)(file.mf->data + hdr.reloff); + for (i64 i = 0; i < hdr.nreloc; i++) { + MachRel r = rel[i]; + rels.push_back({r.offset, r.type}); + } } } // namespace mold::macho diff --git a/macho/mold.h b/macho/mold.h index 4e54c823..4d910ba2 100644 --- a/macho/mold.h +++ b/macho/mold.h @@ -39,11 +39,11 @@ std::ostream &operator<<(std::ostream &out, const ObjectFile &file); // struct Relocation { - u32 offset; - u32 type; - Symbol *sym; - Subsection *subsec; - u64 addend; + u32 offset = 0; + u32 type = 0; + Symbol *sym = nullptr; + Subsection *subsec = nullptr; + u64 addend = 0; }; class InputSection {