Re: [fpc-pascal] What's in Hello World

2024-01-11 Thread DougC via fpc-pascal
Ah, yes! The Hello World Machine.



Doug C.







 On Thu, 11 Jan 2024 14:34:29 -0500 Adriaan van Os via fpc-pascal 
 wrote ---



Nikolay Nikolov via fpc-pascal wrote: 
 > But that increases the binary size to 28 bytes. We can put a 'ret' 
 
That's still 27 bytes too much. Let's design a CPU that has "Hello World" as a 
one-byte 
instruction, implement that CPU in a Field-programmable gate array, write an OS 
for it and let it 
say hello. That's HelloWorld ad absurdum. 
 ___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-11 Thread Adriaan van Os via fpc-pascal

Nikolay Nikolov via fpc-pascal wrote:

But that increases the binary size to 28 bytes. We can put a 'ret' 


That's still 27 bytes too much. Let's design a CPU that has "Hello World" as a one-byte 
instruction, implement that CPU in a Field-programmable gate array, write an OS for it and let it 
say hello. That's HelloWorld ad absurdum.


Or just send some smoke signals 



Regards,

Adriaan van Os
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-11 Thread Nikolay Nikolov via fpc-pascal


On 1/7/24 14:21, Ingemar Ragnemalm via fpc-pascal wrote:


Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see 
it: 4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?


Nah! It's bloat, bloat, bloat, horrible bloat!!! I'm not impressed. :)

Nothing beats assembler for DOS:

; nasm asmhello.asm -o asmhello.com
    bits 16
    cpu 8086
    org 100h
    mov dx, msg
    mov ah, 9
    int 21h
    ret
msg:    db 'Hello, world!', 13, 10, '$'

The produced executable is only 24 bytes (8 bytes of code and 16 bytes 
of data):


BA 08 01 B4 09 CD 21 C3 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 24

You can write this down on a sheet of paper, or memorize it and recite 
it from memory. Try doing that with 4639 bytes :)


Note that noobs will use the following way to terminate the program:

mov ax, 4c00h

int 21h

But that increases the binary size to 28 bytes. We can put a 'ret' 
instruction instead, and that works, because DOS puts a h word on 
top of the stack, and that points to CS:h, which is the beginning of 
the PSP. And that starts with an int 20h, which is the oldschool (MS-DOS 
version 1) way of terminating a process, which requires CS to point to 
the PSP, which it does, because we're a .com file.


Nikolay

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Marco van de Voort via fpc-pascal



Op 7-1-2024 om 16:09 schreef Travis Siegel via fpc-pascal:

