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 target/71151] New: -fmerge-constants and -fdata-sections results in string constants in .progmem.gcc_sw section


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

            Bug ID: 71151
           Summary: -fmerge-constants and -fdata-sections results in
                    string constants in .progmem.gcc_sw section
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: senthil.thecoder at gmail dot com
  Target Milestone: ---

Using -fdata-sections causes string literals in functions to go into
.progmem.sw_gcc, instead of .rodata.str. This is incorrect, since code using
them expects data memory addresses, not flash.

$ cat printf.c
extern void bar(const char*);
void foo(void)
{
  bar("BBBBBBBBBB");
}

$ avr-gcc -mmcu=atmega32u2 printf.c -S -Os -fdata-sections -ffunction-sections
$ cat printf.s
jaguar:~/scratch$ cat printf.s
        .file   "printf.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
        .section        .progmem.gcc_sw_table.foo.str1.1,"aMS",@progbits,1
.LC0:
        .string "BBBBBBBBBB"
        .section        .text.foo,"ax",@progbits
.global foo
        .type   foo, @function
foo:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
        ldi r24,lo8(.LC0)
        ldi r25,hi8(.LC0)
        jmp bar
        .size   foo, .-foo
        .ident  "GCC: (GNU) 6.1.0"


As the testcase shows, the string goes into progmem.gcc_sw_table.<fn_name>.*,
and this gets placed in flash by the linker script. Reading from the address in
r25:24 will obviously not give the correct results - it will read from whatever
happens to be mapped at the same address in the data address space.

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