2011-01-12 05:09:02     strange problem when linking with shared FDPIC ELF library

Document created by Aaronwu Employee on Oct 16, 2013
Version 1Show Document
  • View in full screen mode

2011-01-12 05:09:02     strange problem when linking with shared FDPIC ELF library

Patrik Kluba (HUNGARY)

Message: 97392   

 

Hi!

 

I would like to create a shared zlib library, but the compilation fails when the Makefile tries to build two simple utilities (example and minigzip) with the zlib library linked in as shared library. Actually the shared library itself is built without any errors or warnings, and taking a look at it with objdump everything seems OK.

 

The source is not from the official uclinux distribution, instead we use an upstream release with some collected patches and everything is built with our custom build system. So it can happen that we are missing some important command line arguments or patches but I don't believe that it is the cause of our problem.

 

Command line used to build the shared library (as it is executed by zlib's Makefile):

 

 

 

/project/qlinux/toolchain/bfin-big-r1/bin/bfin-linux-uclibc-gcc -shared \

  -Wl,-soname,libz.so.1,--version-script,zlib.map -pipe -fPIC -mcpu=bf518 -mspecld-anomaly \

  -mno-low64k -mlong-calls -fshort-double -fsingle-precision-constant -funsigned-bitfields \

  -fleading-underscore -mstack-check-l1 -std=gnu99 -O2 -fno-strict-aliasing -fweb \

  -frename-registers -funswitch-loops -fomit-frame-pointer -momit-leaf-frame-pointer \

  -D_LARGEFILE64_SOURCE=1 \

  -o libz.so.1.2.5 \

  adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo \

  infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo \

  -lc -Wl,--check-sections  -L. libz.a

 

Command line used to link with libz.so (as it is executed by zlib's Makefile):

 

 

 

/project/qlinux/toolchain/bfin-big-r1/bin/bfin-linux-uclibc-gcc -pipe -fPIC -mcpu=bf518 \

  -mspecld-anomaly -mno-low64k -mlong-calls -fshort-double -fsingle-precision-constant \

  -funsigned-bitfields -fleading-underscore -mstack-check-l1 -std=gnu99 -O2 \

  -fno-strict-aliasing -fweb -frename-registers -funswitch-loops -fomit-frame-pointer \

  -momit-leaf-frame-pointer -D_LARGEFILE64_SOURCE=1 \

  -o minigzipsh \

  minigzip.o \

  -L. libz.so.1.2.5

 

And I get this build error:

 

minigzip.o: In function `_gz_uncompress':

minigzip.c:(.text+0x72): undefined reference to `_gzread'

minigzip.c:(.text+0xae): undefined reference to `_gzerror'

minigzip.c:(.text+0xe0): undefined reference to `_gzclose'

...

 

-fPIC originally is not part of our CFLAGS, it was added to see if it helps or not, but nothing changed. But if I add -shared for compiling minigzipsh, the executable is built cleanly. Unfortunately we do not have a board to test it yet, so it could happen that it does not work at all.

 

http://docs.blackfin.uclinux.org/doku.php?id=toolchain:creating_libraries does not mention that -shared has to be used when linking the application itself, that's why the problem looks strange to me. Or could that page be wrong and is the flag really required?

 

Regards,

Patrik

QuoteReplyEditDelete

 

 

2011-01-12 06:58:18     Re: strange problem when linking with shared FDPIC ELF library

Patrik Kluba (HUNGARY)

Message: 97397   

 

Problem solved.

 

I've noticed that everything works when --version-script,zlib.map is removed. Taking a look at that map file makes everything clear.

 

ZLIB_1.2.0 {

  global:

    compressBound;

    deflateBound;

    inflateBack;

    inflateBackEnd;

    inflateBackInit_;

    inflateCopy;

  local:

    deflate_copyright;

    inflate_copyright;

    inflate_fast;

    inflate_table;

    zcalloc;

    zcfree;

    z_errmsg;

    gz_error;

    gz_intmax;

    _*;

};

...

 

Due to -fleading-underscore all our symbols begin with _, and are treated as local symbols due to the map file above.

Attachments

    Outcomes