Not that it's 100 percent relevant, but I always use powerbasic 
(https://www.powerbasic.com) when it's a matter of size, 


I also never use powerbasic.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Travis Siegel via fpc-pascal


On 1/7/2024 1:09 PM, Florian Klämpfl via fpc-pascal wrote:



Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal 
:


Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see 
it: 4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?


https://github.com/chainq/amiga-tiny-hello-p

244 bytes with FPC.

Not that it's 100 percent relevant, but I always use powerbasic 
(https://www.powerbasic.com) when it's a matter of size, since 
powerbasic and it's console compiler produces a hello world program of 
just 7,168 bytes which is still a windows executable, and works on 
just about any version of windows.


I've never found any windows compiler that produces smaller executables 
by default.


Even their powerbasic windows compilers do an admirable job of keeping 
the executable sizes down to amazing numbers.


I have an epub reader I've been working off and on for the last couple 
years, and even with a complete gui and significant functionality, my 
epub reader clocks in at a whooping 75,776 bytes.


I've never gotten such results from any other windows compiler, and 
indeed, a great deal of linux compilers can't match that.


Of course, I *always* use FPC when a I need the program on multiple 
platforms, though I do tend to use java when I need a gui on multiple 
platforms, as I can just throw up the grid format, then not have to 
worry about how the gui looks, which is great for me, because it's 
either that, or have a sighted individual pour over the gui with me 
until I get it right.  It's just easier to use grid mode on java. :)


For what it's worth though, generally, I find FPC to be considerably 
better than anything cross platform except of course for GCC.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Travis Siegel via fpc-pascal
For what it's worth, the hello world program in powerbasic 
(https://www.powerbasic.com) comes to a whooping 7,168 bytes. That's the 
console version, not the gui version, that's a bit bigger, but by not 
much more.  I have an epub reader I've been working on for a few years, 
on and off, and that program which has a complete gui, web browser 
calls, and the like, weighs in at just over 75K.  I always use 
powerbasic if I'm writing a windows only program, since it's ability to 
produce such small executables is well known.  Heck, it even has a 
#bloat command in the compiler to artificially inflate the size of the 
exe files it builds, because so many didn't believe that it was 
producing an actual windows binary.


I use FPC when working on cross platform programs, since it can compile 
for many platforms, unless I need a gui.  In that case, I use java, 
since I can put it in grid mode, and then I don't have to worry about 
how the gui is laid out.  Something that typically takes sighted 
assistance, and a great deal of time otherwise.


Of course, GCC produces small binaries too, and I'll use that too when 
the need arrises.


It all depends on what I am working on, and where it is going to run.


On 1/7/2024 7:33 PM, Michael Van Canneyt via fpc-pascal wrote:



On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:



- 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.


Nice result. Smaller than a C program :-)



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.


I know this, but most likely users will not realize this... :-)

Michael.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Jean SUZINEAU via fpc-pascal

Le 08/01/2024 à 13:51, Peter B via fpc-pascal a écrit :

   or if not, is there another way to
turn it on in the textmode IDE?

No idea. Its easy enough if you compile from the command line.
fpc -Os -XX hello.pas

If stripping is not on by default, also use -Xs 


I guess that in the textmode IDE you just have to go Options/Compiler
and in the bottom in "Additional compiler args"
you just have to add -Os -XX - Xs

-Os :  Optimize for size rather than speed
-Xs  :  Strip all symbols from executable
-XX : Try to smartlink units (defines FPC_LINK_SMART)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Karoly Balogh via fpc-pascal
Hi,

On Mon, 8 Jan 2024, Marco van de Voort via fpc-pascal wrote:

>
> Op 8-1-2024 om 14:03 schreef Karoly Balogh via fpc-pascal:
> > No, it's not. But the Linker specific options are under Options ->
> > Linker... There's a smartlinking related option there, but I'm not sure if
> > it is what you need. :)
>
> That one is -XX, and the "create smartlinkable units" in the tab before is -CX
> (generate smartlinkable units or something similar) .
>
> If you change these, force a build afterwards.

You do not need this, if you use a platform that supports section
smartlinking. Then smartlinking "just works" from the regular objects and
libraries.

But yeah, this depends on the target platform. You do not need this on
Linux, which where this discussion started. I'm sure you also do not need
this, if you use the internal linker on Windows either.

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Marco van de Voort via fpc-pascal



Op 8-1-2024 om 14:03 schreef Karoly Balogh via fpc-pascal:

No, it's not. But the Linker specific options are under Options ->
Linker... There's a smartlinking related option there, but I'm not sure if
it is what you need. :)


That one is -XX, and the "create smartlinkable units" in the tab before 
is -CX (generate smartlinkable units or something similar) .


If you change these, force a build afterwards.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread code dz via fpc-pascal
I remember i made a simple  win32 window app with custom tiny RTL , and
final exe size was 4.5kb  .

On Sun, Jan 7, 2024, 20:33 Michael Van Canneyt via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

>
>
> On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:
>
> >>>
> >>> - 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.
>
> Nice result. Smaller than a C program :-)
>
> >
> >> 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.
>
> I know this, but most likely users will not realize this... :-)
>
> Michael.___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, James Richters via fpc-pascal wrote:

> >Try building with smartlinking, -XX
>
> I never knew there was an option for smartlinking.   I'm using the FPC text
> IDE, I see various options like
> Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see
> anything specifically called smartlinking.
> Is it the same as Generate Smaller Code?

No, it's not. But the Linker specific options are under Options ->
Linker... There's a smartlinking related option there, but I'm not sure if
it is what you need. :)

> or if not, is there another way to turn it on in the textmode IDE?

There's a field called "Additional Compiler Args" in the Compiler Switches
window, in the Options -> Compiler... menu. You can add arguments there
like you'd invoke the regular command line compiler.

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-08 Thread Peter B via fpc-pascal

On 07/01/2024 16:07, James Richters via fpc-pascal wrote:

Try building with smartlinking, -XX

I never knew there was an option for smartlinking.   I'm using the FPC text
IDE, I see various options like
Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see
anything specifically called smartlinking.
If you run fpc from the console, with no parameters or options, you 
should see a

full set of options listed.

  
Is it the same as Generate Smaller Code?

No. That is a compile option -Os
-XX is a link time option.


   or if not, is there another way to
turn it on in the textmode IDE?

No idea. Its easy enough if you compile from the command line.
fpc -Os -XX hello.pas

If stripping is not on by default, also use -Xs

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, Florian Klämpfl via fpc-pascal wrote:

>> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal 
>> :
>>
>> Just for comparison, I fired up Think Pascal and made Hello world!
>>
>> Plain Hello world, closes so quickly that you don't have time to see
>> it: 4625 bytes.
>>
>> Including ShowText and while not Button do; 4639 bytes.
>>
>> Yes, less than 5k! Progress?
>
> https://github.com/chainq/amiga-tiny-hello-p
>
> 244 bytes with FPC.

BTW, and while I still stand by the Disclaimer I wrote at the bottom of
that page, this kind of technique can have a real world impact and use.
For example, we made a couple of Windows 4k intros (real time animations
with graphics and music, in less than 4096 bytes!) with Free Pascal using
the same kind of startup-bypass technque - and admittedly, a compressing
linker, called Crinkler. :)

Ampelwürfel:
https://www.pouet.net/prod.php?which=90091
... additional backstory/tech explanation:
- https://www.pouet.net/prod.php?which=90091#c932283
Binary download:
- https://files.scene.org/view/parties/2021/deadline21/pc_intro/rbs-aw.zip
Direct YouTube link:
- https://youtu.be/Tz_dpKQrQE0

Icecold:
https://www.pouet.net/prod.php?which=94741
Binary download:
- https://files.scene.org/view/parties/2023/evoke23/in4k/rbs-icecold.zip
Direct YouTube link:
- https://youtu.be/z5aR2EfqRgI

Sadly the source for these is not available, AFAIR, but it's basically the
same approach as the Amiga Tiny Hello world.

Crinkler, the compressing linker we used:
https://github.com/runestubbe/Crinkler

Charlie___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, Michael Van Canneyt via fpc-pascal wrote:

> > 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.
>
> I think we should also explain why linking to C has almost no effect on
> actual binary size.

Note that the numbers above don't include stripping, so it's full with
symbols. I get the same numbers with unstriped binares. If I add striping
(-Xs), the Hello, World! FPC with smartlinking binary is 35056 bytes.
(Current FPC Git main, on Debian 12, x86_64) Other binary sizes change by
roughly the same percentage.

Also note that on most platforms, smartlinking is a lot faster and less
invasive than it used to be, and it doesn't need additional .a files,
thanks to section smartlinking and the section garbage collection feature
of modern linkers. Not sure if some documentation needs to be updated for
that, but while we're at it... :)

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Karoly Balogh via fpc-pascal
Hi,

On Sun, 7 Jan 2024, Ingemar Ragnemalm via fpc-pascal wrote:

> Just for comparison, I fired up Think Pascal and made Hello world!
>
> Plain Hello world, closes so quickly that you don't have time to see it: 4625 
> bytes.
>
> Including ShowText and while not Button do; 4639 bytes.
>
> Yes, less than 5k! Progress?

This isn't a fair comparison. Think Pascal is a single platform compiler,
which means it can avoid a bunch of abstraction layers, and also it
doesn't support many advanced modern Pascal constructs. Main examples are
AnsiStrings, and exception handling, but also the memory allocator is more
advanced, and thus bigger than the early Pascal compilers. Everything has
a trade off.

