diff --git a/macho/main.cc b/macho/main.cc index 73410414..0a3446e1 100644 --- a/macho/main.cc +++ b/macho/main.cc @@ -539,9 +539,13 @@ static void copy_sections_to_output_file(Context &ctx) { [&](std::unique_ptr> &seg) { Timer t2(ctx, std::string(seg->cmd.get_segname()), &t); - // Fill text segment paddings with NOPs - if (seg->cmd.get_segname() == "__TEXT") - memset(ctx.buf + seg->cmd.fileoff, 0x90, seg->cmd.filesize); + // Fill text segment paddings with single-byte NOP instructions so + // that otool wouldn't out-of-sync when disassembling an output file. + // Do this only for x86-64 because ARM64 instructions are always 4 + // bytes long. + if constexpr (std::is_same_v) + if (seg->cmd.get_segname() == "__TEXT") + memset(ctx.buf + seg->cmd.fileoff, 0x90, seg->cmd.filesize); tbb::parallel_for_each(seg->chunks, [&](Chunk *sec) { if (sec->hdr.type != S_ZEROFILL) {