Re: relink a dynamically linke executable to make some of the libraries static?



On 2007-09-14, John Reiser <jreiser@xxxxxxxxxxxx> wrote:
If I have an ELF executable that dynamically linked against 6
different shared objects, is there a way to link it "again" to
pull one of those in as a static library?

Or do I have to re-do the link that was used to create the
executable?

In order to do any linking, then /bin/ld requires inputs that are ET_REL.
You could try using objcopy, and/or --oformat of /bin/ld, to take apart
the executable and the library, generating pieces that are ET_REL and
with symbols and relocations intact. Consider using a binary editor
to change the two-byte tag Elf32_Ehdr.e_type from ET_EXEC or ET_DYN
into ET_REL. In general you require the "linking view" information
contained in Elf32_Shdr records (and not the "execution view" information
contained in Elf32_Phdr records). Any input that has been "stripped"
will be a disaster.

Study the loading done at the last stages of making Linux kernels.
See the Makefiles and ".*.cmd" files [after successful load] in
linux/arch/$ARCH/boot{,compressed}.

You could do it yourself, particularly if total cleanliness was not required.
Concatenate the PT_LOADs, and concatenate/merge the non-PT_LOAD info. The
output would have as many PT_LOAD as the sum of the input PT_LOAD. Most
of the tables referenced from the Elf32_Ehdr could move to beyond the end
of the original ET_EXEC. The old tables may be left in place, unreferenced.

See also the 'statifier' project http://statifier.sourceforge.net
and the 'jumpstart' tool http://BitWagon.com/jumpstart/jumpstart.html
Both of these create "packages" of executables "bound" to shared libraries.

Thanks for the pointers. It's mostly just an academic
question, since I can just hack up the makefile and re-build
from sources. Actually, it's currently a moot point since the
library I want to 'statify' into the app is libtcl8.4: I
haven't yet figured out how to get a static library out of TCL
8.4's build process.

--
Grant Edwards grante Yow! Half a mind is a
at terrible thing to waste!
visi.com
.



Relevant Pages

  • Re: relink a dynamically linke executable to make some of the libraries static?
    ... pull one of those in as a static library? ... Or do I have to re-do the link that was used to create the ... In order to do any linking, then /bin/ld requires inputs that are ET_REL. ... contained in Elf32_Shdr records (and not the "execution view" information ...
    (comp.os.linux.development.apps)
  • Re: Length of Variable Names Affect Compiled Executable?
    ... case of Dynamic Linking concept is it dependent on Variable/Function ... shared libraries, the names to be linked against must be present ... the OS at the time the image is loaded for execution, ...
    (comp.lang.c)
  • Re: Standard C and math library
    ... The linker that needed to make ... Most common was *not* to prelink before execution. ... When compiling, each ... executing you just entered LGO and linking and whatever began. ...
    (comp.lang.c)
  • Re: aCC option to load all the symbols during linking
    ... functions into the executable (Not loading functions that are not ... called in the execution). ... Presumably you are linking with archive libraries, ...
    (comp.sys.hp.hpux)