[fpc-pascal] What's in Hello World

Sven Barth pascaldragon at googlemail.com
Sun Jan 7 13:55:58 CET 2024


Am 07.01.2024 um 11:39 schrieb Michael Van Canneyt via fpc-pascal:
>
>
> On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:
>
>> Am 07.01.2024 um 10:01 schrieb Florian Klämpfl via fpc-pascal:
>>>
>>>
>>>> Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal 
>>>> <fpc-pascal at lists.freepascal.org>:
>>>>
>>>> I compiled the Hello World program from the docs and noticed that it's
>>>> 435k. Compared to a lot of newer languages, like Golang, that's not 
>>>> bad
>>>> at all.
>>>>
>>>> I then compiled the equivalent C program with gcc which came out at
>>>> 33k. So I'm just curious, where does the difference comes from?
>>>> Could it be that fpc is including some parts that are not being 
>>>> used in
>>>> this simple of a program or is more going on?
>>>
>>> https://wiki.freepascal.org/Size_Matters
>>>
>> To underline this with some numbers (I assume you mean the 
>> demo/text/hello.pp which only contains a mere "Writeln('Hello 
>> World')" and no additional units; all tests on x86_64-linux with 3.3.1):
>>
>> - FPC compiled as is: 388976 B
>> - FPC compiled with full smartlinking: 55920 B
>> - FPC compiled with C linkage: 388760 B
>> - FPC compiled with full smartlinking and C linkage: 56792 B
>
> Maybe it is a good idea to add these numbers to the above WIKI page, 
> to quantify
> the discussion and to illustrate what the effect is of various options.

Probably... 🤷‍♀️

And just for the fun of it, the size if the RTL is compiled into a 
dynamic package and that is used:

- no smartlinking: 15784 B
- with smartlinking: 15608 B

With the librtl.so having a size of 649912 B which will ammortize itself 
if multiple applications use dynamic packages.

> I think we should also explain why linking to C has almost no effect 
> on actual binary size.

That's mainly because the functions that differ between FPC_USE_LIBC and 
not are rather slim syscalls anyway, so the main bunch of Pascal code is 
still the same in both cases.

Regards,
Sven


More information about the fpc-pascal mailing list