1
1
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:
Rui Ueyama 2021-09-16 14:49:50 +09:00
parent 7232178513
commit 5e83481ffb
3 changed files with 20 additions and 5 deletions

View File

@ -18,6 +18,12 @@ void create_synthetic_sections(Context &ctx) {
add(ctx.mach_hdr = std::make_unique<OutputMachHeader>());
add(ctx.load_cmd = std::make_unique<OutputLoadCommand>());
add(ctx.zero_page = std::make_unique<OutputPageZero>());
add(ctx.text_segment =
std::make_unique<OutputSegment>("__TEXT", VM_PROT_READ | VM_PROT_EXECUTE, 0));
TextSection *text_sec = new TextSection(*ctx.text_segment);
ctx.text_segment->sections.push_back(text_sec);
ctx.sections.emplace_back(text_sec);
}
void compute_chunk_sizes(Context &ctx) {

View File

@ -81,11 +81,11 @@ public:
virtual void update_hdr(Context &ctx) {}
virtual void copy_buf(Context &ctx) {}
protected:
OutputSection(OutputSegment &parent, std::string_view name);
MachSection hdr = {};
OutputSegment &parent;
protected:
OutputSection(OutputSegment &parent, std::string_view name);
};
class TextSection : public OutputSection {
@ -148,7 +148,10 @@ struct Context {
std::unique_ptr<OutputMachHeader> mach_hdr;
std::unique_ptr<OutputLoadCommand> load_cmd;
std::unique_ptr<OutputPageZero> zero_page;
std::unique_ptr<OutputSegment> text_segment;
std::vector<Chunk *> chunks;
std::vector<std::unique_ptr<OutputSection>> sections;
};
int main(int argc, char **argv);

View File

@ -69,8 +69,14 @@ void OutputSegment::update_hdr(Context &ctx) {
cmd.cmdsize = sizeof(SegmentCommand) + sizeof(MachSection) * sections.size();
cmd.nsects = sections.size();
for (OutputSection *sec : sections)
sec->update_hdr(ctx);
load_cmd.resize(sizeof(cmd) + sizeof(MachSection) * sections.size());
MachSection *hdrs = (MachSection *)(load_cmd.data() + sizeof(cmd));
for (i64 i = 0; i < sections.size(); i++) {
OutputSection &sec = *sections[i];
sec.update_hdr(ctx);
hdrs[i] = sec.hdr;
}
}
void OutputSegment::copy_buf(Context &ctx) {