View Issue Details

IDProjectCategoryView StatusLast Update
0036751FPCRTLpublic2020-03-07 19:01
ReporterMarcin WiazowskiAssigned ToMarco van de Voort 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformWin64OSOS Version
Product Version3.3.1Product Build44253 
Target Version3.2.0Fixed in Version 
Summary0036751: Win64, Windows unit: some declarations are compiled improperly
DescriptionThere is a bug in the way, in which Windows unit is compiled for Win64 target (potentially, also other units may be affected).

Please see the attached Reproduce demo. It displays field offsets of some records, that are declared in Windows unit. In particular, the TImageOptionalHeader record is interesting. In 32-bit mode, it's redirected to IMAGE_OPTIONAL_HEADER32 declaration. In 64-bit mode, it should be redirected to IMAGE_OPTIONAL_HEADER64 declaration - while it seems that it's still redirected to IMAGE_OPTIONAL_HEADER32 declaration (for some reason, that is unknown to me).


The attached output_Delphi64.txt contains:
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x0050: SizeOfStackCommit
  Field at offset 0x0058: SizeOfHeapReserve
  Field at offset 0x0060: SizeOfHeapCommit

The attached output_FPC64.txt contains:
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x004C: SizeOfStackCommit
  Field at offset 0x0050: SizeOfHeapReserve
  Field at offset 0x0054: SizeOfHeapCommit