Also while this means the initial "bloat" is bigger, there's a lot less
added, as one progresses. I have a fully localized, multithreaded GUI
Amiga application written in Free Pascal, that is around 64KiB. I'm sure
it could be a lot smaller too, but it isn't unreasonable.
(Here: http://viaduct.amigaspirit.hu )

If anyone is curious what gets into a "Hello, World!" binary, feel free to
look into a linker map, by using command line argument -Xm. (Note on Linux
& systems using GNU LD, the linker map file starts with the _discarded_
sections, the ones which did not get into the binary, so look at the
bottom of the file.)

Charlie
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Rainer Stratmann via fpc-pascal
Am Sonntag, 7. Januar 2024, 14:09:24 CET schrieb Florian Klämpfl via fpc-
pascal:
> > Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal
> > :
> > 
> > Just for comparison, I fired up Think Pascal and made Hello world!
> > 
> > Plain Hello world, closes so quickly that you don't have time to see it:
> > 4625 bytes.
> > 
> > Including ShowText and while not Button do; 4639 bytes.
> > 
> > Yes, less than 5k! Progress?
> 
> https://github.com/chainq/amiga-tiny-hello-p
> 
> 244 bytes with FPC.

Is the size of AVR programs reasonable small?
Is the AVR code stable?
I would like to switch to freepascal.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Marco van de Voort via fpc-pascal



Op 7-1-2024 om 11:23 schreef Sven Barth via fpc-pascal:
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

(gotta admit, the last one surprised me though ^^')

I noticed that when I implemented -dFPC_USE_LIBC. The dynamic library 
overhead is bigger than the 15-20kb worth of routines saved in fairly 
simple programs. In the past is was even more pronounced because readdir 
was kernel.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Michael Van Canneyt via fpc-pascal



On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote:



- 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.


Nice result. Smaller than a C program :-)



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.


I know this, but most likely users will not realize this... :-)

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread James Richters via fpc-pascal
>Try building with smartlinking, -XX

I never knew there was an option for smartlinking.   I'm using the FPC text
IDE, I see various options like 
Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see
anything specifically called smartlinking. 
Is it the same as Generate Smaller Code?  or if not, is there another way to
turn it on in the textmode IDE?

James


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Florian Klämpfl via fpc-pascal


> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal 
> :
> 
> Just for comparison, I fired up Think Pascal and made Hello world!
> 
> Plain Hello world, closes so quickly that you don't have time to see it: 4625 
> bytes.
> 
> Including ShowText and while not Button do; 4639 bytes.
> 
> Yes, less than 5k! Progress?
> 
https://github.com/chainq/amiga-tiny-hello-p

244 bytes with FPC.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Sven Barth via fpc-pascal

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 
:


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
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Jonas Maebe via fpc-pascal

On 07/01/2024 13:21, Ingemar Ragnemalm via fpc-pascal wrote:

Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see it: 
4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?


You forgot the 1MB Mac ROM :)

That's also the main difference between C and FPC: C programs by default 
are dynamically linked, so all of the standard RTL functionality that 
gets linked into an FPC program is not there in a C program most of the 
time.


It's also why golang programs are larger: those are statically linked as 
well.



Jonas

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Ingemar Ragnemalm via fpc-pascal

Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see it: 
4625 bytes.


Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?

/Ingemar
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Adriaan van Os via fpc-pascal

Peter B via fpc-pascal wrote:


Try building with smartlinking, -XX
I get 35k


You can also experiment with ld linker options like --strip-all and --strip-debug or run the 
produced code through strip  with various 
options (e.g. -u -r on OSX).


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Peter B via fpc-pascal




Try building with smartlinking, -XX
I get 35k


Thats with 3.2.2 on linux

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread 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 
:


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.

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

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Sven Barth via fpc-pascal

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 
:


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

(gotta admit, the last one surprised me though ^^')

Regards,
Sven___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Peter B via fpc-pascal

On 06/01/2024 19:05, Matthew Phillips via fpc-pascal wrote:

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?

Like I said, purely a curiosity, not intended as a criticism. Cheers.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Try building with smartlinking, -XX
I get 35k


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] What's in Hello World

2024-01-07 Thread Florian Klämpfl via fpc-pascal


> Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal 
> :
> 
> 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

> 
> Like I said, purely a curiosity, not intended as a criticism. Cheers.
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] What's in Hello World

2024-01-07 Thread Matthew Phillips via fpc-pascal
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?

Like I said, purely a curiosity, not intended as a criticism. Cheers.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal