mirror of
https://github.com/rui314/mold.git
synced 2024-11-13 09:39:13 +03:00
[Mach-O] wip
This commit is contained in:
parent
8124a07e07
commit
81581a475d
@ -156,7 +156,7 @@ void dump_compact_unwind(u8 *buf, MachSection &sec) {
|
||||
<< "\n entry: 0x" << (i * sizeof(CompactUnwindEntry))
|
||||
<< "\n code_start: 0x" << ent[i].code_start
|
||||
<< "\n code_len: 0x" << ent[i].code_len
|
||||
<< "\n compact_unwind_info: 0x" << ent[i].compact_unwind_info
|
||||
<< "\n encoding: 0x" << ent[i].encoding
|
||||
<< "\n personality: 0x" << ent[i].personality
|
||||
<< "\n lsda: 0x" << ent[i].lsda;
|
||||
}
|
||||
|
@ -545,7 +545,7 @@ struct UnwindPageEntry {
|
||||
struct CompactUnwindEntry {
|
||||
u64 code_start;
|
||||
u32 code_len;
|
||||
u32 compact_unwind_info;
|
||||
u32 encoding;
|
||||
u64 personality;
|
||||
u64 lsda;
|
||||
};
|
||||
|
22
macho/mold.h
22
macho/mold.h
@ -32,13 +32,12 @@ struct Relocation {
|
||||
};
|
||||
|
||||
struct UnwindRecord {
|
||||
UnwindRecord(u32 len, u32 info)
|
||||
: code_len(len), compact_unwind_info(info) {}
|
||||
UnwindRecord(u32 len, u32 enc) : code_len(len), encoding(enc) {}
|
||||
|
||||
Subsection *subsec = nullptr;
|
||||
u32 offset = 0;
|
||||
u32 code_len;
|
||||
u32 compact_unwind_info;
|
||||
u32 encoding;
|
||||
Symbol *personality = nullptr;
|
||||
Subsection *lsda = nullptr;
|
||||
u32 lsda_offset = 0;
|
||||
@ -82,7 +81,6 @@ public:
|
||||
std::string_view contents;
|
||||
std::vector<Subsection> subsections;
|
||||
std::vector<Relocation> rels;
|
||||
std::vector<UnwindRecord> unwind_records;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const InputSection &sec);
|
||||
@ -94,7 +92,7 @@ public:
|
||||
}
|
||||
|
||||
std::span<UnwindRecord> get_unwind_records() {
|
||||
return std::span(isec.unwind_records).subspan(unwind_offset, nunwind);
|
||||
return std::span(isec.file.unwind_records).subspan(unwind_offset, nunwind);
|
||||
}
|
||||
|
||||
void apply_reloc(Context &ctx, u8 *buf);
|
||||
@ -401,20 +399,6 @@ public:
|
||||
static constexpr char contents[] = "Hello world\n";
|
||||
};
|
||||
|
||||
class UnwindEncoder {
|
||||
public:
|
||||
void add(UnwindRecord &rec);
|
||||
void finish();
|
||||
|
||||
std::vector<u8> buf;
|
||||
|
||||
private:
|
||||
i64 get_personality(Context &ctx, Relocation &rel);
|
||||
|
||||
std::unordered_map<u32, u32> encodings;
|
||||
std::vector<Relocation> personalities;
|
||||
};
|
||||
|
||||
class UnwindInfoSection : public Chunk {
|
||||
public:
|
||||
UnwindInfoSection();
|
||||
|
@ -79,7 +79,7 @@ void ObjectFile::parse_compact_unwind(Context &ctx, MachSection &hdr) {
|
||||
// Read compact unwind entries
|
||||
for (i64 i = 0; i < num_entries; i++) {
|
||||
CompactUnwindEntry &src = ((CompactUnwindEntry *)mf->data)[i];
|
||||
unwind_records.emplace_back(src.code_len, src.compact_unwind_info);
|
||||
unwind_records.emplace_back(src.code_len, src.encoding);
|
||||
}
|
||||
|
||||
// Read relocations
|
||||
|
@ -719,48 +719,22 @@ UnwindInfoSection::UnwindInfoSection() {
|
||||
hdr.size = contents.size();
|
||||
}
|
||||
|
||||
void UnwindEncoder::add(UnwindRecord &rec) {
|
||||
}
|
||||
|
||||
void UnwindEncoder::finish() {
|
||||
}
|
||||
|
||||
i64 UnwindEncoder::get_personality(Context &ctx, Relocation &rel) {
|
||||
if (!rel.sym && !rel.subsec)
|
||||
return 0;
|
||||
|
||||
if (rel.sym) {
|
||||
for (i64 i = 0; i < personalities.size(); i++) {
|
||||
Relocation &p = personalities[i];
|
||||
if (p.sym == rel.sym && p.addend == rel.addend)
|
||||
return i + 1;
|
||||
}
|
||||
} else {
|
||||
for (i64 i = 0; i < personalities.size(); i++) {
|
||||
Relocation &p = personalities[i];
|
||||
if (p.subsec == rel.subsec && p.addend == rel.addend)
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (personalities.size() == 3)
|
||||
Fatal(ctx) << "too many personality functions";
|
||||
personalities.push_back(rel);
|
||||
return personalities.size();
|
||||
static std::vector<u8>
|
||||
encode_unwind_info(Context &ctx, std::span<UnwindRecord> records) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::vector<u8> construct_unwind_info(Context &ctx) {
|
||||
UnwindEncoder enc;
|
||||
std::vector<UnwindRecord> vec;
|
||||
|
||||
for (OutputSegment *seg : ctx.segments)
|
||||
for (Chunk *chunk : seg->chunks)
|
||||
if (chunk->is_regular)
|
||||
for (Subsection *subsec : ((OutputSection *)chunk)->members)
|
||||
for (UnwindRecord &rec : subsec->get_unwind_records())
|
||||
enc.add(rec);
|
||||
vec.push_back(rec);
|
||||
|
||||
enc.finish();
|
||||
return std::move(enc.buf);
|
||||
return encode_unwind_info(ctx, vec);
|
||||
}
|
||||
|
||||
void UnwindInfoSection::compute_size(Context &ctx) {
|
||||
|
Loading…
Reference in New Issue
Block a user