Strange KEEP behavior in linker script

Denis FERRANTI denis.ferranti@st.com
Tue May 6 14:28:00 GMT 2008


Hi Nick,

Ok i see your point. The discarding of an empty output section, even if 
symbols are attached to it, is an expected behavior.
What seemed strange to me was the fact that the symbols were then 
attached  "randomly"  to another section in the ELF.

Cheers,


Nick Clifton wrote:
> Hi Denis,
>
>   The changes in behaviour have happened because of various bug fixes.
>
>> Shouldn't the KEEP() statement force the generation of the output 
>> section in the ELF file, even if there are no input sections.
>
> No, the KEEP statement will ensure that any input sections matching 
> its argument will be copied into the output section containing it.  
> But if there are no matching input sections, then nothing will be 
> copied and hence the output section might be discarded.  If you want 
> to ensure that a section is present in the output file, make sure that 
> some data is placed into it.  eg:
>
>   .mysec :
>   {
>        mysec_start = .;
>        KEEP(*(.mysec));
>        mysec_end = .;
>        LONG(0)
>   }
>
> Cheers
>   Nick
>
>

-- 
Denis Ferranti



More information about the Binutils mailing list