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

Mikhail Maltsev <maltsevm at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maltsevm at gmail dot com

--- Comment #2 from Mikhail Maltsev <maltsevm at gmail dot com> ---
On current trunk GCC does not ICE, but still sort-of-rejects the valid code.
Reduced testcase:

$ cat ./reduced2.c 
void foobar() {
    static const char c1[] __attribute__((__progmem__)) = "1",
                      c2[] __attribute__((__progmem__)) = "2",
                      c3[] = "3";
}

/opt/binutils-avr/bin/avr-gcc -c -fmerge-all-constants ./reduced2.c 
./reduced2.c:5:1: error: section type conflict
 }

Despite the error, assembly code (and object file) are still produced, though
it seems to me, that section information gets trashed, but I'm not sure. Looks
like this:
        .section        .rodata.str1.1,"aMS",@progbits,1
        .type   c3.1570, @object
        .size   c3.1570, 2
c3.1570:
        .string "3"
        .section        .progmem.data.str1.1
        .type   c2.1569, @object
        .size   c2.1569, 2
c2.1569:
        .string "2"
        .type   c1.1568, @object
        .size   c1.1568, 2
c1.1568:
        .string "1"

Without "-fmerge-all-constants" I get the following:

        .size   foobar, .-foobar
        .section        .rodata
        .type   c3.1570, @object
        .size   c3.1570, 2
c3.1570:
        .string "3"
        .section        .progmem.data,"a",@progbits
        .type   c2.1569, @object
        .size   c2.1569, 2
c2.1569:
        .string "2"
        .type   c1.1568, @object
        .size   c1.1568, 2
c1.1568:
        .string "1"

The problem occurs when GCC tries to get the section for c1 and calls
avr_asm_select_section. This function changes the section name from
".rodata.data.str1.1" to ".progmem.data.str1.1", it then turns out that this
section already exists and the check in varasm.c:get_section fails (both
sections have same flags, SECTION_DECLARED is true, SECTION_OVERRIDE is false,
SECTION_WRITE is false - this all triggers an error).

This comment seems relevant:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43746#c8.

Reply via email to