This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold] Merging string literals with bigger alignment
- From: Alan Modra <amodra at gmail dot com>
- To: Cary Coutant <ccoutant at google dot com>
- Cc: "H.J. Lu" <hjl dot tools at gmail dot com>, Alexander Ivchenko <aivchenk at gmail dot com>, binutils <binutils at sourceware dot org>
- Date: Fri, 3 May 2013 10:44:07 +0930
- Subject: Re: [gold] Merging string literals with bigger alignment
- References: <CACysShiw_kcnug9u8ShzS-k0qQVdrz3wk5kB2Aqh=cZmaQrPhA at mail dot gmail dot com> <CAHACq4q7CReFbYaeK+APLLhi+oKxBcv4d-2o4wjvkxRpx=Uj_A at mail dot gmail dot com> <20130501022527 dot GC5221 at bubble dot grove dot modra dot org> <CAHACq4otE1CiMUanv0paiMu=cDNE8UsyrpLCpBbBYaZDH4kQrQ at mail dot gmail dot com> <CAMe9rOpsr1xDvU5tWA5GFp0q+Z+=u_9=eh3LnsS4P_zojLth8A at mail dot gmail dot com> <CAMe9rOqSd4GA8UGrvtPWsNM6CMWFjL=dowpSux=0ruWPq=JpcA at mail dot gmail dot com> <CAMe9rOo9NW=3CfDCCm+uh06kFRfHM=Q-LgmTMrD0pVDm5pft9A at mail dot gmail dot com> <20130502032920 dot GI5221 at bubble dot grove dot modra dot org> <CAMe9rOq5FbfkHmhFCWG4J8aNTPvWeJohigtw1m6sBB=d0zOK=Q at mail dot gmail dot com> <CAHACq4pmuTYL83f8yxnJ1NBj5XBFK3UhLEiLGjNbsYr8O6d7Sg at mail dot gmail dot com>
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