This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold] Merging string literals with bigger alignment
On Tue, Feb 12, 2013 at 7:30 AM, Alexander Ivchenko <aivchenk@gmail.com> wrote:
> The testcase in the patch from my first letter has those .c files. But
> it's very simple anyway:
>>cat merge_string_literals_1.c
>
> const char* bar1() {
> return "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
> }
> const char* bar1_short() {
> return "SSSSSS";
> }
>
>>gcc -c merge_string_literals_1.c -O2
>>readelf -S merge_string_literals_1.o | grep rodata
> [ 5] .rodata.str1.8 PROGBITS 0000000000000000 00000058
> [ 6] .rodata.str1.1 PROGBITS 0000000000000000 0000007d
>
>>objdump -s -j.rodata.str1.8 merge_string_literals_1.o
>
> merge_string_literals_1.o: file format elf64-x86-64
>
> Contents of section .rodata.str1.8:
> 0000 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
> 0010 41414141 41414141 41414141 41414141 AAAAAAAAAAAAAAAA
> 0020 41414141 00 AAAA.
>
> I mentioned .rodata.str1.4 before - that could happen if we compile
> for 32 bits..
Thanks. I see the code in GCC now. It's in ix86_constant_alignment
in gcc/config/i386/i386.c. For a string constant of 31 bytes or more,
GCC sets the alignment to the word size. This means that GCC may use
vector instructions to load the string constant. So gold has to honor
the alignment of each individual entry in the mergeable string
section.
Ian