PATCH: PR 797: Alignment in empty section changes the output layout

Alan Modra amodra@bigpond.net.au
Tue Mar 29 08:12:00 GMT 2005


On Mon, Mar 28, 2005 at 06:06:31PM -0800, H. J. Lu wrote:
> On Tue, Mar 29, 2005 at 08:12:31AM +0930, Alan Modra wrote:
> > On Thu, Mar 24, 2005 at 02:05:56PM -0800, H. J. Lu wrote:
> > > +	 So we remove the unused output sections without input sections
> > > +	 and the empty unused output sections created by linker, if
> > > +	 they don't have any contents.  */
> > 
> > Is it possible to do this in strip_excluded_output_sections?  You won't
> > have sizes set at that stage, but linker_has_input will be set, as will
> > SEC_HAS_CONTENTS from link script data statements.  So I think most of
> 
> But SEC_KEEP may not be set before lang_mark_used_section.
> 
> > what you're trying to achieve can be done there.  SEC_LINKER_CREATED
> > sections ought to be handled by the backend size_dynamic_sections
> > function calling _bfd_strip_section_from_output.
> 
> Or I can check every output section and call _bfd_strip_section_from_output
> at the end of bfd_elf_size_dynamic_sections so that I don't have to
> change every backend.

No, I think that would be a bad idea.  Most SEC_LINKER_CREATED sections
are created by the backend code, so the backend code should manage them.
Otherwise you run the risk of removing sections that some backend wants
to keep.

> But _bfd_strip_section_from_output will check
> every input section. It may be expensive.

Sure.  Let's fix it.  Perhaps by creating bfd_link_order lists earlier,
after placing orphans.

> If I have to do it in
> gld${EMULATION_NAME}_finish for other sections anyway, why not
> to remove empty unused linker created sections in a same place.

I don't really like the idea of removing sections so late in the link
process.  It's a hack that I allowed because removing excess symbols and
output sections was desirable, but now you're adding hacks upon hacks. 
As evidenced by the need for yet another section flag.

The proper place to remove sections is after the backend
size_dynamic_sections has run and before space for dynamic symbols is
allocated.  If you do it that way you'll avoid some unnecessary dynamic
syms too.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Binutils mailing list