This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: turning (part of) an executable into a shared object
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: Ben Liblit <liblit at cs dot berkeley dot edu>
- Cc: binutils at sources dot redhat dot com
- Date: Wed, 08 Oct 2003 13:47:23 +0930
- Subject: Re: turning (part of) an executable into a shared object
- References: <3F7A84AF.3030201@cs.berkeley.edu>
On Wed, Oct 01, 2003 at 12:39:27AM -0700, Ben Liblit wrote:
> It looks like the ".rel.dyn" section contains relocation information.
> Perhaps I need to keep that too? No luck:
>
> % gcc -Wl,--emit-relocs -o executable ...
> % objcopy -j .debug_cfg -j .rodata -j .rel.dyn executable \
> extracted-data
> % gcc -shared -o extracted-data.so extracted-data
> /usr/bin/ld: simple-cfg.sec(.debug_cfg+0x8048400): reloc against \
> `.rodata': error 2
>
> Is there any way to make this alchemical trick work? How can I extract
> selected data sections from a linked executable and turn them back into
> a shared, dynamically loadable object with properly adjusted pointers?
The trouble here is that .rel.dyn contains relocs for _all_ sections,
not just for your .debug_cfg section. What's more, the relocs have
been sorted. You would need to write a utility to select just the
relevant relocs. An easier alternative might be to link "executable"
using -znocombreloc.
--
Alan Modra
IBM OzLabs - Linux Technology Centre