1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 18:08:01 +03:00

[Mach-O] wip

This commit is contained in:
Rui Ueyama 2021-10-14 20:54:28 +09:00
parent 4fee9df38d
commit e218692672
3 changed files with 32 additions and 9 deletions

View File

@ -38,11 +38,10 @@ static void create_synthetic_chunks(Context &ctx) {
ctx.padding.hdr.size = 14808;
OutputSection *text = new OutputSection("__text");
text->hdr.attr = S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS;
text->hdr.p2align = 4;
add_section(ctx, *text, "__TEXT", "__text");
ctx.text_seg.chunks.push_back(text);
ctx.text.hdr.attr = S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS;
ctx.text.hdr.p2align = 4;
add_section(ctx, ctx.text, "__TEXT", "__text");
ctx.text_seg.chunks.push_back(&ctx.text);
ctx.text_seg.chunks.push_back(&ctx.stubs);
ctx.text_seg.chunks.push_back(&ctx.stub_helper);

View File

@ -303,14 +303,12 @@ class OutputFunctionStartsSection : public Chunk {
public:
OutputFunctionStartsSection() {
is_hidden = true;
hdr.size = contents.size();
}
void compute_size(Context &ctx) override;
void copy_buf(Context &ctx) override;
std::vector<u8> contents = {
0xd0, 0x7e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00
};
std::vector<u8> contents;
};
class OutputSymtabSection : public Chunk {
@ -519,6 +517,7 @@ struct Context {
OutputSymtabSection symtab;
OutputIndirectSymtabSection indir_symtab;
OutputStrtabSection strtab;
OutputSection text{"__text"};
std::vector<OutputSegment *> segments;
};

View File

@ -544,6 +544,31 @@ void OutputExportSection::copy_buf(Context &ctx) {
enc.write_trie(ctx.buf + hdr.offset);
}
void OutputFunctionStartsSection::compute_size(Context &ctx) {
std::vector<u64> addrs;
for (ObjectFile *obj : ctx.objs)
for (Symbol *sym : obj->syms)
if (sym->file == obj)
if (sym->subsec->isec.osec == &ctx.text)
addrs.push_back(sym->get_addr(ctx));
std::sort(addrs.begin(), addrs.end());
contents.resize(addrs.size() * 5);
u8 *p = contents.data();
u64 last = PAGE_ZERO_SIZE;
for (u64 val : addrs) {
p += write_uleb(p, val - last);
last = val;
}
hdr.size = p - contents.data();
contents.resize(hdr.size);
}
void OutputFunctionStartsSection::copy_buf(Context &ctx) {
write_vector(ctx.buf + hdr.offset, contents);
}