[fpc-devel] NONE smart link broken on windows?
Graeme Geldenhuys
mailinglist at geldenhuys.co.uk
Sat Apr 25 17:12:07 CEST 2026
On Friday, 24 April 2026 23:57:16 BST Martin Frb via fpc-devel wrote:
> The code currently uses
> tai_const.create_8bit(sizeof(pint))
>
> But that can't be right when cross compiling?
Hi all,
I recently looked into whether sizeof(pint) in dbgdwarf.pas was producing
incorrect DWARF address_size values during cross-compilation — specifically
the concern that on a 64-bit host generating 32-bit debug info, sizeof(pint)
would evaluate to 8 rather than 4.
The short answer is: it doesn't, and the code is correct as-is.
The reason I initially thought it might be a problem is the common assumption
that sizeof(pint) reflects the host pointer size. That is true in user
programs, but not for FPC's cross-compiler binaries. When ppcross386 is built,
the compiler source is compiled with -dCPU_I386, which sets {$define CPU32},
which in turn causes PtrInt (= pint, Pascal being case-insensitive) to be
defined as Longint — 4 bytes — regardless of the host architecture the binary
runs on. So sizeof(pint) evaluates to the target pointer size at Pascal
compile time, which is exactly what you want.
I verified this with a small test. Compiling a trivial program using
ppcross386 on an x86_64 host with debug info:
----
program dwarftest;
var
x: LongInt;
begin
x := 42;
WriteLn(x);
end.
----
$ ppcross386 -g -Cn dwarftest.pas
Free Pascal Compiler version 3.3.1 [2026/04/25] for i386
...
$ readelf --debug-dump=info dwarftest.o | grep -A5 "Compilation Unit"
Compilation Unit @ offset 0:
Length: 0x85 (32-bit)
Version: 3
Abbrev Offset: 0
Pointer Size: 4
Pointer Size: 4 is correct for an i386 target. A patched build using
voidpointertype.size produces identical output, confirming the two expressions
are always equivalent.
I've closed the MR I had opened for this.
Graeme
More information about the fpc-devel
mailing list