简体   繁体   中英

Linker script error: section overlap

I'm writing C code for the CASIO 9860GII calculator using the linker script (see at the end). Unfortunately I get following error:

$ 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

Now i figured out that I have two sections parallel in 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              | 
+-------------------------+

Seemingly, AT(_romdata) makes the linker load .data into the .rodata section (ROM), even though I would expect it to be in RAM because of the region instruction > ram for .data .

I tried this linker script with very small sample code and it worked. After I inspected the .elf file using readelf , I noticed that there is no .data section. If I use my "real" code, the mentioned error appears. When I compile this code on Windows (using a different compiler), it works just fine.

Could anyone please give me a hint what is going on? I'm pretty clueless, to be honest.

Linker script:

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
}

It seems that you have some input sections that you didn't map to any output section in your linker script. Try adding *(.rodata.*) in your .rodata section description.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM