Linker script error: section overlap

Linker script error: section overlap

我正在使用 链接描述文件 为 CASIO 9860GII 计算器编写 C 代码(见最后)。不幸的是我收到以下错误:

$ sh3eb-elf-gcc -o build/crypt.elf build/crt0.o build/crypt.o build/supercoollibrary.o -m3 -mb -ffreestanding -nostdlib -I include -O3 -std=c99 -lc -lgcc -L lib -lfx -T src/crypt.ld -nostdlib
sh3eb-elf/bin/ld: section .data._impl_stderr LMA [000000000030c308,000000000030c317] overlaps section .rodata._printf_ptr.str1.4 LMA [000000000030c308,000000000030c31b]
sh3eb-elf/bin/ld: section .rodata.CSWTCH.44 LMA [000000000030c31c,000000000030c39f] overlaps section .data._impl_stdout LMA [000000000030c318,000000000030c327]
sh3eb-elf/bin/ld: section C LMA [000000000030c328,000000000030c557] overlaps section .rodata.CSWTCH.44 LMA [000000000030c31c,000000000030c39f]
sh3eb-elf/bin/ld: section .rodata.perror.str1.4 LMA [000000000030c3a0,000000000030c3bf] overlaps section C LMA [000000000030c328,000000000030c557]
sh3eb-elf/bin/ld: warning: section `.bss' type changed to PROGBITS

现在我发现我在 ROM 中有两个平行的部分:

+-------------------------+----------------------------+
| 0x0030c308              | 0x0030c308                 |
|       .data_impl_stderr | .rodata._printf_ptr.str1.4 |
| 0x0030c317              |                            |
+-------------------------+ 0x0030c31b                 |
| 0x0030c318              +----------------------------+
|       .data_impl_stdout | 0x0030c31c                 |
| 0x0030c327              |                            |
+-------------------------+                            |
| 0x0030c328              |          .rodata.CSWTCH.44 |
|                         |                            |
|                         |                            |
|                         | 0x0030c39f                 |
|                         +----------------------------+
|                         | 0x0030c3a0                 |
|                       C |      .rodata.perror.str1.4 |
|                         | 0x0030c3bf                 |
|                         +----------------------------|
|                         |
|                         |
|                         |
| 0x0030c557              | 
+-------------------------+

看起来,AT(_romdata) 使链接器将 .data 加载到 .rodata 部分(ROM),尽管我希望它在 RAM 中,因为区域指令 > ram 对于 .data.

我用非常小的示例代码尝试了这个链接描述文件,它成功了。在我使用 readelf 检查 .elf 文件后,我注意到没有 .data 部分。如果我使用我的 "real" 代码,就会出现上述错误。当我在 Windows 上(使用不同的编译器)编译这段代码时,它工作得很好。

谁能告诉我发生了什么事?老实说,我很无能。

链接描述文件:

OUTPUT_ARCH(sh3)
ENTRY(initialize)
MEMORY
{
        rom  : o = 0x00300200, l = 512k
        ram  : o = 0x08100000, l = 64k  /* 64k pretty safe guess */


        /*
        rom start  0x00300200  (+512k = +0x0007D000)
            end    0x0037D200

        ram start  0x08100000  ( +64k = +0x0000FA00)
            end    0x0810FA00
        */
}
SECTIONS
{
        .text : {
                *(.pretext)     /* init stuff */
                *(.text)
        } > rom
        .rodata : {
                *(.rodata)
                *(.rodata.str1.4)
                _romdata = . ;  /* symbol for initialization data */
        } > rom
        .bss : {
                _bbss = . ;
                _bssdatasize = . ;
                LONG(0);        /* bssdatasize */
                *(.bss) *(COMMON);
                _ebss = . ;
        } > ram

        .data BLOCK(4) : AT(_romdata) {
                _bdata = . ;
                *(.data);
                _edata = . ;
        } > ram
}

您似乎有一些输入节没有映射到链接描述文件中的任何输出节。尝试在 .rodata 部分描述中添加 *(.rodata.*)