[fpc-pascal] Separate debug info for release builds

Martin Frb lazarus at mfriebe.de
Fri Nov 1 16:16:15 CET 2024


On 01/11/2024 15:59, Henry Vermaak via fpc-pascal wrote:
> When I add -Xg, the compiler writes the debug info into a separate
> .dbg file and adds a .gnu_debuglink section so the debugger can find
> the info.  So far so good (and simpler than having the use objcopy).
>
> The size of the binary is much larger than building without debug
> info, though.  E.g. with -O2 it goes from 35K to 188K.
>
> When I do exactly the same with gcc (via objcopy and strip), there's
> almost no difference between the stripped binary and a binary built
> without debugging info (even diffing objdump output).
>
> Can anyone explain why this is?
>

I may not have all the factors, but O- O1 and O2 are not debug info, but 
optimization.
So they generate different code, and that leads to different exe sizes.

I am not sure it explains the full size diff you get. Depending on the 
code, you may have a difference due to smart linking.

To check if any other symbols (e.g. those needed for the linker) differ 
between the various builds, you can try to use strip, and that shows you 
how much actually remains for the app-code/data.

-----------
Then of course there are a few problems that make the whole thing more 
complex.

gcc can (afaik) generate working debug info for optimized code.

fpc does not. If data is in registers then fpc does not represent that 
(at least not always correctly) in the debug info. So data will be show 
incorrect in the debugger.
fpc does not generate line info for inlined code. And I don't know how 
well/exact line info is for different level of optimization in different 
fpc versions.
And some versions of fpc (or maybe some linkers?) caused broken debug 
info when smart linking was enabled.

So basically, if you want to debug, then you can't really optimize.
Or at least you must check exactly what is supported by the version of 
fpc you use.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20241101/67adae0b/attachment.htm>


More information about the fpc-pascal mailing list