Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
LDFLAGS Central
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
taviso
Retired Dev
Retired Dev


Joined: 15 Apr 2003
Posts: 261
Location: United Kingdom

PostPosted: Wed Jul 16, 2003 4:28 pm    Post subject: LDFLAGS Central Reply with quote

You may or may not be aware that the next versions of portage will probably support $ASFLAGS and $LDFLAGS, options that are usually passed to the assembler and linker during the build process.

There are even patches on gentoo-dev to add this support, although you can still use $LDFLAGS and $ASFLAGS without this patch, just by setting them in /etc/make.conf.

http://marc.theaimsgroup.com/?l=gentoo-dev&m=105793517425320&w=2

$ASFLAGS is not particularly useful, it will probably be supported only for completeness. $LDFLAGS, however, could be useful and I have been experimenting recently to see what exactly can be done with them.

First of all, you can benchmark dynamic linking using the $LD_DEBUG variable, for example:

Code:
taviso@insomniac:~$ LD_DEBUG=statistics sh -c true
12937: 
12937:  runtime linker statistics:
12937:    total startup time in dynamic loader: 1108348 clock cycles
12937:              time needed for relocation: 572272 clock cycles (51.6%)
12937:                   number of relocations: 132
12937:        number of relocations from cache: 5
12937:             time needed to load objects: 335136 clock cycles (30.2%)
12937: 
12937:  runtime linker statistics:
12937:             final number of relocations: 204
12937:  final number of relocations from cache: 5


as you can see, you can get the dynamic loader to print out lots of interesting stats, mostly measured in clock cycles.

These are some of the ld options that look interesting:


  • -O level
    If level is a numeric values greater than zero ld optimizes the output.
  • --sort-common
    This is to prevent gaps between symbols due to alignment constraints, presumably increasing efficiency layout.
  • --no-keep-memory
    This option tells ld to optimize for memory usage rather than speed, by rereading the symbol tables as necessary instead of caching it in memory.
  • -z now
    Lazy binding is really clever, rather than loading all shared code into memory at runtime, the dynamic loader locates them, and just keeps track of it, when a reference is made to the shared code, then it is loaded memory. This saves some memory, and speeds up startup. Using -z now disables lazy binding, which means slower startup, possibly more memory usage, but better runtime performance.
    You can test how this will effect a particular application by setting $LD_BIND_NOW, and testing responsiveness or timing some task, for example:
    Code:
    taviso@insomniac:~$ LD_BIND_NOW=1 mozilla



I Should also point out that when gcc is used to indirectly call ld, it wont always pass the $LDFLAGS to the linker, to force it to you must use the -Wl switch, all spaces in the switch must be substituted with commas. These are my $LDFLAGS, to demonstrate:

Code:
LDFLAGS="-Wl,-O1 -Wl,--sort-common -s"

References I used to collect this information, you can read these for more information:


note: this post is 2 years old, i've made a few updates to reflect that.
_________________
--------------------------------------
Gentoo on Alpha, is your penguin 64bit?
--------------------------------------------------------


Last edited by taviso on Wed Jan 19, 2005 11:11 pm; edited 7 times in total
Back to top
View user's profile Send private message
aardvark
Guru
Guru


Joined: 30 Jun 2002
Posts: 576

PostPosted: Wed Jul 16, 2003 5:01 pm    Post subject: Reply with quote

I don't quite understand your line here. One would not expect a "," between -z and combreloc.

Code:

LDFLAGS="-Wl,-z,combreloc -Wl,-O,2 -Wl,--relax -Wl,--enable-new-dtags -Wl,--sort-common -s"


Furthermore I am pretty sure that at some point in gentoo history , with certain binutils and glibc, " -z combreloc " is enabled by default when U emerge something in portage. (Just default for the compiler)

You can see that it is enabled (this is when it was introduced) by:
Code:

bash-2.05b$ LD_DEBUG=statistics konqueror
04646:
04646:  runtime linker statistics:
04646:    total startup time in dynamic loader: 1595176706 clock cycles
04646:              time needed for relocation: 1044423406 clock cycles (65.4%)
04646:                   number of relocations: 29638
04646:        number of relocations from cache: 54945
04646:             time needed to load objects: 550219972 clock cycles (34.4%)
mcop warning: user defined signal handler found for SIG_PIPE, overriding
ASSERT: "m_widget" in kaction.cpp (2993)
04646:
04646:  runtime linker statistics:
04646:             final number of relocations: 47460
04646:  final number of relocations from cache: 109400


