This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Introduce new .text.sorted.* sections.


>
> >>>> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]