Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-10

FPC on Rpi3 executable module sizes

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ken Kashmarek

I have a group of programs that compile using FPC on Windows 7. I have ported those programs over to my RPi3 and they all compile fine.

On Windows 7, the executable files are significantly smaller (less 100K) than those from the IDE on RPi3 (all 400K & larger). There may be ways to reduce these sizes. However, it seems that linking on the RPi3 is not as advanced as on Windows (it looks like the entire library is being included rather than just the invoked modules).

Here is a quick comparison of one program:

On Windows 7 (output from the dir command):
SIZE
10/29/2016 08:00 AM 97,792 hello.exe
10/29/2016 08:00 AM 14,191 hello.o
10/20/2016 01:25 PM 5,162 hello.pas

On RPi3 (output from ls -l):
SIZE
-rwxr-xr-x 1 pi pi 408892 Oct 29 07:47 hello
-rw-r--r-- 1 pi pi 12876 Oct 29 07:47 hello.o -rw-r----- 1 pi pi 5164 Oct 29 07:47 hello.pas

The executable file sizes are rather extreme for programs tha run from an terminal session. The output from execution is the same.

I have turned off a number of options that could have been contributing to this issue (such as eliminaing debug code and symbols).

Any possible considerations for the size difference?

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/FPC-on-Rpi3-executable-module-sizes-tp4050126.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Bo Berglund
to Ken Kashmarek
Ken Kashmarek wrote 16 lines
On RPi3 (output from ls -l): SIZE -rwxr-xr-x 1 pi pi 408892 Oct 29 07:47 hello -rw-r--r-- 1 pi pi 12876 Oct 29 07:47 hello.o -rw-r----- 1 pi pi 5164 Oct 29 07:47 hello.pas The executable file sizes are rather extreme for programs tha run from an terminal session. The output from execution is the same. I have turned off a number of options that could have been contributing to this issue (such as eliminaing debug code and symbols). Any possible considerations for the size difference?

Debug symbols still included in the output maybe?
Try this:
strip -s hello

Bo Berglund Developer in Sweden

Reply by email

Ken Kashmarek
to Bo Berglund

FCP on Rapsberry Pi3

On my Window 7 node, a null program produces this output when compiled from the command line:

10/30/2016 11:36 AM 31,744 nullpgm.exe 10/30/2016 11:36 AM 3,141 nullpgm.o
10/30/2016 09:19 AM 574 nullpgm.pas

When the Build menu item is selected under Lazurus on RPi3:

-rwxr-xr-x 1 pi pi 200548 Oct 30 09:19 nullpgm
-rw-r--r-- 1 pi pi 3356 Oct 30 09:19 nullpgm.o
-rw-rw---- 1 pi pi 574 Oct 30 09:19 nullpgm.pas

While the object code generated (nullpgm.o) is relatively the same, the executable is out of sight on the RPi3. What is being included here?

When one uses item (uses sysutils;) is added, the Window 7 executable goes up to over 80K in size.

On the RPi3, goes up to over 400K in size. If 3 items are in the uses line, the RPi3 executable exceeds 800K.

This is clearly an error where each addition adds 200k (or more) the the executable file. I do note however, that all 3 uses entries on Windows 7, brings the executable up to more than 240K (significantly smaller than the RPi3 install of FCP produces).

Here is the program listing:

program nullpgm(input,output);
{$SMARTLINK ON}
{$DEBUGINFO OFF}
uses	sysutils; // , variants, classes;
type	ptr2Byte = ^Byte;
	comp     = int64;
var	i,j:	integer;
begin
  writeln;
  i := 4096;
  writeln('Value of i = ',i:8);
  writeln('--> Execution of (nearly) null program ended.');
  writeln;
end.
View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/FPC-on-Rpi3-executable-module-sizes-tp4050126p4050129.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Florian Klämpfl
to Ken Kashmarek
Ken Kashmarek wrote
This is clearly an error where each addition adds 200k (or more) the the executable file.

Those units contain initialization sections which drag in a lot of code. You might want to try to strip explicitly unused symbols by compiling with -Xs.

I do note however, that all 3 uses entries on Windows 7, brings the executable up to more than 240K (significantly smaller than the RPi3 install of FCP produces).

