mold icon indicating copy to clipboard operation
mold copied to clipboard

[Mach-O] Match block and page size in code directory blob

Open kubkon opened this issue 2 years ago • 4 comments

While setting the BLOCK_SIZE to 0x2000 does indeed cause a kernel panic (still not fixed in Monterey, verified a minute ago), setting it to page size used by macOS with arm64 (i.e., 16KB), works just fine. I'm also happy to report that this has done in Zig's in-house linker for a few releases now, and we had no reports of spurious crashes or kernel panics.

I don't really have any pre-compiled, large projects to check if this makes a huge difference to startup times and doesn't require the startup trick introduced in f3e1f728d3a307c8269c6aeab926310580c7590f; however, it definitely does reduce the binary bloat, even for small programs. The biggest gains will be for large programs however when the program spans multiple page sizes on disk.

Some example numbers:

test/macho/hello.sh

BEFORE: 50144 bytes
AFTER: 49856 bytes

kubkon avatar Jun 08 '22 06:06 kubkon

I'm looking at the test failure, and it seems to me that the code signature injected for x86_64-macos, which shouldn't be the case.

kubkon avatar Jun 08 '22 08:06 kubkon

I'm looking at the test failure, and it seems to me that the code signature injected for x86_64-macos, which shouldn't be the case.

I was thinking about the failure some more, and if mold embeds a code signature for x86_64-macos, I'd suggest making block size architecture dependent where it matches the architecture's page size. What do you think @rui314?

kubkon avatar Jun 09 '22 07:06 kubkon

Maybe write this as 16 * 1024 so nobody has to go through any mental gymnastics to interpret 0x4000 (not everyone thinks in hex so readily).

Hmm if we are set on not using hex at all, I think it would make more sense to write it as 4 * 4096 to emphasise that the block size == page size on arm64-macos (and make it immediately comparable to x86_64-macos where this would be 4096).

kubkon avatar Jun 09 '22 07:06 kubkon

I'm looking at the test failure, and it seems to me that the code signature injected for x86_64-macos, which shouldn't be the case.

I was thinking about the failure some more, and if mold embeds a code signature for x86_64-macos, I'd suggest making block size architecture dependent where it matches the architecture's page size. What do you think @rui314?

I think we need to do that so that this change wouldn’t break the x86 CI.

BESIDES THAT, can you read CONTRIBUTING.md and add a signed-off-by line to this patch?

rui314 avatar Jun 09 '22 22:06 rui314

Sorry I didn't follow this one through! Closing as MachO is now part of sold so this patch doesn't belong in this repo.

kubkon avatar May 06 '23 05:05 kubkon