This is the mail archive of the
mailing list for the binutils project.
Re: [gold] enable sorting of text sections with the same prefix
- From: Sriraman Tallam <tmsriram at google dot com>
- To: Alexander Ivchenko <aivchenk at gmail dot com>
- Cc: binutils <binutils at sourceware dot org>
- Date: Mon, 4 Feb 2013 11:40:05 -0800
- Subject: Re: [gold] enable sorting of text sections with the same prefix
- References: <CACysShgOdS0GdKBjzCkOK8fXTEjvvaBkP_=nchX2iayG4LpDAA@mail.gmail.com> <CAAs8HmyUAy7HzT_xT45RK4EVqjU_N8yZt8PJ4rCxT-MzFEMv9g@mail.gmail.com> <CACysShgLG9UnMuPKMDsuDb-zRfQpt0ogrsY+4Vjiuyb1mg5D+Q@mail.gmail.com> <CAAs8HmycT3pW8x-Ahq+pjmY+oNoPdcS_5HezZr6FAheDSF-qWQ@mail.gmail.com> <CACysShikL0QsKWUx7DPqnNsV2w+ujTJqUEQtufqYVNxayrg_YQ@mail.gmail.com>
@@ -3527,8 +3528,16 @@
return o1 < o2;
+ if (strcmp(parameters->options().sort_section(), "name") == 0)
+ // Within each prefix we sort by name.
+ int compare = s1.section_name().compare(s2.section_name());
+ if (compare != 0)
+ return compare < 0;
I think you can create a new compare function for this. You can rename
the existing function to something like
"Input_section_sort_section_prefix_special_ordering_compare" and make
a new "Input_section_sort_section_name_compare". Sorting by section
name also ensures the grouping of functions with prefixes like
".text.hot", only the entire .text.hot could land up somewhere in the
middle of all functions.
However, if you do want both special ordering and sorting by section
name, I think you should move the strcmp out of the compare function
as the compare function is called many times. A simple bool function
somewhere in layout would be fine I think.
On Mon, Feb 4, 2013 at 4:15 AM, Alexander Ivchenko <firstname.lastname@example.org> wrote:
> The attached patch implements --sort-section=name that sorts text
> sections by name within each
> prefix and also sorts .data and .sdata sections by name (as BFD does).
> That is enough for closing
> that http://sourceware.org/bugzilla/show_bug.cgi?id=14948
> thank you,
> 2013/1/29 Sriraman Tallam <email@example.com>:
>> On Tue, Jan 29, 2013 at 9:55 AM, Alexander Ivchenko <firstname.lastname@example.org> wrote:
>>> Hello Sri,
>>> thank you for your input!
>>> Please, look at
>> So, why not do this guarded by --sort-section=name just like BFD ld?
>> That way, it does not affect the default. Just my two cents.
>>> thank you,
>>> 2013/1/29 Sriraman Tallam <email@example.com>:
>>>> On Tue, Jan 29, 2013 at 7:28 AM, Alexander Ivchenko <firstname.lastname@example.org> wrote:
>>>>> This patch to gold: http://sourceware.org/ml/binutils/2013-01/msg00335.html
>>>>> disabled sorting of text sections with the same prefix like
>>>>> .text.hot0001, .text.hot0002
>>>>> which is very desirable.
>>>> Sorting by section names in general for text sections turns out to be
>>>> a bad idea as we have seen many performance issues. That is the reason
>>>> why the patch you reference was created.
>>>> The reason why some text sections are grouped to begin with is to
>>>> mimic the default GNU ld behaviour. I dont think GNU ld groups these
>>>> two sections. AFAIK, ".text.hot." is the prefix for hot text
>>>> sections. How were these two sections you mention created?Which
>>>> compiler is generating these two sections? Or, did you explicitly use
>>>> a section attribute?
>>>> The attached patch fix this.
>>>>> OK for trunk?
>>>>> thank you,