Bug 5323 - Assignment of grouped sections in linker script ignored
Summary: Assignment of grouped sections in linker script ignored
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-14 14:43 UTC by Tim Bagot
Modified: 2008-01-09 12:26 UTC (History)
2 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Last reconfirmed:


Attachments
Test case (542 bytes, application/octet-stream)
2007-11-14 14:46 UTC, Tim Bagot
Details
Add --discard-section-groups option to ld (1.18 KB, patch)
2008-01-07 11:04 UTC, Tim Bagot
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Bagot 2007-11-14 14:43:19 UTC
The test case I hope to be able to attach after submitting this bug is a .o file
generated by a recent g++. In addition to the normal .text section, it has an
out-of-line definition of an inline function foo() in its own section
.text._Z3foov, in section group _Z3foov . (There are no other sections in that
group.)

If I try feeding this object to ld -r -T test.ld where test.ld contains the
single line:

SECTIONS { .text : { *(.text .text.*) } }

then the .text._Z3foov section is not merged into the output .text section, but
passed through as-is, along with its containing group. Even with an input
specification of *(*), the grouped section and its group section remain
stubbornly separate. I would expect it to be mapped as specified in the script,
and the now empty section group to be discarded. Without -r, the script is
obeyed as expected (and section groups are removed anyway).

(In case you think I am doing something completely mad, what we are actually
trying to do is perform a partial link and localise nearly all resolved symbols,
so that we can perform a final link against libraries some of whose symbols we
would otherwise override. We are experiencing problems that appear to be caused
by conflicting section group names, and were surprised to discover the grouped
sections in the output of the first stage when our linker script looks like it
should already be catching them.)
Comment 1 Tim Bagot 2007-11-14 14:46:25 UTC
Created attachment 2088 [details]
Test case
Comment 2 Alan Modra 2007-11-14 15:33:01 UTC
This is done deliberately so that groups pass unscathed through ld -r. 
Otherwise you'd get .text in group foo being merged with .text in group bar and
with the non-group .text.
Comment 3 Tim Bagot 2007-11-14 15:50:12 UTC
But we do want those sections merged. How do we stop them being passed through
unscathed? I can't find any option to control that.
Comment 4 Alan Modra 2007-11-15 03:46:49 UTC
There is no ld option to do what you want.  You would need to modify ldlang.c
unique_section_p.
Comment 5 Tim Bagot 2008-01-07 11:04:54 UTC
Created attachment 2175 [details]
Add --discard-section-groups option to ld

The obvious change to unique_section_p didn't quite seem to be enough.
Following a slightly less refined approach, here is a patch against 2.18 adding
a --discard-section-groups option to ld that simply strips out all ELF section
groups in relocatable output, the same as for executable output (no docs I'm
afraid). I've just gone blundering in with my chainsaw, so there may be a few
rough edges.
Comment 6 Nick Clifton 2008-01-09 11:15:15 UTC
Hi Tim,

  I think that you are taking the wrong approach.  Either the compiler should
not be generating a group to contain the out-of-line function (if it just
contains a single section) or else you should accept that a section group is a
single entity that cannot be broken down and try to find a way improve the
naming of the groups so that they do not conflict with each other.

Cheers
  Nick
Comment 7 Tim Bagot 2008-01-09 12:26:35 UTC
gcc's naming is quite reasonable: the names of section groups (and the sections
in them) clash because the corresponding symbol names do. We are deliberately
using partial linking and localization of symbols in order to violate the one
definition rule. The section groups emitted by newer versions of gcc threw a
spanner in the works because although we could make the symbols local we
couldn't hide the section groups. The old-style linkonce sections could just be
folded into the desired output sections, whereas ld was stubbornly refusing to
let us have any say in what it does with grouped sections.

The option added by my patch doesn't break section groups apart, it eliminates
them in just the same way as a final link normally does. It's certainly crude,
but it does what we need it to, and is about the best we could manage with our
limited knowledge of ld internals. It may be useful for people doing something
similar, but not for anyone wanting finer control over section groups.