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: [gold] Merging string literals with bigger alignment


On Thu, May 02, 2013 at 09:00:48AM -0700, Cary Coutant wrote:
> >> Thanks HJ, your patch cured my powerpc64 problem, but the x86_64 fail
> >> remains.
> >
> > I didn't see this failure on x86-64 with GCC 4.7 nor GCC 4.6.
> 
> I tried GCC 4.6 and 4.7 also, and didn't see a failure. Which failure
> are you seeing -- the basic_static_test bad_alloc, or the linker
> bootstrap test?

The basic_static_test bad_alloc.

Breakpoint 1, gold::Output_merge_string<char>::do_add_input_section (this=0x1228b70, object=0x16dbff0, shndx=6) at /src/binutils-current/gold/merge.cc:552
(gdb) p count
$9 = 494046755238

Wow! How did we get that number of strings on the following section?

objdump -sj.rodata.str1.8 mbrtowc.o

mbrtowc.o:     file format elf64-x86-64

Contents of section .rodata.str1.8:
 0000 73746174 7573203d 3d205f5f 47434f4e  status == __GCON
 0010 565f4f4b 207c7c20 73746174 7573203d  V_OK || status =
 0020 3d205f5f 47434f4e 565f454d 5054595f  = __GCONV_EMPTY_
 0030 494e5055 54207c7c 20737461 74757320  INPUT || status 
 0040 3d3d205f 5f47434f 4e565f49 4c4c4547  == __GCONV_ILLEG
 0050 414c5f49 4e505554 207c7c20 73746174  AL_INPUT || stat
 0060 7573203d 3d205f5f 47434f4e 565f494e  us == __GCONV_IN
 0070 434f4d50 4c455445 5f494e50 5554207c  COMPLETE_INPUT |
 0080 7c207374 61747573 203d3d20 5f5f4743  | status == __GC
 0090 4f4e565f 46554c4c 5f4f5554 50555400  ONV_FULL_OUTPUT.
 00a0 28286461 74612e5f 5f737461 74657029  ((data.__statep)
 00b0 2d3e5f5f 636f756e 74203d3d 20302900  ->__count == 0).

Ah!  Take a look at merge.cc:545.  len is set for the first string
and then the same value used for all subsequent strings.  The
shadowing of vars is horrible too.  A final nit: If the last string in
the section is missing a terminator, I think input_size_ ought to
include the missing terminator.

Oh, and the loop doesn't terminate due to pt < pend0 until we wrap..
(gdb) p len
$3 = -97 '\237'
(gdb) p sizeof(len)
$4 = 1

	* merge.cc (Output_merge_string::do_add_input_section): Correct
	scan for number of strings.  Rename vars to avoid shadowing.
	Include missing terminator in input_size_.

Index: gold/merge.cc
===================================================================
RCS file: /cvs/src/src/gold/merge.cc,v
retrieving revision 1.43
diff -u -p -r1.43 merge.cc
--- gold/merge.cc	1 May 2013 19:45:27 -0000	1.43
+++ gold/merge.cc	3 May 2013 00:27:17 -0000
@@ -505,17 +505,17 @@ bool
 Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
 						     unsigned int shndx)
 {
-  section_size_type len;
+  section_size_type sec_len;
   bool is_new;
   const unsigned char* pdata = object->decompressed_section_contents(shndx,
-								     &len,
+								     &sec_len,
 								     &is_new);
 
   const Char_type* p = reinterpret_cast<const Char_type*>(pdata);
-  const Char_type* pend = p + len / sizeof(Char_type);
+  const Char_type* pend = p + sec_len / sizeof(Char_type);
   const Char_type* pend0 = pend;
 
-  if (len % sizeof(Char_type) != 0)
+  if (sec_len % sizeof(Char_type) != 0)
     {
       object->error(_("mergeable string section length not multiple of "
 		      "character size"));
@@ -542,11 +542,14 @@ Output_merge_string<Char_type>::do_add_i
 
   // Count the number of non-null strings in the section and size the list.
   size_t count = 0;
-  for (const Char_type* pt = p, len = string_length(pt);
-       pt < pend0;
-       pt += len + 1)
-    if (len != 0)
-      ++count;
+  const Char_type* pt = p;
+  while (pt < pend0)
+    {
+      size_t len = string_length(pt);
+      if (len != 0)
+	++count;
+      pt += len + 1;
+    }
   if (pend0 < pend)
     ++count;
   merged_strings.reserve(count + 1);
@@ -595,7 +598,7 @@ Output_merge_string<Char_type>::do_add_i
   merged_strings.push_back(Merged_string(i, 0));
 
   this->input_count_ += count;
-  this->input_size_ += len;
+  this->input_size_ += i;
 
   if (has_misaligned_strings)
     gold_warning(_("%s: section %s contains incorrectly aligned strings;"

-- 
Alan Modra
Australia Development Lab, IBM


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