1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-10 19:26:38 +03:00

[Mach-O] wip

This commit is contained in:
Rui Ueyama 2021-09-16 19:26:49 +09:00
parent bfdf9ecf7b
commit 7bab3aa994
3 changed files with 52 additions and 0 deletions

View File

@ -23,6 +23,8 @@ void create_synthetic_sections(Context &ctx) {
add(ctx.data_const_segment =
std::make_unique<OutputSegment>("__DATA_CONST", VM_PROT_READ | VM_PROT_WRITE,
SG_READ_ONLY));
add(ctx.data_segment =
std::make_unique<OutputSegment>("__DATA", VM_PROT_READ | VM_PROT_WRITE, 0));
TextSection *text_sec = new TextSection(*ctx.text_segment);
ctx.text_segment->sections.push_back(text_sec);
@ -43,6 +45,14 @@ void create_synthetic_sections(Context &ctx) {
GotSection *got_sec = new GotSection(*ctx.data_const_segment);
ctx.data_const_segment->sections.push_back(got_sec);
ctx.sections.emplace_back(got_sec);
LaSymbolPtrSection *la_sec = new LaSymbolPtrSection(*ctx.data_segment);
ctx.data_segment->sections.push_back(la_sec);
ctx.sections.emplace_back(la_sec);
DataSection *data_sec = new DataSection(*ctx.data_segment);
ctx.data_segment->sections.push_back(data_sec);
ctx.sections.emplace_back(data_sec);
}
void compute_chunk_sizes(Context &ctx) {

View File

@ -130,6 +130,22 @@ public:
static constexpr char contents[] = "Hello world\n";
};
class LaSymbolPtrSection : public OutputSection {
public:
LaSymbolPtrSection(OutputSegment &parent);
void copy_buf(Context &ctx) override;
std::vector<u8> contents;
};
class DataSection : public OutputSection {
public:
DataSection(OutputSegment &parent);
void copy_buf(Context &ctx) override;
std::vector<u8> contents;
};
//
// output-file.cc
//
@ -183,6 +199,7 @@ struct Context {
std::unique_ptr<OutputPageZero> zero_page;
std::unique_ptr<OutputSegment> text_segment;
std::unique_ptr<OutputSegment> data_const_segment;
std::unique_ptr<OutputSegment> data_segment;
std::vector<Chunk *> chunks;
std::vector<std::unique_ptr<OutputSection>> sections;

View File

@ -174,4 +174,29 @@ GotSection::GotSection(OutputSegment &parent)
hdr.size = 8;
}
LaSymbolPtrSection::LaSymbolPtrSection(OutputSegment &parent)
: OutputSection(parent, "__la_symbol_ptr") {
hdr.p2align = __builtin_ctz(8);
hdr.type = S_LAZY_SYMBOL_POINTERS;
contents = {0x94, 0x3f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
hdr.size = contents.size();
}
void LaSymbolPtrSection::copy_buf(Context &ctx) {
write_vector(ctx.buf + parent.fileoff + hdr.offset, contents);
}
DataSection::DataSection(OutputSegment &parent)
: OutputSection(parent, "__data") {
hdr.p2align = __builtin_ctz(8);
hdr.type = S_LAZY_SYMBOL_POINTERS;
contents.resize(8);
hdr.size = contents.size();
}
void DataSection::copy_buf(Context &ctx) {
write_vector(ctx.buf + parent.fileoff + hdr.offset, contents);
}
} // namespace mold::macho