[cfe-users] how clang merge strings in .rodata section

Hans Wennborg via cfe-users cfe-users at lists.llvm.org
Fri Jul 6 00:54:05 PDT 2018


On Thu, Jul 5, 2018 at 3:18 AM, Jian, Xu via cfe-users
<cfe-users at lists.llvm.org> wrote:
> Hi,
>
> The following c source code abc.c:
>
> #include <stdio.h>
>
> int g_val=10;
>
> const char *g_str="abc";
>
> const char *g_str1="c";
>
> int main(void)
>
> {
>
>     printf("%s %s: %d\n",g_str,g_str1,g_val);
>
>     return 0;
>
> }
>
>
>
> When compile with “clang abc.c -o abc” then dump .rodata section:
>
> # readelf -p .rodata abc
>
>
>
> String dump of section '.rodata':
>
>   [     0]  abc
>
>  [     4]  %s %s: %d
>
>
>
> When compile with “gcc abc.c -o abc” then dump .rodata section:
>
> $ readelf -p .rodata abc
>
>
>
> String dump of section '.rodata':
>
>   [    10]  abc
>
>   [    14]  c
>
>   [    16]  %s %s: %d^J
>
>
>
> clang is able to merge short string (“c”) into the tail of a long string
> (“abc”), while gcc will not.
>
> Does anybody know how to disable this behavior (make it similar to gcc) ?

I don't think there is a way to disable it.

Why do you want to disable this behaviour?

 - Hans



More information about the cfe-users mailing list