Smart Link definition ?

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Smart Link definition ?

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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
OK, somebody knows there what is smart-link.
Sorry for the noise.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

Graeme Geldenhuys-6
In reply to this post by fredvs
On 2016-10-07 14:19, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
Thanks Graeme. ;-)

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
Hello.

Could you, please, help me ?

Does somebody know if smart-link (-XX) is done by the compiler (fpc) or by the linker (ld) ?

Many thanks.

Fre;D
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

Jonas Maebe-2
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

denisgolovan
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" <[hidden email]>:

> 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 - [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

--
Regards,
Denis Golovan
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

leledumbo
Administrator
> Sorry, for the question, but is it really working for FPC+Lazarus?

Yes, links fine here, just eating quite significant amount of RAM.
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
In reply to this post by Jonas Maebe-2
> 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.

OK, perfect.

Many thanks.
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
In reply to this post by leledumbo
> 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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
Huh, sorry, it is me again...

About ld (the linker).

In ld doc:
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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

LacaK
In reply to this post by Jonas Maebe-2
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.

>
>> 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.
>
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

Jonas Maebe-2
In reply to this post by fredvs
fredvs wrote:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

Jonas Maebe-2
In reply to this post by LacaK
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

LacaK

>> 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

>
>> 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 ?

>   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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
In reply to this post by Jonas Maebe-2
fredvs wrote:

> 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 ;-)
Reply | Threaded
Open this post in threaded view
|

Re: Smart Link definition ?

fredvs
In reply to this post by Jonas Maebe-2
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 ;-)