OSDN Git Service

This patch adds elf2flt support for prioritised constructors and destructors,
authorDavid McCullough <davidm@snapgear.com>
Fri, 21 Jul 2006 13:11:04 +0000 (13:11 +0000)
committerDavid McCullough <davidm@snapgear.com>
Fri, 21 Jul 2006 13:11:04 +0000 (13:11 +0000)
commitc1d0fa5c0706a1442be511f095e368591d81ad54
tree609dc7c70ca759e92154ee5b7bb606fee655c3b1
parent193e103da642dac40ce3450838798a8cad2d7736
This patch adds elf2flt support for prioritised constructors and destructors,
but only when --enable-emit-relocs is in effect.

GCC puts prioritised constructors and destructors in special .ctor.N
and .dtor.N sections (where N encodes the priority).  The constructors
and destructors in these sections have a lower priority than those
in the default .ctor and .dtor sections.  However, we need to treat
the crtbegin.o's and crtend.o's sections specially; crtbegin.o's .[cd]tor
sections must come before all the other .[cd]tor* contents and crtend.o's
.[cd]tor sections must come after all other contents.

In --disable-emit-relocs links, it wasn't possible to treat crtbegin.o
and crtend.o specially.  ld-elf2flt would do:

                ld -r -o foo.elf2flt ...input objects...
                    |                               |
            ld -r -o foo.elf foo.elf2flt -T script  |
                                                    |
                                   ld -o foo.gdb foo.elf2flt -T script

so all the input .[cd]tor sections would already be lumped together by the
time the script was used.  This isn't a problem for --enable-emit-relocs as
it only links once.

The patch copies the [cd]tor support from the standard binutils linker
script.  The question is: should the new lines be used unconditionally,
or only when --enable-emit-relocs is in effect?

We could use the new lines for --disable-emit-relocs without breaking
programs that don't use prioritised [cd]tors.  However, it would be a user
interface regression for programs that _do_ use them.  At the moment,
if you try to use prioritised [cd]tors with --disable-emit-relocs,
you get a linker error like this:

   error: no memory region specified for loadable section `.ctors.60535'

With the new lines, the link would silently succeed, and you'd get a
runtime failure instead.  I've therefore guarded the lines with
"SINGLE_LINK:", a bit like the "W_RODAT" stuff that's already there.

Tested on Coldfire, with both --enable-emit-relocs and
--disable-emit-relocs.  It fixes the GCC ecos.exp tests.
Please install if OK.

Richard

Signed-off-by: Richard Sandiford <richard@codesourcery.com>
elf2flt.ld
ld-elf2flt.in