This is the mail archive of the
mailing list for the binutils project.
Re: [gold] enable sorting of text sections with the same prefix
On Tue, Feb 12, 2013 at 9:21 AM, Ian Lance Taylor <firstname.lastname@example.org> wrote:
> On Tue, Feb 12, 2013 at 7:01 AM, Alexander Ivchenko <email@example.com> wrote:
>> 2013/2/9 Ian Lance Taylor <firstname.lastname@example.org>:
>>> On Fri, Feb 8, 2013 at 5:11 PM, Ian Lance Taylor <email@example.com> wrote:
>>>> On Thu, Feb 7, 2013 at 3:56 AM, Alexander Ivchenko <firstname.lastname@example.org> wrote:
>>>>> thank you for your help, Sri. I fixed help string and deleted warning.
>>>>> Ian, could you please take a look at the attached patch?
>>>> As far as I can see, with this patch, when you use
>>>> --sort-section=name, gold will only sort sections that start with
>>>> .data. and .bss. by name. Other sections remain unsorted. This does
>>>> not appear to be what the GNU linker does. The GNU linker appears to
>>>> sort all input sections by name when using --sort-section=name.
>>> Sorry, I guess that's not quite right. You call the sorting code one
>>> every section. But you only set must_sort_attached_input_sections on
>>> the .data and .bss sections. How can you get away with that?
>> You mean from hardcoding those names (.bss and .data) there? I'm not
>> sure so far,
>> but I know that BFD sorts them by name when we have -sort-section=name
>> and at the
>> same time, BFD doesn't sort, say,.sdata and .sbss.
>> Do we need to fully mimic the behavior of BFD for this option?
> We do not need to fully mimic GNU ld. However, we need to understand
> how and why GNU ld behaves the way it does. When I look at the GNU ld
> code, I don't see anything that restricts the effect of
> --sort-section=name to the .data and .bss sections. Nor is it
> documented to behave that way.
> The documentation of --sort-section=name for GNU ld is unfortunately
> tied to the notion of a default linker script, which gold does not
> share. Still, we ought to be able to come up with some plausible
> meaning for gold. And restricting the behaviour to .data and .bss
> does not make sense to me.
Why not sort all output sections when --sort-section=name is
specified? However, for special output sections like ctors, dtors,
init_array, fini_array, etc. the original sort compare function will
be used. For all other sections, use the new sort compare can be used.
No need to hard code any names.
> Also, in order for this to work correctly, you must call
> set_may_sort_attached_input_sections when you create the output
> section. You aren't doing that, and I'm surprised that your code is
> working reliably.
I missed this part completely when I was reviewing his code, sorry!. I
am not surprised his patch works for ".text" because the input
sections are retained as he can piggy back on default text sorting.
But, how does his test pass for bss and data? I will apply his patch
and find out.