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.)
Created attachment 2088 [details] Test case
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.
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.
There is no ld option to do what you want. You would need to modify ldlang.c unique_section_p.
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.
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
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.