The cached relocations indicate that it is enabled. before combreloc there where no cahced relocation. Do you have some proof that it helps to enable it in your LDFLAGS explicitly?
Back to top
View user's profile Send private message
taviso
Retired Dev
Retired Dev


Joined: 15 Apr 2003
Posts: 261
Location: United Kingdom

PostPosted: Wed Jul 16, 2003 5:16 pm    Post subject: Reply with quote

aardvark wrote:
I don't quite understand your line here. One would not expect a "," between -z and combreloc.


The comma is correct, it is stripped out by gcc when it calls the linker.

Quote:
Furthermore I am pretty sure that at some point in gentoo history , with certain binutils and glibc, " -z combreloc " is enabled by default when U emerge something in portage. (Just default for the compiler)


Not as far as i am aware.
_________________
--------------------------------------
Gentoo on Alpha, is your penguin 64bit?
--------------------------------------------------------
Back to top
View user's profile Send private message
aardvark
Guru
Guru


Joined: 30 Jun 2002
Posts: 576

PostPosted: Wed Jul 16, 2003 5:37 pm    Post subject: Reply with quote

Ok, but would

Code:

LDFLAGS="-z combreloc"


work?
(I only want combreloc, that I still think I already have anyway :) )
Back to top
View user's profile Send private message
taviso
Retired Dev
Retired Dev


Joined: 15 Apr 2003
Posts: 261
Location: United Kingdom

PostPosted: Wed Jul 16, 2003 5:47 pm    Post subject: Reply with quote

aardvark wrote:
Ok, but would

Code:

LDFLAGS="-z combreloc"


work?

yep, -z xxx is really the exception to the rule, gcc understands that its always a linker invocation option. I only used it with -Wl for consistency. The guide was only a reference, i thought maybe some other people who like to tinker would enjoy it.

Quote:
(I only want combreloc, that I still think I already have anyway )

incidentally, combreloc is the default linker script in recent versions of ld.
_________________
--------------------------------------
Gentoo on Alpha, is your penguin 64bit?
--------------------------------------------------------
Back to top
View user's profile Send private message
aardvark
Guru
Guru


Joined: 30 Jun 2002
Posts: 576

PostPosted: Sun Jul 20, 2003 7:37 am    Post subject: Reply with quote

