Wrong Mach-O header offset with 3.3.1, reading resources with fcl-res
The following test program works with fpc-3.2.4rc1, but fails with fpc-3.3.1 ``` program testres; {$R testres.res} uses classes, resource, machotypes, machoreader; procedure test; const kFilename = 'testres'; var theReader: TMachOResourceReader; theResources: TResources; begin theResources := TResources.Create; theReader := TMachOResourceReader.Create; theResources.LoadFromFile( kFilename, theReader); end; begin writeln( 'SizeOf( TMachHdr) = ', SizeOf( TMachHdr)); writeln( 'SizeOf( TLoadCommand) = ', SizeOf( TLoadCommand)); writeln( 'SizeOf( TSegmentCommand32) = ', SizeOf( TSegmentCommand32)); writeln( 'SizeOf( TSegmentCommand64) = ', SizeOf( TSegmentCommand64)); test end. ``` with attached [testres.res](/uploads/c33e32c3f238002ca36e9c4cb9f7032e/testres.res), as follows ``` [Mac-mini:~/fpc-test/res] administrator% /usr/local/lib/fpc/3.3.1/ppca64 testres.pas Free Pascal Compiler version 3.3.1 [2026/01/10] for aarch64 Copyright (c) 1993-2026 by Florian Klaempfl and others Target OS: Darwin for AArch64 Compiling testres.pas Assembling (pipe) testres.s Compiling resource testres.or Linking testres -macosx_version_min has been renamed to -macos_version_min ld: warning: no platform load command found in '/Users/administrator/fpc-test/res/testres.or', assuming: macOS 26 lines compiled, 0.4 sec, 884736 bytes code, 327679 bytes data [Mac-mini:~/fpc-test/res] administrator% ./testres SizeOf( TMachHdr) = 32 SizeOf( TLoadCommand) = 8 SizeOf( TSegmentCommand32) = 48 SizeOf( TSegmentCommand64) = 64 An unhandled exception occurred at $0000000102DF6DE0: EResourceReaderUnexpectedEndOfStreamException: $0000000102DF6DE0 $0000000102DF3F2C $0000000102DF4124 $0000000102D98C18 $0000000102D98D84 $0000000102DC0B7C $0000000102D98B90 $0000000102D98C58 $00000001868E3154 [Mac-mini:~/fpc-test/res] administrator% /usr/local/lib/fpc/3.2.4/ppca64 testres.pas Free Pascal Compiler version 3.2.4-rc1 [2025/10/15] for aarch64 Copyright (c) 1993-2024 by Florian Klaempfl and others Target OS: Darwin for AArch64 Compiling testres.pas Assembling testres Compiling resource testres.or Linking testres ld: warning: -multiply_defined is obsolete -macosx_version_min has been renamed to -macos_version_min ld: warning: no platform load command found in '/Users/administrator/fpc-test/res/testres.or', assuming: macOS 26 lines compiled, 0.2 sec [Mac-mini:~/fpc-test/res] administrator% ./testres SizeOf( TMachHdr) = 28 SizeOf( TLoadCommand) = 8 SizeOf( TSegmentCommand32) = 48 SizeOf( TSegmentCommand64) = 64 ``` The cause is in the different sizes of TMachHdr, which is 28 with fpc-3.2.4 and 32 with fpc.3.3.1. ``` TMachHdr = record magic : longword; cputype : longint; cpusubtype : longint; filetype : longword; ncmds : longword; sizeofcmds : longword; flags : longword; end; TMachHdr = record magic: cuint32; cputype: tmach_cpu_type; cpusubtype: tmach_cpu_subtype; filetype: cuint32; ncmds: cuint32; sizeofcmds: cuint32; flags: cuint32; {$IFDEF CPU64} reserved: cuint32; {$ENDIF} end; ``` Consequently, when _TMachOSubReader_.FindResSection starts to read load commands, the offset is 4 bytes to high. Indeed, there is a 4-byte reserved field in the TMachHdr, but I assume it is compensated for in the code already.
issue