The way in which zlib is embedded in libbfd is half-way broken. While the zlib symbols correctly show up in libbfd.so
$ nm $EBROOTBINUTILS/lib/libbfd.so | grep inflate
00000000000f2d80 T inflate
00000000000f50a0 T inflateCodesUsed
00000000000f4e00 T inflateCopy
00000000000f49b0 T inflateEnd
[...]
they do not in libbfd.a:
$ nm $EBROOTBINUTILS/lib/libbfd.a | grep inflate
nm: libz.a: File format not recognized
U inflate
U inflateEnd
U inflateInit_
U inflateReset
As can be seen from the first line of the output, the reason is that the whole libz.a is included in libbfd.a rather than the individual object files of libz.a. This leads to problems when linking a program statically.
Example:
$ cat foo.c
#define PACKAGE_NAME
#define PACKAGE_VERSION
#include <stdio.h>
#include <bfd.h>
int main(int argc, char** argv)
{
bfd_init();
bfd * bfdFile = bfd_openr( "/bin/ls", "elf64-x86-64" );
if ( bfdFile == NULL )
{
printf( "Error [%x]: %s\n", bfd_get_error(), bfd_errmsg(bfd_get_error()) );
return 1;
}
if ( !bfd_check_format( bfdFile, bfd_object ))
{
printf( "Error [%x]: %s\n", bfd_get_error(), bfd_errmsg(bfd_get_error()) );
return 1;
}
bfd_close( bfdFile );
return 0;
}
$ gcc -o foo foo.c -static -lbfd -liberty -ldl
/.../binutils/2.29.1/lib/libbfd.a(plugin.o):plugin.c:function try_load_plugin: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/.../binutils/2.29.1/lib/libbfd.a(compress.o):compress.c:function decompress_contents: error: undefined reference to 'inflateInit_'
/.../binutils/2.29.1/lib/libbfd.a(compress.o):compress.c:function decompress_contents: error: undefined reference to 'inflateReset'
/.../binutils/2.29.1/lib/libbfd.a(compress.o):compress.c:function decompress_contents: error: undefined reference to 'inflate'
/.../binutils/2.29.1/lib/libbfd.a(compress.o):compress.c:function decompress_contents: error: undefined reference to 'inflateEnd'
/.../binutils/2.29.1/lib/libbfd.a(compress.o):compress.c:function bfd_compress_section_contents: error: undefined reference to 'compressBound'
/.../binutils/2.29.1/lib/libbfd.a(compress.o):compress.c:function bfd_compress_section_contents: error: undefined reference to 'compress'
I'm not entirely sure what the right way to fix this is. Maybe set ZLIB to -L$EBROOTZLIB/lib -lz rather than $EBROOTZLIB/lib/libz.a in all the Makefile.ins?
The way in which
zlibis embedded inlibbfdis half-way broken. While thezlibsymbols correctly show up inlibbfd.sothey do not in
libbfd.a:As can be seen from the first line of the output, the reason is that the whole
libz.ais included inlibbfd.arather than the individual object files oflibz.a. This leads to problems when linking a program statically.Example:
I'm not entirely sure what the right way to fix this is. Maybe set
ZLIBto-L$EBROOTZLIB/lib -lzrather than$EBROOTZLIB/lib/libz.ain all theMakefile.ins?