This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why "ld -r" should not be used as a replacement for "ar".


This is in response to Jan's comment in PR 349.  I'm hoping to educate a
wider audience. :)

Here are a few ways that an intermediate "ld -r" link stage can change
the output:

1) Sections can be placed differently.  Consider a -ffunction-sections
compilation, which puts function code in sections named after the
function.  If you have multiple occurrences of static functions with the
same name, "ld -r" will place all such functions together because same
name sections are combined.  This can cause worse icache performance
because you lose code locality.

2) Combination of sections with the same name might result in
"ld --gc-sections" not discarding as much garbage.

3) Combination of sections might overflow target limits.  This occurs on
targets that have limited range branch instructions, limited size
literal pools, constant sections, got etc., and that implement schemes
to handle overflow at final link.  Typically, such schemes work on input
sections as a unit, inserting long branch stubs between input sections,
or placing input sections in separate multi-toc or multi-got tables.
ie. There is no attempt to break apart an input section, because doing
so is a risky business.  A "ld -r" link stage can thus cause a final
link to fail that would otherwise succeed.  This actually happens
building libjava on powerpc64-linux mainline gcc, because libtool
unfortunately uses "ld -r".

Of course, none of the above would occur if "ld -r" didn't combine input
sections.  The trouble is that people use "ld -r" to do exactly that,
and would no doubt complain if we changed ld.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]