This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Introduce new .text.sorted.* sections.
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Martin Liška <mliska at suse dot cz>
- Cc: Alan Modra <amodra at gmail dot com>, Binutils <binutils at sourceware dot org>, Ian Lance Taylor <iant at golang dot org>
- Date: Fri, 22 Nov 2019 11:39:39 -0800
- Subject: Re: [PATCH] Introduce new .text.sorted.* sections.
- References: <caa076c6-e356-f5e3-756d-eb1bbf498293@suse.cz> <20190925133427.GE19242@bubble.grove.modra.org> <501c6840-5c5f-2610-d0f9-aec269d07fda@suse.cz> <20190927074857.GC15102@bubble.grove.modra.org> <b19575b8-0524-6837-d081-1019e392b139@suse.cz> <e3625344-8771-fc66-6b4f-9cd1f94c211a@suse.cz>
>
> >>>> This looks fine to me, even though the gold implementation can produce
> >>>> different results on input sections that match ".text.sorted.*". For
> >>>> example, ".text.sorted.1" will be accepted by both ld.gold and ld.bfd,
> >>>> but ld.bfd will sort it after ".text.sorted.02" while ld.gold would
> >>>> sort it before.
> >>>
> >>> Hi.
> >>>
> >>> You are right, it's not precisely 1:1 among ld.bfd and ld.gold. I guess
> >>> we can live with that.
@@ -1132,12 +1132,15 @@ Layout::special_ordering_of_input_section(const
char* name)
".text.hot"
};
- for (size_t i = 0;
- i < sizeof(text_section_sort) / sizeof(text_section_sort[0]);
- i++)
+ unsigned scount = sizeof(text_section_sort) /
sizeof(text_section_sort[0]);
+ for (size_t i = 0; i < scount; i++)
if (is_prefix_of(text_section_sort[i], name))
return i;
+ int order;
+ if (sscanf (name, ".text.sorted.%d", &order) == 1)
+ return order + scount;
+
return -1;
}
Please declare scount as "const int" or "const size_t", and move the
declaration up to just under the declaration of text_section_sort.
Also, no space before "(" in C++ coding conventions.
Using sscanf this way will end up ignoring any non-digits that might follow
the index -- e.g., ".text.sorted.0001.foo". If that's the behavior you
want, fine (I guess), but if you want to sort based on whatever arbitrary
string follows ".text.sorted.", you'll need to add some extra logic
to Output_section::Input_section_sort_section_prefix_special_ordering_compare().
In that case, you can just add ".text.sorted" to the list in
text_section_sort.
I'm concerned about the different behavior between bfd ld and gold, as
sooner or later, someone's going to notice that they can use strings
instead of numbers to control the sort in bfd ld, and then complain that it
doesn't work in gold.
-cary