mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 01:47:11 +03:00
[Mach-O] wip
This commit is contained in:
parent
4ab5e09974
commit
369c19fdf6
@ -78,32 +78,32 @@ void dump_unwind_info(u8 *buf, MachSection &sec) {
|
||||
<< "\n encoding_count: 0x" << hdr.encoding_count
|
||||
<< "\n personality_offset: 0x" << hdr.personality_offset
|
||||
<< "\n personality_count: 0x" << hdr.personality_count
|
||||
<< "\n index_offset: 0x" << hdr.index_offset
|
||||
<< "\n index_count: 0x" << hdr.index_count;
|
||||
<< "\n page_offset: 0x" << hdr.page_offset
|
||||
<< "\n page_count: 0x" << hdr.page_count;
|
||||
|
||||
u32 *enc = (u32 *)(buf + sec.offset + hdr.encoding_offset);
|
||||
std::cout << "\n encoding:";
|
||||
for (i64 i = 0; i < hdr.encoding_count; i++)
|
||||
std::cout << std::hex << "\n 0x" << enc[i];
|
||||
|
||||
UnwindIndexEntry *ent =
|
||||
(UnwindIndexEntry *)(buf + sec.offset + hdr.index_offset);
|
||||
UnwindFirstLevelPage *ent =
|
||||
(UnwindFirstLevelPage *)(buf + sec.offset + hdr.page_offset);
|
||||
|
||||
for (i64 i = 0; i < hdr.index_count; i++) {
|
||||
for (i64 i = 0; i < hdr.page_count; i++) {
|
||||
std::cout << std::hex << "\n function:"
|
||||
<< "\n func_offset: 0x" << ent[i].func_offset
|
||||
<< "\n func_addr: 0x" << ent[i].func_addr
|
||||
<< "\n page_offset: 0x" << ent[i].page_offset
|
||||
<< "\n lsda_offset: 0x" << ent[i].lsda_offset;
|
||||
|
||||
if (i != hdr.index_count - 1) {
|
||||
if (i != hdr.page_count - 1) {
|
||||
UnwindLsdaEntry *lsda =
|
||||
(UnwindLsdaEntry *)(buf + sec.offset + ent[i].lsda_offset);
|
||||
i64 lsda_size = ent[i + 1].lsda_offset - ent[i].lsda_offset;
|
||||
for (i64 j = 0; j < lsda_size / sizeof(UnwindLsdaEntry); j++)
|
||||
std::cout << std::hex
|
||||
<< "\n lsda:"
|
||||
<< "\n func_offset: 0x" << lsda[j].func_offset
|
||||
<< "\n lsda_offset: 0x" << lsda[j].lsda_offset;
|
||||
<< "\n func_addr: 0x" << lsda[j].func_addr
|
||||
<< "\n lsda_addr: 0x" << lsda[j].lsda_addr;
|
||||
}
|
||||
|
||||
if (ent[i].page_offset == 0)
|
||||
@ -118,7 +118,7 @@ void dump_unwind_info(u8 *buf, MachSection &sec) {
|
||||
}
|
||||
case UNWIND_SECOND_LEVEL_COMPRESSED: {
|
||||
std::cout << "\n UNWIND_SECOND_LEVEL_COMPRESSED" ;
|
||||
UnwindPageHeader &hdr2 = *(UnwindPageHeader *)addr;
|
||||
UnwindSecondLevelPage &hdr2 = *(UnwindSecondLevelPage *)addr;
|
||||
std::cout << std::hex
|
||||
<< "\n page_offset: 0x" << hdr2.page_offset
|
||||
<< "\n page_count: 0x" << hdr2.page_count
|
||||
@ -128,7 +128,7 @@ void dump_unwind_info(u8 *buf, MachSection &sec) {
|
||||
UnwindPageEntry *ent2 = (UnwindPageEntry *)(addr + hdr2.page_offset);
|
||||
for (i64 j = 0; j < hdr2.page_count; j++)
|
||||
std::cout << std::hex << "\n ent 0x"
|
||||
<< (ent[i].func_offset + ent2[j].func_offset)
|
||||
<< (ent[i].func_addr + ent2[j].func_addr)
|
||||
<< " 0x" << ent2[j].encoding;
|
||||
|
||||
u32 *enc = (u32 *)(addr + hdr2.encoding_offset);
|
||||
|
@ -511,22 +511,17 @@ struct UnwindSectionHeader {
|
||||
u32 encoding_count;
|
||||
u32 personality_offset;
|
||||
u32 personality_count;
|
||||
u32 index_offset;
|
||||
u32 index_count;
|
||||
u32 page_offset;
|
||||
u32 page_count;
|
||||
};
|
||||
|
||||
struct UnwindIndexEntry {
|
||||
u32 func_offset;
|
||||
struct UnwindFirstLevelPage {
|
||||
u32 func_addr;
|
||||
u32 page_offset;
|
||||
u32 lsda_offset;
|
||||
};
|
||||
|
||||
struct UnwindLsdaEntry {
|
||||
u32 func_offset;
|
||||
u32 lsda_offset;
|
||||
};
|
||||
|
||||
struct UnwindPageHeader {
|
||||
struct UnwindSecondLevelPage {
|
||||
u32 kind;
|
||||
u16 page_offset;
|
||||
u16 page_count;
|
||||
@ -534,8 +529,13 @@ struct UnwindPageHeader {
|
||||
u16 encoding_count;
|
||||
};
|
||||
|
||||
struct UnwindLsdaEntry {
|
||||
u32 func_addr;
|
||||
u32 lsda_addr;
|
||||
};
|
||||
|
||||
struct UnwindPageEntry {
|
||||
u32 func_offset : 24;
|
||||
u32 func_addr : 24;
|
||||
u32 encoding : 8;
|
||||
};
|
||||
|
||||
|
@ -740,7 +740,7 @@ void UnwindEncoder::finish(Context &ctx) {
|
||||
i64 size = sizeof(UnwindSectionHeader) +
|
||||
personalities.size() * 4 +
|
||||
num_lsda * sizeof(UnwindLsdaEntry) +
|
||||
pages.size() * sizeof(UnwindPageHeader) +
|
||||
pages.size() * sizeof(UnwindSecondLevelPage) +
|
||||
records.size() * 4;
|
||||
|
||||
buf.resize(size);
|
||||
@ -752,8 +752,8 @@ void UnwindEncoder::finish(Context &ctx) {
|
||||
hdr.encoding_count = 0;
|
||||
hdr.personality_offset = sizeof(hdr);
|
||||
hdr.personality_count = personalities.size();
|
||||
hdr.index_offset = sizeof(hdr) + personalities.size() * 4;
|
||||
hdr.index_count = pages.size();
|
||||
hdr.page_offset = sizeof(hdr) + personalities.size() * 4;
|
||||
hdr.page_count = pages.size();
|
||||
|
||||
// Write the personalities
|
||||
u32 *per = (u32 *)(buf.data() + sizeof(hdr));
|
||||
@ -761,9 +761,9 @@ void UnwindEncoder::finish(Context &ctx) {
|
||||
*per++ = sym->get_addr(ctx);
|
||||
|
||||
// Write first level pages, LSDA and second level pages
|
||||
UnwindIndexEntry *page1 = (UnwindIndexEntry *)per;
|
||||
UnwindFirstLevelPage *page1 = (UnwindFirstLevelPage *)per;
|
||||
UnwindLsdaEntry *lsda = (UnwindLsdaEntry *)(page1 + pages.size());
|
||||
UnwindPageHeader *page2 = (UnwindPageHeader *)(lsda + num_lsda);
|
||||
UnwindSecondLevelPage *page2 = (UnwindSecondLevelPage *)(lsda + num_lsda);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user