Discussion:
[fpc-pascal] Minimal size of compiled library (DLL under Windows)
LacaK via fpc-pascal
2021-04-03 11:22:23 UTC
Permalink
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Marco van de Voort via fpc-pascal
2021-04-03 12:56:20 UTC
Permalink
I am guessing, that there must be something in initialization sections
of units (SysUtils and Classes), which cause that some code is
included, right?
Can I somehow to avoid this grow of size (for example I need from
Classes only TFPList)?
Not in an easy way at the moment, I don't expect it to change anytime soon.

The problem is probably the streaming system that the compiler can't
easily determine if it is used runtime. This also has resourcestrings as
errors, uses typeinfo etc etc.  I also see interface related support
probably because tcomponent also implements interfaces.



_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-
LacaK via fpc-pascal
2021-04-06 07:33:52 UTC
Permalink
Post by Marco van de Voort via fpc-pascal
I am guessing, that there must be something in initialization
sections of units (SysUtils and Classes), which cause that some code
is included, right?
Can I somehow to avoid this grow of size (for example I need from
Classes only TFPList)?
Not in an easy way at the moment, I don't expect it to change anytime soon.
The problem is probably the streaming system that the compiler can't
easily determine if it is used runtime. This also has resourcestrings
as errors, uses typeinfo etc etc.  I also see interface related
support probably because tcomponent also implements interfaces.
What I can say is, that in initialization sections are touched:

SysUtils: WidestringManager, Exceptions, FormatSettings
Classes: TCriticalSection, TList, TThreadList, TComponent
(IUnknown,IDispatch, RegisterInitComponentHandler() -> var
InitHandlerList), Interface (var GlobalNameSpace: IReadWriteSync)

So we see that classes like TComponent and also interfaces are touched,
but they are used only in conjuction with initilizing some global
variables like InitHandlerList, GlobalNameSpace.

But these variables are never used in my library. Only again in
finalization sections of above mentioned units.

Does it means, that smart-linking can not remove this code due to usage
of this global variables in finalization section (resp. initialization
sections)?

Probably it is too hard task for linker to determine which code is realy
not needed ... WPO in this regard can not help?

-Laco.


_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepas
Jonas Maebe via fpc-pascal
2021-04-06 09:23:35 UTC
Permalink
Post by LacaK via fpc-pascal
So we see that classes like TComponent and also interfaces are touched,
but they are used only in conjuction with initilizing some global
variables like InitHandlerList, GlobalNameSpace.
But these variables are never used in my library. Only again in
finalization sections of above mentioned units.
They are used in your library as far as the linker is concerned, because
the init and finalisation sections are code like any other code.
Post by LacaK via fpc-pascal
Does it means, that smart-linking can not remove this code due to usage
of this global variables in finalization section (resp. initialization
sections)?
Indeed.
Post by LacaK via fpc-pascal
Probably it is too hard task for linker to determine which code is realy
not needed ... WPO in this regard can not help?
No. There is no way for WPO to know what side effects the initialisation
of those variables could have.


Jonas
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists
LacaK via fpc-pascal
2021-04-06 10:22:47 UTC
Permalink
May be, that important word is here "referenced" code.
Once some code (procedure, class) is referenced then this code is linked
/ included.
It does not play role if it is really required by program / library ...
right?

L.
Post by Jonas Maebe via fpc-pascal
Post by LacaK via fpc-pascal
So we see that classes like TComponent and also interfaces are touched,
but they are used only in conjuction with initilizing some global
variables like InitHandlerList, GlobalNameSpace.
But these variables are never used in my library. Only again in
finalization sections of above mentioned units.
They are used in your library as far as the linker is concerned, because
the init and finalisation sections are code like any other code.
Post by LacaK via fpc-pascal
Does it means, that smart-linking can not remove this code due to usage
of this global variables in finalization section (resp. initialization
sections)?
Indeed.
Post by LacaK via fpc-pascal
Probably it is too hard task for linker to determine which code is realy
not needed ... WPO in this regard can not help?
No. There is no way for WPO to know what side effects the initialisation
of those variables could have.
Jonas
_______________________________________________
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/
Jonas Maebe via fpc-pascal
2021-04-06 12:16:59 UTC
Permalink
Post by LacaK via fpc-pascal
May be, that important word is here "referenced" code.
Once some code (procedure, class) is referenced then this code is
linked / included.
It does not play role if it is really required by program / library ...
right?
It is impossible for a linker to know whether code is "really required".
It doesn't know what code does. It only knows whether or not it
(theoretically) can get executed.


Jonas
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pasc

Sven Barth via fpc-pascal
2021-04-03 16:23:37 UTC
Permalink
Hi,
(with -CX -WR -O3 -Xs -XX options set)
library library1;
{$mode objfpc}{$H+}
uses
SysUtils, Classes;
begin
end.
Compilation produces DLL with size 200+ KB.
When in uses is only SysUtils then size is under 100 KB.
Whene there are not units in uses clause then size is under 40 K B.
I am guessing, that there must be something in initialization sections of
units (SysUtils and Classes), which cause that some code is included, right?
Can I somehow to avoid this grow of size (for example I need from Classes
only TFPList)?
Everything that is touched by initialization or finalization sections, even
if nothing else is used, will be included.

Regards,
Sven
Continue reading on narkive:
Search results for '[fpc-pascal] Minimal size of compiled library (DLL under Windows)' (Questions and Answers)
9
replies
What is uTorrent?
started 2007-05-19 10:52:10 UTC
software
Loading...