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: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Cary Coutant <ccoutant at google dot com>
- Cc: Alexander Ivchenko <aivchenk at gmail dot com>, binutils <binutils at sourceware dot org>
- Date: Wed, 1 May 2013 12:21:41 -0700
- Subject: Re: [gold] Merging string literals with bigger alignment
- References: <CAHACq4odyq1ok_SWBFNUDreq8=b-4MMqp3DXJY03viF2-HUe8w at mail dot gmail dot com> <CACysShj2TB84vkATNQhDVYx7QURtx29Qpb5t+i_i2OP6R-zgZQ at mail dot gmail dot com> <CAHACq4q4=bd1gB9LEBJRwOnqDTYQxZ_Z=BKN++M0KSPqDdGJtg at mail dot gmail dot com> <CACysShjX+kaq8CAcCWDMcvChGrUPYNz4XQGYbk+okV2baGPfJQ at mail dot gmail dot com> <CAHACq4rN=nj5wX5AJYwKSbqnDfbMPC=p9CvGJR-y-JjKi=0gqw at mail dot gmail dot com> <CAKOQZ8y7DMUSWh5dozvxBD1a8uW981K+Gwn95JTqcGFkAHdVOg at mail dot gmail dot com> <CACysShhF+sh1vebktXwoc6epBJ8FQTMTjXRURm7nJT9MfjUvLA at mail dot gmail dot com> <CAHACq4p4fqA2YiJLPsxoP=+KMy-9H+r2Jyp_WXhzxxcDgxa0aQ at mail dot gmail dot com> <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>
On Wed, May 1, 2013 at 11:28 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Wed, May 1, 2013 at 11:24 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Wed, May 1, 2013 at 10:43 AM, Cary Coutant <ccoutant@google.com> wrote:
>>>> `echo g++ -W -Wall -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fmerge-constants -g -O2 -o basic_static_test | sed -e 's/-Wp,-D_FORTIFY_SOURCE=[0-9][0-9]*//'` -Bgcctestdir/ -static basic_test.o
>>>> collect2: ld terminated with signal 6 [Aborted]
>>>> terminate called after throwing an instance of 'std::bad_alloc'
>>>> what(): std::bad_alloc
>>>> make[5]: *** [basic_static_test] Error 1
>>>
>>> I'm not seeing this. What target?
>>>
>>>> Fixing new_key_offset() is easy, but the gold bootstrap test fails
>>>>
>>>> (cd gcctestdir2 && ln -s ../ld1 ld)
>>>> g++ -m64 -W -Wall -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -frandom-seed=ld2 -g -O2 -Bgcctestdir2/ -Wl,--build-id=tree -Wl,--build-id-chunk-size-for-treehash=12345 -Wl,--build-id-min-file-size-for-treehash=0 -o ld2 main.o powerpc.o libgold.a ../libiberty/libiberty.a -ldl -lz
>>>> gcctestdir2/ld: error: cannot find main.o
>>>> gcctestdir2/ld: error: cannot find powerpc.o
>>>> gcctestdir2/ld: error: cannot find libgold.a
>>>> gcctestdir2/ld: error: cannot find ../libiberty/libiberty.a
>>>> .zdebug_line: error: undefined reference to 'main'
>>>> collect2: error: ld returned 1 exit status
>>>
>>> I don't see this one either.
>>>
>>> -cary
>>
>> I can reproduce it on Fedora 18 with GCC 4.7.2. ld1 is mis-linked by ld-new.
>>
>> --
>> H.J.
>
> String merging is broken:
>
> Breakpoint 1, gold::Input_file::try_extra_search_path (
> pindex=pindex@entry=0x799530,
> input_argument=input_argument@entry=0x757c98, filename="main.o",
> found_name=found_name@entry=0x879578, namep=namep@entry=0x7fffffff7110)
> at /export/gnu/import/git/binutils/gold/fileread.cc:975
> 975 if (*pindex > 0 || ::stat(name.c_str(), &dummy_stat) < 0)
> (gdb) p name
> $1 = "Group end without group start/main.o"
> (gdb)
>
> --
> H.J.
This change:
while (p < pend0)
{
size_t len = string_length(p);
- Stringpool::Key key;
- this->stringpool_.add_with_length(p, len, true, &key);
+ if (len != 0)
+ {
+ // Within merge input section each string must be aligned.
+ if ((reinterpret_cast<uintptr_t>(p) & (this->addralign() - 1))
+ != init_align_modulo)
+ has_misaligned_strings = true;
- merged_strings.push_back(Merged_string(i, key));
+ Stringpool::Key key;
+ this->stringpool_.add_with_length(p, len, true, &key);
+ merged_strings.push_back(Merged_string(i, key));
+ }
p += len + 1;
i += (len + 1) * sizeof(Char_type);
}
skips merged_strings.push_back for empty strings so that
empty string merge is mishandled.
This patch restores merged_strings.push_back for emty
strings and fixes the regression.
--
H.J.
---
diff --git a/gold/merge.cc b/gold/merge.cc
index 6480bd9..2d01462 100644
--- a/gold/merge.cc
+++ b/gold/merge.cc
@@ -565,18 +565,16 @@
Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
{
size_t len = string_length(p);
- if (len != 0)
- {
- // Within merge input section each string must be aligned.
- if ((reinterpret_cast<uintptr_t>(p) & (this->addralign() - 1))
- != init_align_modulo)
- has_misaligned_strings = true;
+ // Within merge input section each string must be aligned.
+ if (len != 0
+ && ((reinterpret_cast<uintptr_t>(p) & (this->addralign() - 1))
+ != init_align_modulo))
+ has_misaligned_strings = true;
- Stringpool::Key key;
- this->stringpool_.add_with_length(p, len, true, &key);
+ Stringpool::Key key;
+ this->stringpool_.add_with_length(p, len, true, &key);
- merged_strings.push_back(Merged_string(i, key));
- }
+ merged_strings.push_back(Merged_string(i, key));
p += len + 1;
i += (len + 1) * sizeof(Char_type);
}