Strange KEEP behavior in linker script

Denis FERRANTI denis.ferranti@st.com
Tue May 6 13:30:00 GMT 2008


Hi,

could someone explain the following change of behavior in last binutils 
versions about the linker script KEEP() statement, when there are no 
input sections for a given ouput section:

I just added this section definition to a default x86 linker script:

.mysec :
{
        mysec_start = .;

        KEEP(*(.mysec));

        mysec_end = .;
}

- With GNU ld version 2.16:
 > objdump -th ~/tmp/test/hello.elf | grep mysec
 27 .mysec        00000000  000000d2  000000d2  00000962  2**0
000000d2 l    d  .mysec 00000000              .mysec
000000d2 g       .mysec 00000000              mysec_end
000000d2 g       .mysec 00000000              mysec_start
The section .mysec is created in the ELF file and the two symbols are 
attached to it, which is the behavior i would expect when the KEEP() 
statement is used.

- With GNU ld version 2.17:
 > objdump -th ~/tmp/test/hello.elf | grep mysec
000000d2 g       *ABS*  00000000              mysec_end
000000d2 g       *ABS*  00000000              mysec_start
The section .mysec is discarded and the symbols become absolute

- With GNU ld version 2.18:
 > objdump -th ~/tmp/test/hello.elf | grep mysec
000000d2 g       .comment       00000000              mysec_end
000000d2 g       .comment       00000000              mysec_start
The section .mysec is also discarded and the symbols are attached to 
another section (in fact the previous one in the linker script).
The change of behavior occurs also for ARM target.

Shouldn't the KEEP() statement force the generation of the output 
section in the ELF file, even if there are no input sections.




More information about the Binutils mailing list