taviso wrote:
[
incidentally, combreloc is the default linker script in recent versions of [url=http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ChangeLog?cvsroot
=src]ld[/url].


And that means that it is enabled on my system already?
Back to top
View user's profile Send private message
deadbeef
n00b
n00b


Joined: 14 Nov 2003
Posts: 1

PostPosted: Fri Nov 14, 2003 4:01 pm    Post subject: Reply with quote

I have to rebuild my system tomorrow, I'm going to try this out.

I'll do some benchmarks before+after & post back any results.

-0xdb
Back to top
View user's profile Send private message
pennedinil
Tux's lil' helper
Tux's lil' helper


Joined: 08 Aug 2003
Posts: 95

PostPosted: Sat Oct 09, 2004 5:14 am    Post subject: Reply with quote

For completeness, should the flags not be
Code:

LDFLAGS="-Wl,-O1 -Wl,--relax -Wl,--enable-new-dtags -Wl,--sort-common -Wl,-s"
Back to top
View user's profile Send private message
Hackeron
Guru
Guru


Joined: 01 Nov 2002
Posts: 307

PostPosted: Fri Oct 15, 2004 10:48 pm    Post subject: Reply with quote

breaks emacs compile! -- everything else so far compiles just fine, but emacs says:

Code:
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../../i686-pc-linux-gnu/bin/ld: unrecognized option '-Wl,-O1'
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/../../../../i686-pc-linux-gnu/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
make[1]: *** [temacs] Error 1
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Wed Jan 19, 2005 11:14 am    Post subject: Reply with quote

This is my ldflags.

Code:
LDFLAGS="-Wl,-O1"


I read that in another thread somewhere on here. Is that safe? Does it help any? Is there a better setting for my rig? Are they rig specific? I'm not a guru regardless of what is under my name over there. :roll: Hmmm. Now it says l33t. Wonder when that changed. :oops:

AMD 2500+ CPU and 1GB of ram. I like speed, I am using Gentoo :D, but I also want stability. I am almost to 70 days uptime. Woooo Ooooo.

Thanks.

:D :D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
taskara
Advocate
Advocate


Joined: 10 Apr 2002
Posts: 3763
Location: Australia

PostPosted: Wed Jan 19, 2005 11:36 am    Post subject: Reply with quote

LDFLAGS are not hardware specific afaik.

So they will work on any system.

The initial post from 2003 suggests
Code:
LDFLAGS="-Wl,-O1 -Wl,--relax -Wl,--enable-new-dtags -Wl,--sort-common -s"


but --relax is only for alpha, and --enable-new-dtags is the default for current binutils, and -s is not neccessary afaik because gentoo strips all packages by default.

so the only other thing you could try is

Code:
LDFLAGS="-Wl,-O1 -Wl,--sort-common"

_________________
Kororaa install method - have Gentoo up and running quickly and easily, fully automated with an installer!
Back to top
View user's profile Send private message
wrc1944
Advocate
Advocate


Joined: 15 Aug 2002
Posts: 3432
Location: Gainesville, Florida

PostPosted: Wed Jan 19, 2005 8:46 pm    Post subject: Reply with quote

After much thought, and a lot of reading, I just put

LDFLAGS="-Wl,-O1"

in my make.conf, and started an emerge -e system. I'm cruising along at 21 out of 103 to go, but am not seeing any LDFLAGS related stuff in the gcc output.

What output am I supposed to be looking for, and does it even show up in the output, like the CFLAGS do? In other words, how do I know if I'm really compiling with the LDFLAGS I set in .make.conf?

One more thing: I know it's -Wl (letter L, not numeric 1), but can't find anything regarding if -o1 is -o(letter o), or -0(numerical zero). Since I didn't know which, I pasted what was in the LDFLAGS post, and it seems to be working (shows up in emerge --info), but since I'm not seeing any LDFLAGS output I can identify, I'm still wondering if I have it correct.

Thanks,
wrc1944
_________________
Main box- AsRock x370 Gaming K4
Ryzen 7 3700x, 3.6GHz, 16GB GSkill Flare DDR4 3200mhz
Samsung SATA 1000GB, Radeon HD R7 350 2GB DDR5
OpenRC Gentoo ~amd64 plasma, glibc-2.36-r7, gcc-13.2.1_p20230304
kernel-6.7.2 USE=experimental python3_11
Back to top
View user's profile Send private message
SoTired
Apprentice
Apprentice


Joined: 19 May 2004
Posts: 174

PostPosted: Wed Jan 19, 2005 10:27 pm    Post subject: Reply with quote

The ldflags will only show up during an emerge during linking, which generally is very quick/easy to miss. If you watch an emerge and it gets to a point where you see a lot of .o files on one line, there should be ldflags there as well.

The 'O' is a capital letter o, just like O for gcc (cflags) they both turn on optimizations.

As reference, an example from my current compilation of gtk+:
Quote:
/bin/sh ../libtool --mode=link i586-pc-linux-gnu-gcc -pipe -Os -march=pentium -
mieee-fp -momit-leaf-frame-pointer -fforce-addr -freorder-blocks -fomit-frame-po
inter -fmove-all-movables -fmerge-all-constants -ftracer -finline-functions -fwe
b -frename-registers -fpeel-loops -fstack-protector -ffast-math -Wall -Wl,--ena
ble-new-dtags -Wl,--sort-common -s -o testtreesort testtreesort.o ../gdk-pixbuf
/libgdk_pixbuf-2.0.la ../gdk/libgdk-x11-2.0.la ../gtk/libgtk-x11-2.0.la
i586-pc-linux-gnu-gcc -pipe -Os -march=pentium -mieee-fp -momit-leaf-frame-point
er -fforce-addr -freorder-blocks -fomit-frame-pointer -fmove-all-movables -fmerg
e-all-constants -ftracer -finline-functions -fweb -frename-registers -fpeel-loop
s -fstack-protector -ffast-math -Wall -Wl,--enable-new-dtags -Wl,--sort-common -
s -o .libs/testtreesort testtreesort.o ../gdk-pixbuf/.libs/libgdk_pixbuf-2.0.so


Note the "-Wl,--enable-new-dtags -Wl,--sort-common".
Back to top
View user's profile Send private message
taipan67
l33t
l33t


Joined: 04 Dec 2004
Posts: 866
Location: England (i'm told...)

PostPosted: Thu Jan 20, 2005 9:19 pm    Post subject: Reply with quote

When did '-z combreloc' get edited out of the original post, & why?

I ask because i've just started a very careful rebuild, & had to remove it from my LDFLAGS to get 'glibc' to compile (it's doing so now - i hope it finishes okay... :? )
_________________
"Anyone who goes to see a psychiatrist should have their head examined!"
Back to top
View user's profile Send private message
taipan67
l33t
l33t


Joined: 04 Dec 2004
Posts: 866
Location: England (i'm told...)

PostPosted: Thu Jan 20, 2005 10:02 pm    Post subject: Reply with quote

taipan67 wrote:
When did '-z combreloc' get edited out of the original post, & why?

I ask because i've just started a very careful rebuild, & had to remove it from my LDFLAGS to get 'glibc' to compile (it's doing so now - i hope it finishes okay... :? )

Further to my previous post, because i'm using the 'nptl' USE-flag by itself, & not with the 'nptlonly' one, glibc gets built twice - once without nptl-support, & again with.

By chance, i happened to be watching the text scroll by when the second part of the build started, & noticed that the check for '-z combreloc' returned 'yes', whereas it returned 'no' on the first part (without nptl-support).

I'm not about to do another restart of the entire process to check this out, but i am surmising that an 'nptlonly' system wouldn't spit the '-z combreloc' LDFLAG back in my face. I don't think Gentoo's quite ready to be nptlonly, but i would like any guidance that might be available on whether or not i can put '-z combreloc' back in my LDFLAGS once glibc has finished compiling... :?:
_________________
"Anyone who goes to see a psychiatrist should have their head examined!"
Back to top
View user's profile Send private message
taviso
Retired Dev
Retired Dev


Joined: 15 Apr 2003
Posts: 261
Location: United Kingdom

PostPosted: Thu Jan 20, 2005 10:58 pm    Post subject: Reply with quote

taipan67 wrote:
i would like any guidance that might be available on whether or not i can put '-z combreloc' back in my LDFLAGS once glibc has finished compiling... :?:

combreloc has been the default linker script for a while now, you dont need it.
_________________
--------------------------------------
Gentoo on Alpha, is your penguin 64bit?
--------------------------------------------------------
Back to top
View user's profile Send private message
taipan67
l33t
l33t


Joined: 04 Dec 2004
Posts: 866
Location: England (i'm told...)

PostPosted: Thu Jan 20, 2005 11:13 pm    Post subject: Reply with quote

taviso wrote:

combreloc has been the default linker script for a while now, you dont need it.

Thanks for the reassurance - currently ploughing through gcc-3.4.3-compile without '-z combreloc'... :D
_________________
"Anyone who goes to see a psychiatrist should have their head examined!"
Back to top
View user's profile Send private message
wrc1944
Advocate
Advocate


Joined: 15 Aug 2002
Posts: 3432
Location: Gainesville, Florida

PostPosted: Thu Jan 20, 2005 11:45 pm    Post subject: Reply with quote

SoTired,
Thanks for the info. I got most of the way through emerge -e system, and came back in and my computer was off. Apparently my power supply failed, so I ordered a new 580 watt monster, and presently am back to my old mandrake backup box for a few days, so I can't see how these LDFLAGS work.. Haven't used this older box in about 3 months, and even though it has Mandrake 10.1 on it (just did it today), I'm now reminded of why I went to Gentoo Almost two years ago.
_________________
Main box- AsRock x370 Gaming K4
Ryzen 7 3700x, 3.6GHz, 16GB GSkill Flare DDR4 3200mhz
Samsung SATA 1000GB, Radeon HD R7 350 2GB DDR5
OpenRC Gentoo ~amd64 plasma, glibc-2.36-r7, gcc-13.2.1_p20230304
kernel-6.7.2 USE=experimental python3_11
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3505

PostPosted: Thu Mar 10, 2005 5:02 pm    Post subject: per-package LDFLAGS Reply with quote

Is there a way to get LDFLAGS tailored differently for a specific package, kind of like /etc/portage/package.use?

For most software the suggestions in this thread are good, but XOrg seems to think differently. (IIRC they mentioned security concerns) It will build with these flags, but complains every time and makes suggestions, though at the moment the only one I can remember is "-z now". For that matter, XOrg already strips a bunch of CFLAGS, maybe it a package has feelings that strong, they should strip and rework LDFLAGS, too.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
wrc1944
Advocate
Advocate


Joined: 15 Aug 2002
Posts: 3432
Location: Gainesville, Florida

PostPosted: Thu Mar 10, 2005 6:08 pm    Post subject: Reply with quote

Update:
I guess sometimes packages do strip LDFLAGS. I've been using the basic

LDFLAGS="-Wl,-O1"

for about three weeks now. In addition to a few emerge syncs and -upD worlds, I've also done an emerge -e system, and an emerge -e world during this time, with no problems, on two ~x86 systems with gcc-3.4.3-20050110. I've noticed the LDFLAGS showing up in the gcc output of some packages, but not in others.

I've had no issues so far, and no complaints.
_________________
Main box- AsRock x370 Gaming K4
Ryzen 7 3700x, 3.6GHz, 16GB GSkill Flare DDR4 3200mhz
Samsung SATA 1000GB, Radeon HD R7 350 2GB DDR5
OpenRC Gentoo ~amd64 plasma, glibc-2.36-r7, gcc-13.2.1_p20230304
kernel-6.7.2 USE=experimental python3_11
Back to top
View user's profile Send private message
Kyrra
n00b
n00b


Joined: 15 Jan 2003
Posts: 53
Location: Kansas

PostPosted: Sun Apr 03, 2005 5:28 pm    Post subject: Reply with quote

I had the same problem with using LDFLAGS to compile Emacs as listed in a post higher in this thread. But everything else I've compiled on my system hasn't had a problem with the LDFLAGS yet.
_________________
It's not what it is, it's something else.
-Kyrra
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sun Apr 03, 2005 11:57 pm    Post subject: Reply with quote

I was using this but was getting a error about lazy bindings: edit, notice that this line is commented out. :lol:

Code:
#LDFLAGS="-Wl,-O1"


I then changed back to this:

Code:
LDFLAGS='-Wl,-z,now'


I have not had any of those errors that I can see anyway.

Rig in sig if that matters. New one seems faster but not real sure though.

Later

:D :D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
infirit
l33t
l33t


Joined: 11 Jan 2003
Posts: 778
Location: Hoofddorp / The Netherlands

PostPosted: Fri Apr 08, 2005 8:38 pm    Post subject: Reply with quote

Another flag that I am looking into lately is -Wl,--as-needed. Some app break horibly but most benefit from it .

It all started with an editorial on osnews.com and this thread is a result of it.
_________________
EASY TO INSTALL = Difficult to install, but instruction manual has pictures.
Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
makzu
n00b
n00b


Joined: 28 Jun 2004
Posts: 42

PostPosted: Sat Apr 23, 2005 7:56 am    Post subject: Reply with quote

I'm looking around the man page for ld right now, wondering what else we can add into this. (Yes, I am a ricer, I have to make sure I'm not missing anything) Anyway, there's a few options that I'm a little curious about now, including:

Quote:
--strip-debug
Omit debugger symbol information (but not all symbols) from the
output file.

Debug information really isn't something that we need anyway, is it?

Quote:
--relax
An option with machine dependent effects. This option is only sup-
ported on a few targets.

On some platforms, the --relax option performs global optimizations
that become possible when the linker resolves addressing in the
program, such as relaxing address modes and synthesizing new
instructions in the output object file.

On some platforms these link time global optimizations may make
symbolic debugging of the resulting executable impossible. This is
known to be the case for the Matsushita MN10200 and MN10300 family
of processors.

On platforms where this is not supported, --relax is accepted, but
ignored.

Does this do anything at all on an x86 or amd64 machine?

Also, is --enable-new-dtags useful any more?
_________________
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe.
All mimsey were the borogroves,
And the mome raths outgrabe.
Back to top
View user's profile Send private message
schrepfler
n00b
n00b


Joined: 01 Mar 2004
Posts: 56
Location: Bologna, Italy

PostPosted: Tue May 31, 2005 9:31 pm    Post subject: Reply with quote

Are there any new tips for the use of LDFLAGS, what are some good configs for the 3.4, 3.4 and 4.0 compilers?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum