Skip to content

Commit 5061036

Browse files
committed
[Mach-O] Programmatically construct export trie
1 parent 43e513d commit 5061036

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

macho/output-chunks.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,19 @@ i64 ExportEncoder::set_offset(TrieNode &node, i64 offset) {
539539
return offset;
540540
}
541541

542-
void ExportEncoder::write_trie(u8 *start) {
543-
write_trie(start, root);
542+
void ExportEncoder::write_trie(u8 *buf) {
543+
write_trie(buf, root);
544544
}
545545

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

549549
if (node.is_leaf) {
550550
buf += write_uleb(buf, uleb_size(node.flags) + uleb_size(node.addr));
551551
buf += write_uleb(buf, node.flags);
552552
buf += write_uleb(buf, node.addr);
553553
} else {
554-
*buf++ = 1;
554+
*buf++ = 0;
555555
}
556556

557557
u8 *num_children = buf++;
@@ -573,8 +573,10 @@ void ExportEncoder::write_trie(u8 *start, TrieNode &node) {
573573
OutputExportSection::OutputExportSection(OutputSegment &parent)
574574
: OutputSection(parent) {
575575
is_hidden = true;
576-
enc.add("__mh_execute_header", 0, 0x100000000);
577-
hdr.size = enc.finish();
576+
enc.add("__mh_execute_header", 0, 0);
577+
enc.add("_hello", 0, 0x3f50);
578+
enc.add("_main", 0, 0x3f70);
579+
hdr.size = align_to(enc.finish(), 8);
578580
}
579581

580582
void OutputExportSection::copy_buf(Context &ctx) {

0 commit comments

Comments
 (0)