iosmacosmach-ouniversal-binaryfat-binaries

How to understand the comments about fat_arch_64 in 'mach-o/fat.h'


Recently, I'm learning some materials related to Mach-O and noticed the comment

When a slice is greater than 4mb or an offset to a slice is greater than 4mb then the 64-bit fat file format is used.

in 'mach-o/fat.h' about struct fat_acrh_64

I know we should use the value of fat_header.magic to decide use fat_arch or fat_arch_64 to parse the data in a fat file.

But I am confused about the comment, why the limit condition is 4 Mb and what's the slice/offset in the comment means?

Here is the screenshot for header file: enter image description here


Solution

  • The comment is wrong and you can find counterexamples in the wild.
    This is from an M1 Mac:

    % otool -f /usr/sbin/php-fpm
    Fat headers
    fat_magic 0xcafebabe
    nfat_arch 2
    architecture 0
        cputype 16777223
        cpusubtype 3
        capabilities 0x0
        offset 16384
        size 14061120
        align 2^14 (16384)
    architecture 1
        cputype 16777228
        cpusubtype 2
        capabilities 0x80
        offset 14090240
        size 14110192
        align 2^15 (32768)
    

    As you can see, both size and offset are in excess of 14MB.

    A reasonable guess would be that they meant 4GB, which is the limit of what a uint32 can represent.