Include archive member section with ld script (+ somewhat RFC)

Alan Modra amodra@bigpond.net.au
Thu Jun 12 07:17:00 GMT 2003


On Wed, Jun 11, 2003 at 05:59:10PM +0200, Vincent Rubiolo wrote:
> how to include a given section of an 
> archive member in an ld script

See info node "Input Section Basics".  You want filename(section),
where "filename" is the archive member.  Note the last paragraph though!
ld will try to open "filename" if it doesn't contain a wildcard char.

You might use something like

SECTIONS {
.
.
  .foocode : { foo.?(.text) }
.
.
}

to put ".text" from archive member "foo.o" into output section
".foocode".  Note how I've sneakily used a wildcard to match "foo.o", so
that the linker doesn't try to find file "foo.o".

This example doesn't force the linker to actually include foo.o in
the link.  For that, you need to specify your library on the command
line (or via an INPUT command in the script), and arrange for foo.o
to be extracted.  ie. normal archive search rules apply, and members
will be included to satisfy some non-weak undefined symbol or if
--whole-archive is used.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Binutils mailing list