Although SizeOfStackReserve, SizeOfStackCommit, SizeOfHeapReserve and SizeOfHeapCommit fields should be compiled as 64-bit fields, they are compiled as 32-bit fields by FPC. When the attached Reproduce demo is compiled for Win32 and Win64 targets, generated results are basically same (although they shouldn't). Adding the "-Mdelphi" compilation command does not change anything.

Tested with FPC 3.0.4, 3.2.0 (r44252) and 3.3.1 (r44253).
TagsNo tags attached.
Fixed in Revision44258 (struct.inc) 44259,44260 (winunits-base), 44278 (winunits-jedi)
FPCOldBugId
FPCTarget-
Attached Files
  • Reproduce.zip (1,058 bytes)
  • output_Delphi32.txt (2,610 bytes)
    TImageNtHeaders (size of record is 0x00F8 bytes):
      Field at offset 0x0000: Signature
      Field at offset 0x0004: FileHeader
      Field at offset 0x0018: OptionalHeader
    
    TImageFileHeader (size of record is 0x0014 bytes):
      Field at offset 0x0000: Machine
      Field at offset 0x0002: NumberOfSections
      Field at offset 0x0004: TimeDateStamp
      Field at offset 0x0008: PointerToSymbolTable
      Field at offset 0x000C: NumberOfSymbols
      Field at offset 0x0010: SizeOfOptionalHeader
      Field at offset 0x0012: Characteristics
    
    TImageOptionalHeader (size of record is 0x00E0 bytes):
      Field at offset 0x0000: Magic
      Field at offset 0x0002: MajorLinkerVersion
      Field at offset 0x0003: MinorLinkerVersion
      Field at offset 0x0004: SizeOfCode
      Field at offset 0x0008: SizeOfInitializedData
      Field at offset 0x000C: SizeOfUninitializedData
      Field at offset 0x0010: AddressOfEntryPoint
      Field at offset 0x0014: BaseOfCode
      Field at offset 0x0018: BaseOfData
      Field at offset 0x001C: ImageBase
      Field at offset 0x0020: SectionAlignment
      Field at offset 0x0024: FileAlignment
      Field at offset 0x0028: MajorOperatingSystemVersion
      Field at offset 0x002A: MinorOperatingSystemVersion
      Field at offset 0x002C: MajorImageVersion
      Field at offset 0x002E: MinorImageVersion
      Field at offset 0x0030: MajorSubsystemVersion
      Field at offset 0x0032: MinorSubsystemVersion
      Field at offset 0x0034: Win32VersionValue
      Field at offset 0x0038: SizeOfImage
      Field at offset 0x003C: SizeOfHeaders
      Field at offset 0x0040: CheckSum
      Field at offset 0x0044: Subsystem
      Field at offset 0x0046: DllCharacteristics
      Field at offset 0x0048: SizeOfStackReserve
      Field at offset 0x004C: SizeOfStackCommit
      Field at offset 0x0050: SizeOfHeapReserve
      Field at offset 0x0054: SizeOfHeapCommit
      Field at offset 0x0058: LoaderFlags
      Field at offset 0x005C: NumberOfRvaAndSizes
      Field at offset 0x0060: DataDirectory[0]
      Field at offset 0x0068: DataDirectory[1]
      Field at offset 0x0070: DataDirectory[2]
      Field at offset 0x0078: DataDirectory[3]
      Field at offset 0x0080: DataDirectory[4]
      Field at offset 0x0088: DataDirectory[5]
      Field at offset 0x0090: DataDirectory[6]
      Field at offset 0x0098: DataDirectory[7]
      Field at offset 0x00A0: DataDirectory[8]
      Field at offset 0x00A8: DataDirectory[9]
      Field at offset 0x00B0: DataDirectory[10]
      Field at offset 0x00B8: DataDirectory[11]
      Field at offset 0x00C0: DataDirectory[12]
      Field at offset 0x00C8: DataDirectory[13]
      Field at offset 0x00D0: DataDirectory[14]
      Field at offset 0x00D8: DataDirectory[15]
    
    output_Delphi32.txt (2,610 bytes)
  • output_Delphi64.txt (2,572 bytes)
    TImageNtHeaders (size of record is 0x0108 bytes):
      Field at offset 0x0000: Signature
      Field at offset 0x0004: FileHeader
      Field at offset 0x0018: OptionalHeader
    
    TImageFileHeader (size of record is 0x0014 bytes):
      Field at offset 0x0000: Machine
      Field at offset 0x0002: NumberOfSections
      Field at offset 0x0004: TimeDateStamp
      Field at offset 0x0008: PointerToSymbolTable
      Field at offset 0x000C: NumberOfSymbols
      Field at offset 0x0010: SizeOfOptionalHeader
      Field at offset 0x0012: Characteristics
    
    TImageOptionalHeader (size of record is 0x00F0 bytes):
      Field at offset 0x0000: Magic
      Field at offset 0x0002: MajorLinkerVersion
      Field at offset 0x0003: MinorLinkerVersion
      Field at offset 0x0004: SizeOfCode
      Field at offset 0x0008: SizeOfInitializedData
      Field at offset 0x000C: SizeOfUninitializedData
      Field at offset 0x0010: AddressOfEntryPoint
      Field at offset 0x0014: BaseOfCode
      Field at offset 0x0018: ImageBase
      Field at offset 0x0020: SectionAlignment
      Field at offset 0x0024: FileAlignment
      Field at offset 0x0028: MajorOperatingSystemVersion
      Field at offset 0x002A: MinorOperatingSystemVersion
      Field at offset 0x002C: MajorImageVersion
      Field at offset 0x002E: MinorImageVersion
      Field at offset 0x0030: MajorSubsystemVersion
      Field at offset 0x0032: MinorSubsystemVersion
      Field at offset 0x0034: Win32VersionValue
      Field at offset 0x0038: SizeOfImage
      Field at offset 0x003C: SizeOfHeaders
      Field at offset 0x0040: CheckSum
      Field at offset 0x0044: Subsystem
      Field at offset 0x0046: DllCharacteristics
      Field at offset 0x0048: SizeOfStackReserve
      Field at offset 0x0050: SizeOfStackCommit
      Field at offset 0x0058: SizeOfHeapReserve
      Field at offset 0x0060: SizeOfHeapCommit
      Field at offset 0x0068: LoaderFlags
      Field at offset 0x006C: NumberOfRvaAndSizes
      Field at offset 0x0070: DataDirectory[0]
      Field at offset 0x0078: DataDirectory[1]
      Field at offset 0x0080: DataDirectory[2]
      Field at offset 0x0088: DataDirectory[3]
      Field at offset 0x0090: DataDirectory[4]
      Field at offset 0x0098: DataDirectory[5]
      Field at offset 0x00A0: DataDirectory[6]
      Field at offset 0x00A8: DataDirectory[7]
      Field at offset 0x00B0: DataDirectory[8]
      Field at offset 0x00B8: DataDirectory[9]
      Field at offset 0x00C0: DataDirectory[10]
      Field at offset 0x00C8: DataDirectory[11]
      Field at offset 0x00D0: DataDirectory[12]
      Field at offset 0x00D8: DataDirectory[13]
      Field at offset 0x00E0: DataDirectory[14]
      Field at offset 0x00E8: DataDirectory[15]
    
    output_Delphi64.txt (2,572 bytes)
  • output_FPC32.txt (2,610 bytes)
    TImageNtHeaders (size of record is 0x00F8 bytes):
      Field at offset 0x0000: Signature
      Field at offset 0x0004: FileHeader
      Field at offset 0x0018: OptionalHeader
    
    TImageFileHeader (size of record is 0x0014 bytes):
      Field at offset 0x0000: Machine
      Field at offset 0x0002: NumberOfSections
      Field at offset 0x0004: TimeDateStamp
      Field at offset 0x0008: PointerToSymbolTable
      Field at offset 0x000C: NumberOfSymbols
      Field at offset 0x0010: SizeOfOptionalHeader
      Field at offset 0x0012: Characteristics
    
    TImageOptionalHeader (size of record is 0x00E0 bytes):
      Field at offset 0x0000: Magic
      Field at offset 0x0002: MajorLinkerVersion
      Field at offset 0x0003: MinorLinkerVersion
      Field at offset 0x0004: SizeOfCode
      Field at offset 0x0008: SizeOfInitializedData
      Field at offset 0x000C: SizeOfUninitializedData
      Field at offset 0x0010: AddressOfEntryPoint
      Field at offset 0x0014: BaseOfCode
      Field at offset 0x0018: BaseOfData
      Field at offset 0x001C: ImageBase
      Field at offset 0x0020: SectionAlignment
      Field at offset 0x0024: FileAlignment
      Field at offset 0x0028: MajorOperatingSystemVersion
      Field at offset 0x002A: MinorOperatingSystemVersion
      Field at offset 0x002C: MajorImageVersion
      Field at offset 0x002E: MinorImageVersion
      Field at offset 0x0030: MajorSubsystemVersion
      Field at offset 0x0032: MinorSubsystemVersion
      Field at offset 0x0034: Win32VersionValue
      Field at offset 0x0038: SizeOfImage
      Field at offset 0x003C: SizeOfHeaders
      Field at offset 0x0040: CheckSum
      Field at offset 0x0044: Subsystem
      Field at offset 0x0046: DllCharacteristics
      Field at offset 0x0048: SizeOfStackReserve
      Field at offset 0x004C: SizeOfStackCommit
      Field at offset 0x0050: SizeOfHeapReserve
      Field at offset 0x0054: SizeOfHeapCommit
      Field at offset 0x0058: LoaderFlags
      Field at offset 0x005C: NumberOfRvaAndSizes
      Field at offset 0x0060: DataDirectory[0]
      Field at offset 0x0068: DataDirectory[1]
      Field at offset 0x0070: DataDirectory[2]
      Field at offset 0x0078: DataDirectory[3]
      Field at offset 0x0080: DataDirectory[4]
      Field at offset 0x0088: DataDirectory[5]
      Field at offset 0x0090: DataDirectory[6]
      Field at offset 0x0098: DataDirectory[7]
      Field at offset 0x00A0: DataDirectory[8]
      Field at offset 0x00A8: DataDirectory[9]
      Field at offset 0x00B0: DataDirectory[10]
      Field at offset 0x00B8: DataDirectory[11]
      Field at offset 0x00C0: DataDirectory[12]
      Field at offset 0x00C8: DataDirectory[13]
      Field at offset 0x00D0: DataDirectory[14]
      Field at offset 0x00D8: DataDirectory[15]
    
    output_FPC32.txt (2,610 bytes)
  • output_FPC64.txt (2,572 bytes)
    TImageNtHeaders (size of record is 0x00F8 bytes):
      Field at offset 0x0000: Signature
      Field at offset 0x0004: FileHeader
      Field at offset 0x0018: OptionalHeader
    
    TImageFileHeader (size of record is 0x0014 bytes):
      Field at offset 0x0000: Machine
      Field at offset 0x0002: NumberOfSections
      Field at offset 0x0004: TimeDateStamp
      Field at offset 0x0008: PointerToSymbolTable
      Field at offset 0x000C: NumberOfSymbols
      Field at offset 0x0010: SizeOfOptionalHeader
      Field at offset 0x0012: Characteristics
    
    TImageOptionalHeader (size of record is 0x00E0 bytes):
      Field at offset 0x0000: Magic
      Field at offset 0x0002: MajorLinkerVersion
      Field at offset 0x0003: MinorLinkerVersion
      Field at offset 0x0004: SizeOfCode
      Field at offset 0x0008: SizeOfInitializedData
      Field at offset 0x000C: SizeOfUninitializedData
      Field at offset 0x0010: AddressOfEntryPoint
      Field at offset 0x0014: BaseOfCode
      Field at offset 0x001C: ImageBase
      Field at offset 0x0020: SectionAlignment
      Field at offset 0x0024: FileAlignment
      Field at offset 0x0028: MajorOperatingSystemVersion
      Field at offset 0x002A: MinorOperatingSystemVersion
      Field at offset 0x002C: MajorImageVersion
      Field at offset 0x002E: MinorImageVersion
      Field at offset 0x0030: MajorSubsystemVersion
      Field at offset 0x0032: MinorSubsystemVersion
      Field at offset 0x0034: Win32VersionValue
      Field at offset 0x0038: SizeOfImage
      Field at offset 0x003C: SizeOfHeaders
      Field at offset 0x0040: CheckSum
      Field at offset 0x0044: Subsystem
      Field at offset 0x0046: DllCharacteristics
      Field at offset 0x0048: SizeOfStackReserve
      Field at offset 0x004C: SizeOfStackCommit
      Field at offset 0x0050: SizeOfHeapReserve
      Field at offset 0x0054: SizeOfHeapCommit
      Field at offset 0x0058: LoaderFlags
      Field at offset 0x005C: NumberOfRvaAndSizes
      Field at offset 0x0060: DataDirectory[0]
      Field at offset 0x0068: DataDirectory[1]
      Field at offset 0x0070: DataDirectory[2]
      Field at offset 0x0078: DataDirectory[3]
      Field at offset 0x0080: DataDirectory[4]
      Field at offset 0x0088: DataDirectory[5]
      Field at offset 0x0090: DataDirectory[6]
      Field at offset 0x0098: DataDirectory[7]
      Field at offset 0x00A0: DataDirectory[8]
      Field at offset 0x00A8: DataDirectory[9]
      Field at offset 0x00B0: DataDirectory[10]
      Field at offset 0x00B8: DataDirectory[11]
      Field at offset 0x00C0: DataDirectory[12]
      Field at offset 0x00C8: DataDirectory[13]
      Field at offset 0x00D0: DataDirectory[14]
      Field at offset 0x00D8: DataDirectory[15]
    
    output_FPC64.txt (2,572 bytes)
  • struct.inc.diff (1,295 bytes)
    diff --git a/rtl/win/wininc/struct.inc b/rtl/win/wininc/struct.inc
    index 045a9b0cfc..0c5c0cb363 100644
    --- a/rtl/win/wininc/struct.inc
    +++ b/rtl/win/wininc/struct.inc
    @@ -7363,7 +7363,7 @@ Const
               idCommand : longint;
               fsState : BYTE;
               fsStyle : BYTE;
    -{$ifdef _WIN64}
    +{$ifdef WIN64}
               bReserved : array[0..5] of BYTE;
     {$else}
               bReserved : array[0..1] of BYTE;
    @@ -8592,7 +8592,7 @@ const
       IMAGE_ROM_OPTIONAL_HDR_MAGIC  = $107;
     
     type
    -{$ifdef _WIN64}
    +{$ifdef WIN64}
       IMAGE_OPTIONAL_HEADER = IMAGE_OPTIONAL_HEADER64;
       PIMAGE_OPTIONAL_HEADER = PIMAGE_OPTIONAL_HEADER64;
     {$else}
    @@ -8636,7 +8636,7 @@ type
       TImageRomHeaders = IMAGE_ROM_HEADERS;
       PImageRomHeaders = PIMAGE_ROM_HEADERS;
     
    -{$ifdef _WIN64}
    +{$ifdef WIN64}
       IMAGE_NT_HEADERS = IMAGE_NT_HEADERS64;
       PIMAGE_NT_HEADERS = PIMAGE_NT_HEADERS64;
     {$else}
    @@ -8804,7 +8804,7 @@ type
            end;
          PIMAGE_LOAD_CONFIG_DIRECTORY64 = ^IMAGE_LOAD_CONFIG_DIRECTORY64;
          TIMAGE_LOAD_CONFIG_DIRECTORY64 = IMAGE_LOAD_CONFIG_DIRECTORY64;
    -{$ifdef _WIN64}
    +{$ifdef WIN64}
          IMAGE_LOAD_CONFIG_DIRECTORY = IMAGE_LOAD_CONFIG_DIRECTORY64;
          TIMAGE_LOAD_CONFIG_DIRECTORY = TIMAGE_LOAD_CONFIG_DIRECTORY64;
          PIMAGE_LOAD_CONFIG_DIRECTORY = PIMAGE_LOAD_CONFIG_DIRECTORY64;
    
    struct.inc.diff (1,295 bytes)
  • output_win64_fpc.txt (2,572 bytes)
    TImageNtHeaders (size of record is 0x0108 bytes):
      Field at offset 0x0000: Signature
      Field at offset 0x0004: FileHeader
      Field at offset 0x0018: OptionalHeader
    
    TImageFileHeader (size of record is 0x0014 bytes):
      Field at offset 0x0000: Machine
      Field at offset 0x0002: NumberOfSections
      Field at offset 0x0004: TimeDateStamp
      Field at offset 0x0008: PointerToSymbolTable
      Field at offset 0x000C: NumberOfSymbols
      Field at offset 0x0010: SizeOfOptionalHeader
      Field at offset 0x0012: Characteristics
    
    TImageOptionalHeader (size of record is 0x00F0 bytes):
      Field at offset 0x0000: Magic
      Field at offset 0x0002: MajorLinkerVersion
      Field at offset 0x0003: MinorLinkerVersion
      Field at offset 0x0004: SizeOfCode
      Field at offset 0x0008: SizeOfInitializedData
      Field at offset 0x000C: SizeOfUninitializedData
      Field at offset 0x0010: AddressOfEntryPoint
      Field at offset 0x0014: BaseOfCode
      Field at offset 0x0018: ImageBase
      Field at offset 0x0020: SectionAlignment
      Field at offset 0x0024: FileAlignment
      Field at offset 0x0028: MajorOperatingSystemVersion
      Field at offset 0x002A: MinorOperatingSystemVersion
      Field at offset 0x002C: MajorImageVersion
      Field at offset 0x002E: MinorImageVersion
      Field at offset 0x0030: MajorSubsystemVersion
      Field at offset 0x0032: MinorSubsystemVersion
      Field at offset 0x0034: Win32VersionValue
      Field at offset 0x0038: SizeOfImage
      Field at offset 0x003C: SizeOfHeaders
      Field at offset 0x0040: CheckSum
      Field at offset 0x0044: Subsystem
      Field at offset 0x0046: DllCharacteristics
      Field at offset 0x0048: SizeOfStackReserve
      Field at offset 0x0050: SizeOfStackCommit
      Field at offset 0x0058: SizeOfHeapReserve
      Field at offset 0x0060: SizeOfHeapCommit
      Field at offset 0x0068: LoaderFlags
      Field at offset 0x006C: NumberOfRvaAndSizes
      Field at offset 0x0070: DataDirectory[0]
      Field at offset 0x0078: DataDirectory[1]
      Field at offset 0x0080: DataDirectory[2]
      Field at offset 0x0088: DataDirectory[3]
      Field at offset 0x0090: DataDirectory[4]
      Field at offset 0x0098: DataDirectory[5]
      Field at offset 0x00A0: DataDirectory[6]
      Field at offset 0x00A8: DataDirectory[7]
      Field at offset 0x00B0: DataDirectory[8]
      Field at offset 0x00B8: DataDirectory[9]
      Field at offset 0x00C0: DataDirectory[10]
      Field at offset 0x00C8: DataDirectory[11]
      Field at offset 0x00D0: DataDirectory[12]
      Field at offset 0x00D8: DataDirectory[13]
      Field at offset 0x00E0: DataDirectory[14]
      Field at offset 0x00E8: DataDirectory[15]
    
    output_win64_fpc.txt (2,572 bytes)
  • output_win32_fpc.txt (2,610 bytes)
    TImageNtHeaders (size of record is 0x00F8 bytes):
      Field at offset 0x0000: Signature
      Field at offset 0x0004: FileHeader
      Field at offset 0x0018: OptionalHeader
    
    TImageFileHeader (size of record is 0x0014 bytes):
      Field at offset 0x0000: Machine
      Field at offset 0x0002: NumberOfSections
      Field at offset 0x0004: TimeDateStamp
      Field at offset 0x0008: PointerToSymbolTable
      Field at offset 0x000C: NumberOfSymbols
      Field at offset 0x0010: SizeOfOptionalHeader
      Field at offset 0x0012: Characteristics
    
    TImageOptionalHeader (size of record is 0x00E0 bytes):
      Field at offset 0x0000: Magic
      Field at offset 0x0002: MajorLinkerVersion
      Field at offset 0x0003: MinorLinkerVersion
      Field at offset 0x0004: SizeOfCode
      Field at offset 0x0008: SizeOfInitializedData
      Field at offset 0x000C: SizeOfUninitializedData
      Field at offset 0x0010: AddressOfEntryPoint
      Field at offset 0x0014: BaseOfCode
      Field at offset 0x0018: BaseOfData
      Field at offset 0x001C: ImageBase
      Field at offset 0x0020: SectionAlignment
      Field at offset 0x0024: FileAlignment
      Field at offset 0x0028: MajorOperatingSystemVersion
      Field at offset 0x002A: MinorOperatingSystemVersion
      Field at offset 0x002C: MajorImageVersion
      Field at offset 0x002E: MinorImageVersion
      Field at offset 0x0030: MajorSubsystemVersion
      Field at offset 0x0032: MinorSubsystemVersion
      Field at offset 0x0034: Win32VersionValue
      Field at offset 0x0038: SizeOfImage
      Field at offset 0x003C: SizeOfHeaders
      Field at offset 0x0040: CheckSum
      Field at offset 0x0044: Subsystem
      Field at offset 0x0046: DllCharacteristics
      Field at offset 0x0048: SizeOfStackReserve
      Field at offset 0x004C: SizeOfStackCommit
      Field at offset 0x0050: SizeOfHeapReserve
      Field at offset 0x0054: SizeOfHeapCommit
      Field at offset 0x0058: LoaderFlags
      Field at offset 0x005C: NumberOfRvaAndSizes
      Field at offset 0x0060: DataDirectory[0]
      Field at offset 0x0068: DataDirectory[1]
      Field at offset 0x0070: DataDirectory[2]
      Field at offset 0x0078: DataDirectory[3]
      Field at offset 0x0080: DataDirectory[4]
      Field at offset 0x0088: DataDirectory[5]
      Field at offset 0x0090: DataDirectory[6]
      Field at offset 0x0098: DataDirectory[7]
      Field at offset 0x00A0: DataDirectory[8]
      Field at offset 0x00A8: DataDirectory[9]
      Field at offset 0x00B0: DataDirectory[10]
      Field at offset 0x00B8: DataDirectory[11]
      Field at offset 0x00C0: DataDirectory[12]
      Field at offset 0x00C8: DataDirectory[13]
      Field at offset 0x00D0: DataDirectory[14]
      Field at offset 0x00D8: DataDirectory[15]
    
    output_win32_fpc.txt (2,610 bytes)

Activities

Marcin Wiazowski

2020-03-02 23:33

reporter  

Reproduce.zip (1,058 bytes)
output_Delphi32.txt (2,610 bytes)
TImageNtHeaders (size of record is 0x00F8 bytes):
  Field at offset 0x0000: Signature
  Field at offset 0x0004: FileHeader
  Field at offset 0x0018: OptionalHeader

TImageFileHeader (size of record is 0x0014 bytes):
  Field at offset 0x0000: Machine
  Field at offset 0x0002: NumberOfSections
  Field at offset 0x0004: TimeDateStamp
  Field at offset 0x0008: PointerToSymbolTable
  Field at offset 0x000C: NumberOfSymbols
  Field at offset 0x0010: SizeOfOptionalHeader
  Field at offset 0x0012: Characteristics

TImageOptionalHeader (size of record is 0x00E0 bytes):
  Field at offset 0x0000: Magic
  Field at offset 0x0002: MajorLinkerVersion
  Field at offset 0x0003: MinorLinkerVersion
  Field at offset 0x0004: SizeOfCode
  Field at offset 0x0008: SizeOfInitializedData
  Field at offset 0x000C: SizeOfUninitializedData
  Field at offset 0x0010: AddressOfEntryPoint
  Field at offset 0x0014: BaseOfCode
  Field at offset 0x0018: BaseOfData
  Field at offset 0x001C: ImageBase
  Field at offset 0x0020: SectionAlignment
  Field at offset 0x0024: FileAlignment
  Field at offset 0x0028: MajorOperatingSystemVersion
  Field at offset 0x002A: MinorOperatingSystemVersion
  Field at offset 0x002C: MajorImageVersion
  Field at offset 0x002E: MinorImageVersion
  Field at offset 0x0030: MajorSubsystemVersion
  Field at offset 0x0032: MinorSubsystemVersion
  Field at offset 0x0034: Win32VersionValue
  Field at offset 0x0038: SizeOfImage
  Field at offset 0x003C: SizeOfHeaders
  Field at offset 0x0040: CheckSum
  Field at offset 0x0044: Subsystem
  Field at offset 0x0046: DllCharacteristics
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x004C: SizeOfStackCommit
  Field at offset 0x0050: SizeOfHeapReserve
  Field at offset 0x0054: SizeOfHeapCommit
  Field at offset 0x0058: LoaderFlags
  Field at offset 0x005C: NumberOfRvaAndSizes
  Field at offset 0x0060: DataDirectory[0]
  Field at offset 0x0068: DataDirectory[1]
  Field at offset 0x0070: DataDirectory[2]
  Field at offset 0x0078: DataDirectory[3]
  Field at offset 0x0080: DataDirectory[4]
  Field at offset 0x0088: DataDirectory[5]
  Field at offset 0x0090: DataDirectory[6]
  Field at offset 0x0098: DataDirectory[7]
  Field at offset 0x00A0: DataDirectory[8]
  Field at offset 0x00A8: DataDirectory[9]
  Field at offset 0x00B0: DataDirectory[10]
  Field at offset 0x00B8: DataDirectory[11]
  Field at offset 0x00C0: DataDirectory[12]
  Field at offset 0x00C8: DataDirectory[13]
  Field at offset 0x00D0: DataDirectory[14]
  Field at offset 0x00D8: DataDirectory[15]
output_Delphi32.txt (2,610 bytes)
output_Delphi64.txt (2,572 bytes)
TImageNtHeaders (size of record is 0x0108 bytes):
  Field at offset 0x0000: Signature
  Field at offset 0x0004: FileHeader
  Field at offset 0x0018: OptionalHeader

TImageFileHeader (size of record is 0x0014 bytes):
  Field at offset 0x0000: Machine
  Field at offset 0x0002: NumberOfSections
  Field at offset 0x0004: TimeDateStamp
  Field at offset 0x0008: PointerToSymbolTable
  Field at offset 0x000C: NumberOfSymbols
  Field at offset 0x0010: SizeOfOptionalHeader
  Field at offset 0x0012: Characteristics

TImageOptionalHeader (size of record is 0x00F0 bytes):
  Field at offset 0x0000: Magic
  Field at offset 0x0002: MajorLinkerVersion
  Field at offset 0x0003: MinorLinkerVersion
  Field at offset 0x0004: SizeOfCode
  Field at offset 0x0008: SizeOfInitializedData
  Field at offset 0x000C: SizeOfUninitializedData
  Field at offset 0x0010: AddressOfEntryPoint
  Field at offset 0x0014: BaseOfCode
  Field at offset 0x0018: ImageBase
  Field at offset 0x0020: SectionAlignment
  Field at offset 0x0024: FileAlignment
  Field at offset 0x0028: MajorOperatingSystemVersion
  Field at offset 0x002A: MinorOperatingSystemVersion
  Field at offset 0x002C: MajorImageVersion
  Field at offset 0x002E: MinorImageVersion
  Field at offset 0x0030: MajorSubsystemVersion
  Field at offset 0x0032: MinorSubsystemVersion
  Field at offset 0x0034: Win32VersionValue
  Field at offset 0x0038: SizeOfImage
  Field at offset 0x003C: SizeOfHeaders
  Field at offset 0x0040: CheckSum
  Field at offset 0x0044: Subsystem
  Field at offset 0x0046: DllCharacteristics
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x0050: SizeOfStackCommit
  Field at offset 0x0058: SizeOfHeapReserve
  Field at offset 0x0060: SizeOfHeapCommit
  Field at offset 0x0068: LoaderFlags
  Field at offset 0x006C: NumberOfRvaAndSizes
  Field at offset 0x0070: DataDirectory[0]
  Field at offset 0x0078: DataDirectory[1]
  Field at offset 0x0080: DataDirectory[2]
  Field at offset 0x0088: DataDirectory[3]
  Field at offset 0x0090: DataDirectory[4]
  Field at offset 0x0098: DataDirectory[5]
  Field at offset 0x00A0: DataDirectory[6]
  Field at offset 0x00A8: DataDirectory[7]
  Field at offset 0x00B0: DataDirectory[8]
  Field at offset 0x00B8: DataDirectory[9]
  Field at offset 0x00C0: DataDirectory[10]
  Field at offset 0x00C8: DataDirectory[11]
  Field at offset 0x00D0: DataDirectory[12]
  Field at offset 0x00D8: DataDirectory[13]
  Field at offset 0x00E0: DataDirectory[14]
  Field at offset 0x00E8: DataDirectory[15]
output_Delphi64.txt (2,572 bytes)
output_FPC32.txt (2,610 bytes)
TImageNtHeaders (size of record is 0x00F8 bytes):
  Field at offset 0x0000: Signature
  Field at offset 0x0004: FileHeader
  Field at offset 0x0018: OptionalHeader

TImageFileHeader (size of record is 0x0014 bytes):
  Field at offset 0x0000: Machine
  Field at offset 0x0002: NumberOfSections
  Field at offset 0x0004: TimeDateStamp
  Field at offset 0x0008: PointerToSymbolTable
  Field at offset 0x000C: NumberOfSymbols
  Field at offset 0x0010: SizeOfOptionalHeader
  Field at offset 0x0012: Characteristics

TImageOptionalHeader (size of record is 0x00E0 bytes):
  Field at offset 0x0000: Magic
  Field at offset 0x0002: MajorLinkerVersion
  Field at offset 0x0003: MinorLinkerVersion
  Field at offset 0x0004: SizeOfCode
  Field at offset 0x0008: SizeOfInitializedData
  Field at offset 0x000C: SizeOfUninitializedData
  Field at offset 0x0010: AddressOfEntryPoint
  Field at offset 0x0014: BaseOfCode
  Field at offset 0x0018: BaseOfData
  Field at offset 0x001C: ImageBase
  Field at offset 0x0020: SectionAlignment
  Field at offset 0x0024: FileAlignment
  Field at offset 0x0028: MajorOperatingSystemVersion
  Field at offset 0x002A: MinorOperatingSystemVersion
  Field at offset 0x002C: MajorImageVersion
  Field at offset 0x002E: MinorImageVersion
  Field at offset 0x0030: MajorSubsystemVersion
  Field at offset 0x0032: MinorSubsystemVersion
  Field at offset 0x0034: Win32VersionValue
  Field at offset 0x0038: SizeOfImage
  Field at offset 0x003C: SizeOfHeaders
  Field at offset 0x0040: CheckSum
  Field at offset 0x0044: Subsystem
  Field at offset 0x0046: DllCharacteristics
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x004C: SizeOfStackCommit
  Field at offset 0x0050: SizeOfHeapReserve
  Field at offset 0x0054: SizeOfHeapCommit
  Field at offset 0x0058: LoaderFlags
  Field at offset 0x005C: NumberOfRvaAndSizes
  Field at offset 0x0060: DataDirectory[0]
  Field at offset 0x0068: DataDirectory[1]
  Field at offset 0x0070: DataDirectory[2]
  Field at offset 0x0078: DataDirectory[3]
  Field at offset 0x0080: DataDirectory[4]
  Field at offset 0x0088: DataDirectory[5]
  Field at offset 0x0090: DataDirectory[6]
  Field at offset 0x0098: DataDirectory[7]
  Field at offset 0x00A0: DataDirectory[8]
  Field at offset 0x00A8: DataDirectory[9]
  Field at offset 0x00B0: DataDirectory[10]
  Field at offset 0x00B8: DataDirectory[11]
  Field at offset 0x00C0: DataDirectory[12]
  Field at offset 0x00C8: DataDirectory[13]
  Field at offset 0x00D0: DataDirectory[14]
  Field at offset 0x00D8: DataDirectory[15]
output_FPC32.txt (2,610 bytes)
output_FPC64.txt (2,572 bytes)
TImageNtHeaders (size of record is 0x00F8 bytes):
  Field at offset 0x0000: Signature
  Field at offset 0x0004: FileHeader
  Field at offset 0x0018: OptionalHeader

TImageFileHeader (size of record is 0x0014 bytes):
  Field at offset 0x0000: Machine
  Field at offset 0x0002: NumberOfSections
  Field at offset 0x0004: TimeDateStamp
  Field at offset 0x0008: PointerToSymbolTable
  Field at offset 0x000C: NumberOfSymbols
  Field at offset 0x0010: SizeOfOptionalHeader
  Field at offset 0x0012: Characteristics

TImageOptionalHeader (size of record is 0x00E0 bytes):
  Field at offset 0x0000: Magic
  Field at offset 0x0002: MajorLinkerVersion
  Field at offset 0x0003: MinorLinkerVersion
  Field at offset 0x0004: SizeOfCode
  Field at offset 0x0008: SizeOfInitializedData
  Field at offset 0x000C: SizeOfUninitializedData
  Field at offset 0x0010: AddressOfEntryPoint
  Field at offset 0x0014: BaseOfCode
  Field at offset 0x001C: ImageBase
  Field at offset 0x0020: SectionAlignment
  Field at offset 0x0024: FileAlignment
  Field at offset 0x0028: MajorOperatingSystemVersion
  Field at offset 0x002A: MinorOperatingSystemVersion
  Field at offset 0x002C: MajorImageVersion
  Field at offset 0x002E: MinorImageVersion
  Field at offset 0x0030: MajorSubsystemVersion
  Field at offset 0x0032: MinorSubsystemVersion
  Field at offset 0x0034: Win32VersionValue
  Field at offset 0x0038: SizeOfImage
  Field at offset 0x003C: SizeOfHeaders
  Field at offset 0x0040: CheckSum
  Field at offset 0x0044: Subsystem
  Field at offset 0x0046: DllCharacteristics
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x004C: SizeOfStackCommit
  Field at offset 0x0050: SizeOfHeapReserve
  Field at offset 0x0054: SizeOfHeapCommit
  Field at offset 0x0058: LoaderFlags
  Field at offset 0x005C: NumberOfRvaAndSizes
  Field at offset 0x0060: DataDirectory[0]
  Field at offset 0x0068: DataDirectory[1]
  Field at offset 0x0070: DataDirectory[2]
  Field at offset 0x0078: DataDirectory[3]
  Field at offset 0x0080: DataDirectory[4]
  Field at offset 0x0088: DataDirectory[5]
  Field at offset 0x0090: DataDirectory[6]
  Field at offset 0x0098: DataDirectory[7]
  Field at offset 0x00A0: DataDirectory[8]
  Field at offset 0x00A8: DataDirectory[9]
  Field at offset 0x00B0: DataDirectory[10]
  Field at offset 0x00B8: DataDirectory[11]
  Field at offset 0x00C0: DataDirectory[12]
  Field at offset 0x00C8: DataDirectory[13]
  Field at offset 0x00D0: DataDirectory[14]
  Field at offset 0x00D8: DataDirectory[15]
output_FPC64.txt (2,572 bytes)

Cyrax

2020-03-03 01:35

reporter   ~0121330

The problem and cause is multiple compiler conditional checks like these {$ifdef _WIN64} (please notice underscore which should not be there if we are checking for if target is Win64 system) in rtl/win/wininc/struct.inc file.

Cyrax

2020-03-03 08:58

reporter   ~0121333

Attached patch will fix this bug (struct.inc.diff).

Also attached outputs of test program, which is built by fixed FPC trunk compiler.

struct.inc.diff (1,295 bytes)
diff --git a/rtl/win/wininc/struct.inc b/rtl/win/wininc/struct.inc
index 045a9b0cfc..0c5c0cb363 100644
--- a/rtl/win/wininc/struct.inc
+++ b/rtl/win/wininc/struct.inc
@@ -7363,7 +7363,7 @@ Const
           idCommand : longint;
           fsState : BYTE;
           fsStyle : BYTE;
-{$ifdef _WIN64}
+{$ifdef WIN64}
           bReserved : array[0..5] of BYTE;
 {$else}
           bReserved : array[0..1] of BYTE;
@@ -8592,7 +8592,7 @@ const
   IMAGE_ROM_OPTIONAL_HDR_MAGIC  = $107;
 
 type
-{$ifdef _WIN64}
+{$ifdef WIN64}
   IMAGE_OPTIONAL_HEADER = IMAGE_OPTIONAL_HEADER64;
   PIMAGE_OPTIONAL_HEADER = PIMAGE_OPTIONAL_HEADER64;
 {$else}
@@ -8636,7 +8636,7 @@ type
   TImageRomHeaders = IMAGE_ROM_HEADERS;
   PImageRomHeaders = PIMAGE_ROM_HEADERS;
 
-{$ifdef _WIN64}
+{$ifdef WIN64}
   IMAGE_NT_HEADERS = IMAGE_NT_HEADERS64;
   PIMAGE_NT_HEADERS = PIMAGE_NT_HEADERS64;
 {$else}
@@ -8804,7 +8804,7 @@ type
        end;
      PIMAGE_LOAD_CONFIG_DIRECTORY64 = ^IMAGE_LOAD_CONFIG_DIRECTORY64;
      TIMAGE_LOAD_CONFIG_DIRECTORY64 = IMAGE_LOAD_CONFIG_DIRECTORY64;
-{$ifdef _WIN64}
+{$ifdef WIN64}
      IMAGE_LOAD_CONFIG_DIRECTORY = IMAGE_LOAD_CONFIG_DIRECTORY64;
      TIMAGE_LOAD_CONFIG_DIRECTORY = TIMAGE_LOAD_CONFIG_DIRECTORY64;
      PIMAGE_LOAD_CONFIG_DIRECTORY = PIMAGE_LOAD_CONFIG_DIRECTORY64;
struct.inc.diff (1,295 bytes)
output_win64_fpc.txt (2,572 bytes)
TImageNtHeaders (size of record is 0x0108 bytes):
  Field at offset 0x0000: Signature
  Field at offset 0x0004: FileHeader
  Field at offset 0x0018: OptionalHeader

TImageFileHeader (size of record is 0x0014 bytes):
  Field at offset 0x0000: Machine
  Field at offset 0x0002: NumberOfSections
  Field at offset 0x0004: TimeDateStamp
  Field at offset 0x0008: PointerToSymbolTable
  Field at offset 0x000C: NumberOfSymbols
  Field at offset 0x0010: SizeOfOptionalHeader
  Field at offset 0x0012: Characteristics

TImageOptionalHeader (size of record is 0x00F0 bytes):
  Field at offset 0x0000: Magic
  Field at offset 0x0002: MajorLinkerVersion
  Field at offset 0x0003: MinorLinkerVersion
  Field at offset 0x0004: SizeOfCode
  Field at offset 0x0008: SizeOfInitializedData
  Field at offset 0x000C: SizeOfUninitializedData
  Field at offset 0x0010: AddressOfEntryPoint
  Field at offset 0x0014: BaseOfCode
  Field at offset 0x0018: ImageBase
  Field at offset 0x0020: SectionAlignment
  Field at offset 0x0024: FileAlignment
  Field at offset 0x0028: MajorOperatingSystemVersion
  Field at offset 0x002A: MinorOperatingSystemVersion
  Field at offset 0x002C: MajorImageVersion
  Field at offset 0x002E: MinorImageVersion
  Field at offset 0x0030: MajorSubsystemVersion
  Field at offset 0x0032: MinorSubsystemVersion
  Field at offset 0x0034: Win32VersionValue
  Field at offset 0x0038: SizeOfImage
  Field at offset 0x003C: SizeOfHeaders
  Field at offset 0x0040: CheckSum
  Field at offset 0x0044: Subsystem
  Field at offset 0x0046: DllCharacteristics
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x0050: SizeOfStackCommit
  Field at offset 0x0058: SizeOfHeapReserve
  Field at offset 0x0060: SizeOfHeapCommit
  Field at offset 0x0068: LoaderFlags
  Field at offset 0x006C: NumberOfRvaAndSizes
  Field at offset 0x0070: DataDirectory[0]
  Field at offset 0x0078: DataDirectory[1]
  Field at offset 0x0080: DataDirectory[2]
  Field at offset 0x0088: DataDirectory[3]
  Field at offset 0x0090: DataDirectory[4]
  Field at offset 0x0098: DataDirectory[5]
  Field at offset 0x00A0: DataDirectory[6]
  Field at offset 0x00A8: DataDirectory[7]
  Field at offset 0x00B0: DataDirectory[8]
  Field at offset 0x00B8: DataDirectory[9]
  Field at offset 0x00C0: DataDirectory[10]
  Field at offset 0x00C8: DataDirectory[11]
  Field at offset 0x00D0: DataDirectory[12]
  Field at offset 0x00D8: DataDirectory[13]
  Field at offset 0x00E0: DataDirectory[14]
  Field at offset 0x00E8: DataDirectory[15]
output_win64_fpc.txt (2,572 bytes)
output_win32_fpc.txt (2,610 bytes)
TImageNtHeaders (size of record is 0x00F8 bytes):
  Field at offset 0x0000: Signature
  Field at offset 0x0004: FileHeader
  Field at offset 0x0018: OptionalHeader

TImageFileHeader (size of record is 0x0014 bytes):
  Field at offset 0x0000: Machine
  Field at offset 0x0002: NumberOfSections
  Field at offset 0x0004: TimeDateStamp
  Field at offset 0x0008: PointerToSymbolTable
  Field at offset 0x000C: NumberOfSymbols
  Field at offset 0x0010: SizeOfOptionalHeader
  Field at offset 0x0012: Characteristics

TImageOptionalHeader (size of record is 0x00E0 bytes):
  Field at offset 0x0000: Magic
  Field at offset 0x0002: MajorLinkerVersion
  Field at offset 0x0003: MinorLinkerVersion
  Field at offset 0x0004: SizeOfCode
  Field at offset 0x0008: SizeOfInitializedData
  Field at offset 0x000C: SizeOfUninitializedData
  Field at offset 0x0010: AddressOfEntryPoint
  Field at offset 0x0014: BaseOfCode
  Field at offset 0x0018: BaseOfData
  Field at offset 0x001C: ImageBase
  Field at offset 0x0020: SectionAlignment
  Field at offset 0x0024: FileAlignment
  Field at offset 0x0028: MajorOperatingSystemVersion
  Field at offset 0x002A: MinorOperatingSystemVersion
  Field at offset 0x002C: MajorImageVersion
  Field at offset 0x002E: MinorImageVersion
  Field at offset 0x0030: MajorSubsystemVersion
  Field at offset 0x0032: MinorSubsystemVersion
  Field at offset 0x0034: Win32VersionValue
  Field at offset 0x0038: SizeOfImage
  Field at offset 0x003C: SizeOfHeaders
  Field at offset 0x0040: CheckSum
  Field at offset 0x0044: Subsystem
  Field at offset 0x0046: DllCharacteristics
  Field at offset 0x0048: SizeOfStackReserve
  Field at offset 0x004C: SizeOfStackCommit
  Field at offset 0x0050: SizeOfHeapReserve
  Field at offset 0x0054: SizeOfHeapCommit
  Field at offset 0x0058: LoaderFlags
  Field at offset 0x005C: NumberOfRvaAndSizes
  Field at offset 0x0060: DataDirectory[0]
  Field at offset 0x0068: DataDirectory[1]
  Field at offset 0x0070: DataDirectory[2]
  Field at offset 0x0078: DataDirectory[3]
  Field at offset 0x0080: DataDirectory[4]
  Field at offset 0x0088: DataDirectory[5]
  Field at offset 0x0090: DataDirectory[6]
  Field at offset 0x0098: DataDirectory[7]
  Field at offset 0x00A0: DataDirectory[8]
  Field at offset 0x00A8: DataDirectory[9]
  Field at offset 0x00B0: DataDirectory[10]
  Field at offset 0x00B8: DataDirectory[11]
  Field at offset 0x00C0: DataDirectory[12]
  Field at offset 0x00C8: DataDirectory[13]
  Field at offset 0x00D0: DataDirectory[14]
  Field at offset 0x00D8: DataDirectory[15]
output_win32_fpc.txt (2,610 bytes)

Marcin Wiazowski

2020-03-03 11:31

reporter   ~0121336

Indeed, conditional checks for "_WIN64" can be found in the following files:


packages\winceunits\src\wininet.pp
packages\winunits-base\src\commctrl.pp
packages\winunits-base\src\nb30.pp
packages\winunits-jedi\src\jwanb30.pas
packages\winunits-jedi\src\jwawinioctl.pas
packages\winunits-jedi\src\jwaws2spi.pas
rtl\win\wininc\struct.inc
tests\test\cg\obj\stdint.h


This should be also checked.

Marco van de Voort

2020-03-03 12:11

manager   ~0121338

I committed some quickfixes in trunk. Still have to do jedi and merge to fixes. Too late for RC1, but definitely should be in 3.2.

Marco van de Voort

2020-03-06 23:30

manager   ~0121422

Also did jedi, 44258-60 merged to fixes.

Marcin Wiazowski

2020-03-07 19:01

reporter   ~0121438

Fix confirmed. Thanks!

Issue History

Date Modified Username Field Change
2020-03-02 23:33 Marcin Wiazowski New Issue
2020-03-02 23:33 Marcin Wiazowski File Added: Reproduce.zip
2020-03-02 23:33 Marcin Wiazowski File Added: output_Delphi32.txt
2020-03-02 23:33 Marcin Wiazowski File Added: output_Delphi64.txt
2020-03-02 23:33 Marcin Wiazowski File Added: output_FPC32.txt
2020-03-02 23:33 Marcin Wiazowski File Added: output_FPC64.txt
2020-03-03 01:35 Cyrax Note Added: 0121330
2020-03-03 08:58 Cyrax File Added: struct.inc.diff
2020-03-03 08:58 Cyrax File Added: output_win64_fpc.txt
2020-03-03 08:58 Cyrax File Added: output_win32_fpc.txt
2020-03-03 08:58 Cyrax Note Added: 0121333
2020-03-03 11:31 Marcin Wiazowski Note Added: 0121336
2020-03-03 11:38 Marco van de Voort Target Version => 3.2.0
2020-03-03 11:38 Marco van de Voort Description Updated View Revisions
2020-03-03 11:38 Marco van de Voort FPCTarget => -
2020-03-03 11:49 Marco van de Voort Assigned To => Marco van de Voort
2020-03-03 11:49 Marco van de Voort Status new => assigned
2020-03-03 11:50 Marco van de Voort Category Compiler => RTL
2020-03-03 12:05 Marco van de Voort Fixed in Revision => 44258 (struct.inc)
2020-03-03 12:10 Marco van de Voort Fixed in Revision 44258 (struct.inc) => 44258 (struct.inc) 44259,44260 (winunits-base)
2020-03-03 12:11 Marco van de Voort Note Added: 0121338
2020-03-06 23:30 Marco van de Voort Status assigned => resolved
2020-03-06 23:30 Marco van de Voort Resolution open => fixed
2020-03-06 23:30 Marco van de Voort Fixed in Revision 44258 (struct.inc) 44259,44260 (winunits-base) => 44258 (struct.inc) 44259,44260 (winunits-base), 44278 (winunits-jedi)
2020-03-06 23:30 Marco van de Voort Note Added: 0121422
2020-03-07 19:01 Marcin Wiazowski Status resolved => closed
2020-03-07 19:01 Marcin Wiazowski Note Added: 0121438