From 5061036e7e24d19c62bdc713990d460dc6e4dc43 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 19 Sep 2021 19:48:16 +0900 Subject: [PATCH] [Mach-O] Programmatically construct export trie --- macho/output-chunks.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/macho/output-chunks.cc b/macho/output-chunks.cc index 7a657047d0..f506d50ce0 100644 --- a/macho/output-chunks.cc +++ b/macho/output-chunks.cc @@ -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++; @@ -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) {