Sign in Join

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

Mailing lists / fpc-pascal / 2016-10

Smart Link definition ?

17 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

fredvs

Hello.

Who can explain what is smart linking ?
I can say that it tells the compiler to remove unneeded symbols but it is only my feeling.

There are no explanation in wikipedia and Googling did not help.

I ask you this because in FreeBSD forum they want to know what is smart-link (https://forums.freebsd.org/threads/57931/).

Many thanks.

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Smart-Link-definition-tp5726480.html Sent from the Free Pascal - General mailing list .
Graeme Geldenhuys
to fredvs: Hello. Who can explain what is smart linking ? I can say that it tells the compiler to…
fredvs wrote
I can say that it tells the compiler to remove unneeded symbols but it is only my feeling.

Yes, that is pretty much what it does. At the linking stage the compiler can determine what code is never used and exclude that from the binary - normally with a huge reduction in executable size (for real-world applications).

Here is the full description from the FPC Programmers Manual.

http://www.freepascal.org/docs-html/current/prog/progsu118.html#x126-1270001.3.35

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp
Jonas Maebe
to fredvs
fredvs wrote
Does somebody know if smart-link (-XX) is done by the compiler (fpc) or by the linker (ld) ?

It's done by the linker, but it is based on how the compiler structures/annotates the code and data when you compile with -CX.

Jonas

denisgolovan
to Jonas Maebe

Sorry, for the question, but is it really working for FPC+Lazarus? I mean FPC with smart-linking from trunk.

Last time I tried, I could not complete full FPC and Lazarus rebuild.

BR,
Denis

10.10.2016, 18:03, "Jonas Maebe" :

Show quoted text 11 lines
On 10/10/16 16:25, fredvs wrote: >  Does somebody know if smart-link (-XX) is done by the compiler (fpc) or by >  the linker (ld) ? It's done by the linker, but it is based on how the compiler structures/annotates the code and data when you compile with -CX. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Regards, Denis Golovan
fredvs
to leledumbo: Yes, links fine here, just eating quite significant amount of RAM. View this message in…
Sorry, for the question, but is it really working for FPC+Lazarus?

For Windows64+32, Linux64+32 it is working here perfectly. For FreeBSD, it is in discussion. ;-)

Yes just eating quite significant amount of RAM.

Ooops, I did not knew this...
Thanks for the tip.

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Smart-Link-definition-tp5726480p5726517.html Sent from the Free Pascal - General mailing list .
fredvs
to fredvs

Huh, sorry, it is me again...

About ld (the linker).

In ld doc:
http://sourceware.org/binutils/docs-2.16/ld/Options.html <http://sourceware.org/binutils/docs-2.16/ld/Options.html>

=> -X --discard-locals
Delete all temporary local symbols. For most targets, this is all local symbols whose names begin with L.

I guess that the fpc compiler option -CX is using that ld option -X to "smart-link" their program.
Without any "customization" (yes/no ?).

If so, ld is responsable of the "smart-linking" and fpc has nothing to do with it (yes/no ?).

And, of course, if it is the case, it should be the responsibility of ld to take care about the sym-link that he creates. (yes/no?)

Many thanks.

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Smart-Link-definition-tp5726480p5726518.html Sent from the Free Pascal - General mailing list .
LacaK
to Jonas Maebe: It's done by the linker, but it is based on how the compiler structures/annotates the…

Hi,
What is difference between "Link smart (-XX)" and "Smart linkable (-XC)" ? -XC is by default off and corresponds to per unit {$SMARTLINK OFF/ON} ?

Does it means, that compiler/linker is trying "Link smart", but only units marked "Smart linkable" ?
Which means, that when I use in my program StrUtils or SysUtils and I use only one function from these unit, in my program executable will be all function presented in these units ?

Thanks
-Laco.

Show quoted text 9 lines
> Does somebody know if smart-link (-XX) is done by the compiler (fpc) > or by > the linker (ld) ? It's done by the linker, but it is based on how the compiler structures/annotates the code and data when you compile with -CX.
Jonas Maebe
to fredvs: Huh, sorry, it is me again... About ld (the linker). In ld doc:…
fredvs wrote 14 lines
In ld doc: http://sourceware.org/binutils/docs-2.16/ld/Options.html <http://sourceware.org/binutils/docs-2.16/ld/Options.html> => -X --discard-locals Delete all temporary local symbols. For most targets, this is all local symbols whose names begin with L. I guess that the fpc compiler option -CX is using that ld option -X to "smart-link" their program. Without any "customization" (yes/no ?). If so, ld is responsable of the "smart-linking" and fpc has nothing to do with it (yes/no ?).

