Skip to content

Commit

Permalink
[Mach-O] Programmatically construct export trie
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 19, 2021
1 parent 43e513d commit 5061036
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions macho/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,19 @@ i64 ExportEncoder::set_offset(TrieNode &node, i64 offset) {
return offset;
}

void ExportEncoder::write_trie(u8 *start) {
write_trie(start, root);
void ExportEncoder::write_trie(u8 *buf) {
write_trie(buf, root);
}

void ExportEncoder::write_trie(u8 *start, TrieNode &node) {
u8 *buf = start;
u8 *buf = start + node.offset;

if (node.is_leaf) {
buf += write_uleb(buf, uleb_size(node.flags) + uleb_size(node.addr));
buf += write_uleb(buf, node.flags);
buf += write_uleb(buf, node.addr);
} else {
*buf++ = 1;
*buf++ = 0;
}

u8 *num_children = buf++;
Expand All @@ -573,8 +573,10 @@ void ExportEncoder::write_trie(u8 *start, TrieNode &node) {
OutputExportSection::OutputExportSection(OutputSegment &parent)
: OutputSection(parent) {
is_hidden = true;
enc.add("__mh_execute_header", 0, 0x100000000);
hdr.size = enc.finish();
enc.add("__mh_execute_header", 0, 0);
enc.add("_hello", 0, 0x3f50);
enc.add("_main", 0, 0x3f70);
hdr.size = align_to(enc.finish(), 8);
}

void OutputExportSection::copy_buf(Context &ctx) {
Expand Down

0 comments on commit 5061036

Please sign in to comment.