madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.65k stars 2.44k forks source link

Shared library is disabled when undefined versions produce errors #960

Open alyssais opened 6 months ago

alyssais commented 6 months ago

To check whether shared libraries are supported, the configure script tries to compile a test file. On Linux, GNU, Solaris, and BSD, this test file will be compiled with the version script. On some linkers, this produces an error, because that test file does not produce the symbols expected by the version script:

Checking for shared library support...
=== ztest41.c ===
extern int getchar();
int hello() {return getchar();}
===
x86_64-unknown-freebsd13-clang -c -O3 -fPIC ztest41.c
x86_64-unknown-freebsd13-clang -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -o ztest41.so ztest41.o
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'compressBound' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'deflateBound' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateBack' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateBackEnd' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateBackInit_' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateCopy' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'deflate_copyright' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'inflate_copyright' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'inflate_fast' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'inflate_table' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'zcalloc' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'zcfree' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'z_errmsg' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'gz_error' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'local' to symbol 'gz_intmax' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0.2' to symbol 'gzclearerr' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0.2' to symbol 'gzungetc' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0.2' to symbol 'zlibCompileFlags' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.0.8' to symbol 'deflatePrime' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: version script assignment of 'ZLIB_1.2.2' to symbol 'adler32_combine' failed: symbol not defined
x86_64-unknown-freebsd13-ld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(exit code 1)
No shared library support; try without defining CC and CFLAGS

On other linkers, the undefined versions are just warnings, so compilation succeeds and the static library is built.

An easy way to reproduce this error if you don't have a linker that defaults to an error here is to run configure with CC='clang -Wl,--no-undefined-version.

To fix this, the test file probably needs to be compiled without the version script, or with -Wl,--undefined-version or -Wl,--noinhibit-exec.

OmNamasi commented 5 months ago

Seeing the same issue when cross-compiling with clang 17.x. Below is snippet from configure.log.

Can you update the test or version script to resolve this issue?

2024-04-17T13:41:06.5355664Z /home/runner/work/custom/maverick/toolchain_llvm17/bin/arm-linux-gnueabihf-clang -c -fPIC ztest2881.c
2024-04-17T13:41:06.5359084Z /home/runner/work/custom/maverick/toolchain_llvm17/bin/arm-linux-gnueabihf-clang -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -fPIC -o ztest2881.so ztest2881.o
2024-04-17T13:41:06.5362681Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'compressBound' failed: symbol not defined
2024-04-17T13:41:06.5364864Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'deflateBound' failed: symbol not defined
2024-04-17T13:41:06.5366480Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateBack' failed: symbol not defined
2024-04-17T13:41:06.5367884Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateBackEnd' failed: symbol not defined
2024-04-17T13:41:06.5370567Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateBackInit_' failed: symbol not defined
2024-04-17T13:41:06.5372859Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0' to symbol 'inflateCopy' failed: symbol not defined
2024-04-17T13:41:06.5375491Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'deflate_copyright' failed: symbol not defined
2024-04-17T13:41:06.5378027Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'inflate_copyright' failed: symbol not defined
2024-04-17T13:41:06.5380691Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'inflate_fast' failed: symbol not defined
2024-04-17T13:41:06.5383044Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'inflate_table' failed: symbol not defined
2024-04-17T13:41:06.5385452Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'zcalloc' failed: symbol not defined
2024-04-17T13:41:06.5387782Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'zcfree' failed: symbol not defined
2024-04-17T13:41:06.5390170Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'z_errmsg' failed: symbol not defined
2024-04-17T13:41:06.5392778Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'gz_error' failed: symbol not defined
2024-04-17T13:41:06.5395280Z arm-linux-gnueabihf-ld: error: version script assignment of 'local' to symbol 'gz_intmax' failed: symbol not defined
2024-04-17T13:41:06.5397684Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0.2' to symbol 'gzclearerr' failed: symbol not defined
2024-04-17T13:41:06.5400903Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0.2' to symbol 'gzungetc' failed: symbol not defined
2024-04-17T13:41:06.5403401Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0.2' to symbol 'zlibCompileFlags' failed: symbol not defined
2024-04-17T13:41:06.5406056Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.0.8' to symbol 'deflatePrime' failed: symbol not defined
2024-04-17T13:41:06.5408626Z arm-linux-gnueabihf-ld: error: version script assignment of 'ZLIB_1.2.2' to symbol 'adler32_combine' failed: symbol not defined
2024-04-17T13:41:06.5411106Z arm-linux-gnueabihf-ld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
2024-04-17T13:41:06.5412982Z clang: error: linker command failed with exit code 1 (use -v to see invocation)
2024-04-17T13:41:06.5414269Z (exit code 1)
2024-04-17T13:41:06.5415380Z No shared library support; try without defining CC and CFLAGS
2024-04-17T13:41:06.5417805Z Building static library libz.a version 1.3.1 with /home/runner/work/custom/maverick/toolchain_llvm17/bin/arm-linux-gnueabihf-clang.