None of the above has anything to do with smart linking/dead code stripping. It's about removing symbols (not the code/data they point to) from the symbol table of the linked program.

Jonas

Jonas Maebe
to LacaK: What is difference between "Link smart (-XX)" and "Smart linkable (-XC)" ? -XC is by…
LacaK wrote
What is difference between "Link smart (-XX)" and "Smart linkable (-XC)" ? -XC is by default off and corresponds to per unit {$SMARTLINK OFF/ON} ?

-CX (not -XC) means "generate code that can be smart linked by the linker if you specify -XX while compiling a program that uses this unit".

Does it means, that compiler/linker is trying "Link smart", but only units marked "Smart linkable" ?

Yes.

Which means, that when I use in my program StrUtils or SysUtils and I use only one function from these unit, in my program executable will be all function presented in these units ?

The top-level FPC makefile builds all units smart-linkable if the target OS is one of "win32 go32v2 linux freebsd netbsd openbsd netware netwlibc darwin". I guess win64 should be added to that list (once someone verifies this doesn't cause test suite regressions).

Jonas

LacaK
to Jonas Maebe
> What is difference between "Link smart (-XX)" and "Smart linkable (-XC)" ? > -XC is by default off and corresponds to per unit {$SMARTLINK OFF/ON} ? -CX (not -XC) means "generate code that can be smart linked by the linker if you specify -XX while compiling a program that uses this unit".

Clear.
Can this be somewhere documented ?
For example:
http://www.freepascal.org/docs-html/prog/progse30.html#x196-2010007.3

Show quoted text 9 lines
> Does it means, that compiler/linker is trying "Link smart", but only > units marked "Smart linkable" ? Yes. > Which means, that when I use in my program StrUtils or SysUtils and I > use only one function from these unit, in my program executable will be > all function presented in these units ? The top-level FPC makefile builds all units smart-linkable

do you mean all units in RTL or FCL or also user program units ?

Show quoted text 6 lines
if the target OS is one of "win32 go32v2 linux freebsd netbsd openbsd netware netwlibc darwin". I guess win64 should be added to that list (once someone verifies this doesn't cause test suite regressions).

Ooo it will be very good IMO ;-)

-Laco

fredvs
to Jonas Maebe: None of the above has anything to do with smart linking/dead code stripping. It's about…
fredvs wrote 14 lines
In ld doc: http://sourceware.org/binutils/docs-2.16/ld/Options.html <http://sourceware.org/binutils/docs-2.16/ld/Options.html> => -X --discard-locals Delete all temporary local symbols. For most targets, this is all local symbols whose names begin with L. I guess that the fpc compiler option -CX is using that ld option -X to "smart-link" their program. Without any "customization" (yes/no ?). If so, ld is responsable of the "smart-linking" and fpc has nothing to do with it (yes/no ?).

None of the above has anything to do with smart linking/dead code stripping. It's about removing symbols (not the code/data they point to) from the symbol table of the linked program.

_______________________

Hello and thanks for answer.

OK, so what fpc does if -XX is used ?
Does fpc sent some parameters to ld and if yes what parameters ?

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Smart-Link-definition-tp5726480p5726536.html Sent from the Free Pascal - General mailing list .
fredvs
to Jonas Maebe: -CX (not -XC) means "generate code that can be smart linked by the linker if you specify…

Hello.

OK, after check (adding -s parameter to have ppas.sh script for ld), it appears that -XX fpc parameter sent this option to ld:

--gc-sections

And this produce, sorry FreeBSD, bad linked 32 bit executable in FreeBSD, that is not possible to run in a 64 multi-arch FreeBSD.

So, I maintain that fpc is not guilty in that smartlink-saga, but ld 32 bit that was not good adapted from Linux.

And I am tired of the insults from FreeBSD forum.

Fre;D

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Smart-Link-definition-tp5726480p5726541.html Sent from the Free Pascal - General mailing list .