Recent

Author Topic: [SOLVED] Linux binaries too big  (Read 15173 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Linux binaries too big
« Reply #15 on: January 15, 2017, 04:09:00 pm »
First: the compiler itself does not matter but the RTL and FCL and the FPC packages should...be build with -Cg -Xc -XX -CX and maybe -Xs
Second: Why would you need Forms and Interfaces in a shared library? That is bad practice: It will pull in ALL code, since a shared library will never be able to distinguish what you need.
A simple shared library is a few KB on Linux. Add classes for some Pzazz and it is still under 1 MB. (867 KB on ARM-LINUX.Note it still pulls in ALL of classes)
Code: Pascal  [Select][+][-]
  1. library project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes{, Forms, Interfaces //are bad design!! for a shared library}
  7.   { you can add units after this };
  8.  
  9. begin
  10. end.  

The template for a shared library looks plainly stupid for Linux, but also in general.
Sensible programmers won't put any GUI code in a shared library. Unless it IS the shared library, e.g. GTK+ or QT.
« Last Edit: January 15, 2017, 05:35:27 pm by Thaddy »
Specialize a type, not a var.

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Linux binaries too big
« Reply #16 on: January 16, 2017, 01:53:49 pm »
First: the compiler itself does not matter but the RTL and FCL and the FPC packages should...be build with -Cg -Xc -XX -CX and maybe -Xs

Could you achieve with these options, that the compiled shared library under Linux has similar size as on Windows? I've rebuilt whole FPC (which means compiler+rtl+packages) with options -CX -XX -Xs (options -Cg and -Xc were not accepted and always resulted in misc. compilation errors) then took these options for my project and made Clean+Rebuild. And did not succeed, binary size is still around 3x bigger for a SO than for a DLL.

Second: Why would you need Forms and Interfaces in a shared library? That is bad practice: It will pull in ALL code, since a shared library will never be able to distinguish what you need.

I have good reasons why to do that for some of my libraries, but that is not the issue we discuss here. The same difference (SO 3x bigger than DLL) I see for any library, whether LCL is included or not.

A simple shared library is a few KB on Linux. Add classes for some Pzazz and it is still under 1 MB. (867 KB on ARM-LINUX.Note it still pulls in ALL of classes)
Unfortunately I do not have simple libraries. Compare library size for a library that takes min. 200kB on Windows. What takes it on your Linux then?

The template for a shared library looks plainly stupid for Linux, but also in general.
The default library template in Lazarus of course comes without any LCL dependency.
« Last Edit: January 16, 2017, 01:55:33 pm by tk »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Linux binaries too big
« Reply #17 on: January 16, 2017, 02:38:57 pm »
Quote
Unfortunately I do not have simple libraries. Compare library size for a library that takes min. 200kB on Windows. What takes it on your Linux then?

Depends: between 253 K and 800K.
Specialize a type, not a var.

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Linux binaries too big
« Reply #18 on: January 16, 2017, 03:11:25 pm »
Depends: between 253 K and 800K.

Same lpi, same bitness, same compiler options, 253K a SO on Linux and 200K a DLL on Windows?
If yes then I don't believe you. Make a proof.
« Last Edit: January 16, 2017, 03:14:26 pm by tk »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Linux binaries too big
« Reply #19 on: January 16, 2017, 03:34:01 pm »
Make a proof.
I interpreted it differently - I tested one simple and one complex shared lib - but this should be around 250k on arm-linux. On Windows and 32bit intel  linux it is much smaller:
Code: [Select]
library simple;
{$CALLING C}
uses initc; // this is actually needed for an so to make it callable from other languages.

function AddMe(const a,b:integer):integer;
begin
  AddMe := a+b;
end;

exports AddMe;
begin
end.

Ps. the .o for this is just 2667 bytes on arm.
Specialize a type, not a var.

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Linux binaries too big
« Reply #20 on: January 16, 2017, 04:29:43 pm »
I interpreted it differently

Let's stay on i386 for simplicity. Tried your small lib now on Win,Linux,OS X. Results attached. Still Linux binary has the biggest size (dll is even 5 times smaller than so).
.o files are completely different matter I think, their sizes are similar.

However, these small libs are not representative enough for the problem described in my first post.
Because IMO here the binary file overhead and/or RTL differences clearly win against the size of compiled user code.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Linux binaries too big
« Reply #21 on: January 16, 2017, 05:15:45 pm »
Hello.

The size of fpc libraries are too big because dynamic runtime packages are not supported yet.

But it is WIP.

http://free-pascal-general.1045716.n5.nabble.com/Size-of-program-vs-library-td5718200.html

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Linux binaries too big
« Reply #22 on: January 16, 2017, 06:06:39 pm »
Yes. But that is a one time penalty,about 200K-250K, and the size should not grow significantly in size compared to a dll except for that 200K-250K penalty that is the runtime lib.
That means the sizes should converge to a similar size with larger dynlibs. And that is what I see.
Specialize a type, not a var.

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: Linux binaries too big
« Reply #23 on: January 16, 2017, 07:44:27 pm »
That means the sizes should converge to a similar size with larger dynlibs. And that is what I see.

Unfortunatelly that is what I don't see.

EDIT: Finally I solved this by adding -k--gc-sections to compiler options. Now the linux builds have similar size as OSX dylibs, which is ca 1.4x the size of Windows DLLs. And the Linux build map file finally shows the removed sections. I don't know why, because I have -XX option checked, but it works.
« Last Edit: January 16, 2017, 10:55:18 pm by tk »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: [SOLVED] Linux binaries too big
« Reply #24 on: February 11, 2017, 08:01:15 pm »
If you compile with the -Cn command line parameter, you should be able to see which parameters FPC is passing to ld by looking at the generated ppas.sh file.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: [SOLVED] Linux binaries too big
« Reply #25 on: February 11, 2017, 08:59:47 pm »
I want my executable to include anything it might even remotely need. Because I want it to run on all the different versions.

It's called "dll hell", although they could be called .so or whatever instead.

If you want tiny, you also want endless dependencies.

 

TinyPortal © 2005-2018