* * *

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

Thaddy

  • Hero Member
  • *****
  • Posts: 4650
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 »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

tk

  • Sr. Member
  • ****
  • Posts: 354
    • tkweb
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 »
Lazarus 1.7 with FPC 3.1.1.

http://www.tkweb.eu/

Thaddy

  • Hero Member
  • *****
  • Posts: 4650
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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

tk

  • Sr. Member
  • ****
  • Posts: 354
    • tkweb
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 »
Lazarus 1.7 with FPC 3.1.1.

http://www.tkweb.eu/

Thaddy

  • Hero Member
  • *****
  • Posts: 4650
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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

tk

  • Sr. Member
  • ****
  • Posts: 354
    • tkweb
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.
Lazarus 1.7 with FPC 3.1.1.

http://www.tkweb.eu/

Fred vS

  • Hero Member
  • *****
  • Posts: 1663
    • miXimum is the DJ's 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 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 4650
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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

tk

  • Sr. Member
  • ****
  • Posts: 354
    • tkweb
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 »
Lazarus 1.7 with FPC 3.1.1.

http://www.tkweb.eu/

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 556
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

  • Sr. Member
  • ****
  • Posts: 299
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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus