This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug middle-end/77422] New: -fdata-sections should put each string literal in its own section


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77422

            Bug ID: 77422
           Summary: -fdata-sections should put each string literal in its
                    own section
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
  Target Milestone: ---

[hjl@gnu-6 string-1]$ cat x.i
void
foo (void)
{
  __builtin_printf ("bar\n");
  __builtin_printf ("test\n");
}

int
main ()
{
  __builtin_printf ("hello\n");
  __builtin_printf ("test\n");
  return 0;
}
[hjl@gnu-6 string-1]$ make 
/export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc
-B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -fdata-sections
-ffunction-sections -S -o x.s x.i
[hjl@gnu-6 string-1]$ cat x.s
        .file   "x.i"
        .section        .rodata.foo.str1.1,"aMS",@progbits,1
.LC0:
        .string "bar"
.LC1:
        .string "test"
        .section        .text.foo,"ax",@progbits
        .p2align 4,,15
        .globl  foo
        .type   foo, @function
foo:
.LFB0:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        movl    $.LC0, %edi
        call    puts
        movl    $.LC1, %edi
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        jmp     puts
        .cfi_endproc
.LFE0:
        .size   foo, .-foo
        .section        .rodata.main.str1.1,"aMS",@progbits,1
.LC2:
        .string "hello"
        .section        .text.startup.main,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB1:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        movl    $.LC2, %edi
        call    puts
        movl    $.LC1, %edi
        call    puts
        xorl    %eax, %eax
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE1:
        .size   main, .-main
        .ident  "GCC: (GNU) 7.0.0 20160829 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-6 string-1]$ 

.LC0 and .LC1 are in the same section, .rodata.foo.str1.1.
.rodata.foo.str1.1 can't be discarded even when function foo
is unused since LC1 is also referenced by main.

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