I guess the reason is that you are using the variants unit. On windows, most of the variants stuff can be handled by the OS. On unix style systems, everything is handled by FPC libraries which emulate how windows handles variants.

Show quoted text 12 lines
uses sysutils; // , variants, classes; type ptr2Byte = ^Byte; comp = int64; var i,j: integer; begin writeln; i := 4096; writeln('Value of i = ',i:8); writeln('--> Execution of (nearly) null program ended.'); writeln; end.

Reply by email

Sascha Hestermann
to Ken Kashmarek: FCP on Rapsberry Pi3 On my Window 7 node, a null program produces this output when…
Ken Kashmarek wrote 7 lines
On the RPi3, goes up to over 400K in size. If 3 items are in the uses line, the RPi3 executable exceeds 800K. This is clearly an error where each addition adds 200k (or more) the the executable file. I do note however, that all 3 uses entries on Windows 7, brings the executable up to more than 240K (significantly smaller than the RPi3 install of FCP produces).

It seems that you are using Linux on your RPi3 and when I compile any project on my Linux desktop box I get the following compiler message: "Note: DWARF debug information cannot be used with smart linking on this target, switching to static linking"
So even after stripping the debug symbols the size is significantly larger because of the deactivated smart linking.

As far as I remember this happens with all of the possible debug formats I can choose from. So to allow smart linking you probably have to disable the generation of debug symbols completely. (Though I have never used the RPi3 target, so I can only guess from using x86 Linux.)

By the way if you are using Lazarus, the compiler note is hidden by default: Right click in the message window -> "Filter Hints without Source Position"

Reply by email

Ken Kashmarek
to Sascha Hestermann

I used Bo Berglund's script to install FPC (including Lasarus) on my RPi3. That script is long and complicated and making changes to it would be in his domain. I suspect there are some issues with any options dealing with smart linking and debug symbols. I hope he gets a chance to review the script in this regard. If your 'uses' clause includes several items, that can easily drive the executable file size over a megabyte (disasterous on any Raspberry Pi node). With no 'uses' clause, over 200K is added to the executable file anyway.

By the way, since this isn't a normal apt-get style install, deleting the result of a successful execution of Bo's script, will be quite an effort. The install itself does add 840 meg to your SD card (all the source files and bloated library files of every kind).

Ken

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/FPC-on-Rpi3-executable-module-sizes-tp4050126p4050151.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Sascha Hestermann
to Ken Kashmarek
Ken Kashmarek wrote
I used Bo Berglund's script to install FPC (including Lasarus) on my RPi3. That script is long and complicated and making changes to it would be in his domain.

I understand that changing the installation can be a bit complicated. But I was actually referring to the settings of your particular project. I neither have experience with the RPi3 nor with compilation in command line, but if I compile my project without any "-g" options I can use smart linking and otherwise not.

But anyways if that is the problem in your case you should get a warning like in my previous mail. So it should be easy to check if that is the cause of the growth in size.

It was just an idea to look for because that message can easily be overlooked (at least in Lazarus).

Reply by email

Ken Kashmarek
to Sascha Hestermann

I have solved the problem with modules sizes when compiled under Lazarus FPC 3.0.0 on RPi3.

First, I am able to perform scripted compile and link operations (ie, not done via the IDE).

Next, by adding the -XX parameter to the compile/link script file, that is:

fpc -XX sourcefile.pas

the resulting executable file sizes are comparable to those created on Windows 7. That is, a 400K executable size drops to approximately 100K.

Finally, the install of the compiler is in /usr/lib on the RPi3 SSD card.

View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/FPC-on-Rpi3-executable-module-sizes-tp4050126p4050490.html Sent from the Free Pascal - Lazarus mailing list .

Reply by email

Lars
to Ken Kashmarek
Ken Kashmarek wrote 7 lines
I have solved the problem with modules sizes when compiled under Lazarus FPC 3.0.0 on RPi3. First, I am able to perform scripted compile and link operations (ie, not done via the IDE).

Another option is to write your script, and launch it with a tools menu item in the ide. Not integrated compiling, but at least you can compile it from a menu item in the ide.

Tools -> Configure External Tools

Then at least you don't have to run to the command line window manually, you just click a menu item button or use a keyboard shortcut

Reply by email