Strange KEEP behavior in linker script
Denis FERRANTI
denis.ferranti@st.com
Tue May 6 14:23:00 GMT 2008
Well, my issue is the fact that the output section is discarded.
I tried the --no-gc-sections but it has no effect.
I can stop the linker from discarding the section adding a contribution
like below, but that's ....strange ;-)
.mysec :
{
. += 1; /* dummy contribution */
mysec_start = .;
KEEP(*(.mysec));
mysec_end = .;
}
When there are no contributions, the section seems to be removed in
ldlang.c:
strip_excluded_output_sections (void)
{
...
exclude = (output_section->rawsize == 0
&& (output_section->flags & SEC_KEEP) == 0
&& !bfd_section_removed_from_list (output_bfd,
output_section));
...
if (exclude)
{
/* We don't set bfd_section to NULL since bfd_section of the
removed output section statement may still be used. */
if (!os->section_relative_symbol
&& !os->update_dot_tree)
os->ignored = TRUE;
output_section->flags |= SEC_EXCLUDE;
bfd_section_list_remove (output_bfd, output_section);
output_bfd->section_count--;
}
...
}
The SEC_KEEP flag is tested on the output section.
I see your point about the KEEP() semantic, but then do you see a
solution to avoid the discard of the output section (without adding
artificial contributions in the linker script)?
Daniel Jacobowitz wrote:
> On Tue, May 06, 2008 at 03:29:27PM +0200, Denis FERRANTI wrote:
>
>> Shouldn't the KEEP() statement force the generation of the output section
>> in the ELF file, even if there are no input sections.
>>
>
> No, why should it? It is supposed to keep the input sections, not the
> output section. I'm not sure why ld started discarding the empty
> output section.
>
>
--
Denis Ferranti
More information about the Binutils
mailing list