1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-14 07:18:42 +03:00

[Mach-O] wip

This commit is contained in:
Rui Ueyama 2021-10-04 17:29:44 +09:00
parent fd62bbfacb
commit 89d5e9e3b4
3 changed files with 12 additions and 0 deletions

View File

@ -64,6 +64,10 @@ static void export_symbols(Context &ctx) {
}
static i64 assign_offsets(Context &ctx) {
for (OutputSegment *seg : ctx.segments)
for (Chunk *chunk : seg->chunks)
chunk->compute_size();
i64 fileoff = 0;
i64 vmaddr = PAGE_ZERO_SIZE;

View File

@ -103,6 +103,7 @@ public:
class Chunk {
public:
virtual ~Chunk() = default;
virtual void compute_size() {};
virtual void copy_buf(Context &ctx) {}
MachSection hdr = {};
@ -138,6 +139,7 @@ private:
class OutputSection : public Chunk {
public:
OutputSection(std::string_view name);
void compute_size() override;
std::vector<Subsection *> members;
};

View File

@ -235,6 +235,12 @@ OutputSection::OutputSection(std::string_view name) {
memcpy(hdr.segname, name.data(), name.size());
}
void OutputSection::compute_size() {
hdr.size = 0;
for (Subsection *subsec : members)
hdr.size += subsec->input_size;
}
OutputSegment::OutputSegment(std::string_view name, u32 prot, u32 flags) {
assert(name.size() <= sizeof(cmd.segname));