Skip to content

gzdopen, gzerror, gzread, ... not present in "libz_rs.so"'s cdylib? #370

Open
@brainstorm

Description

@brainstorm

Writing this with checked out repo on latest HEAD from today (commit 1cd807107f75b0b30fc7bd3ac34569bf75f407b6)

Thanks for offering a dynamic C lib way to substitute old zlib implementations! I'm trying to migrate a bioinformatics program away from it (bwa-mem2), but unfortunately, I can't see some of the symbols I need on the resulting shared lib, like gzdopen?

$ uname -a
Linux home 6.8.0-1019-oracle #20-Ubuntu SMP Fri Jan 17 21:19:50 UTC 2025 aarch64 aarch64 aarch64 GNU/Linux

$ cargo clean && cargo build --release --no-default-features --features "c-allocator" && nm target/release/libz_rs.so | grep -i gzdopen
     Removed 0 files
   Compiling zlib-rs v0.5.0 (/home/ubuntu/tmp/zlib-rs/zlib-rs)
   Compiling libz-rs-sys v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys)
   Compiling libz-rs-sys-cdylib v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys-cdylib)
    Finished `release` profile [optimized] target(s) in 3.28s
$
$ cargo clean && cargo build --release && nm target/release/libz_rs.so | grep -i gzdopen
     Removed 25 files, 3.1MiB total
   Compiling zlib-rs v0.5.0 (/home/ubuntu/tmp/zlib-rs/zlib-rs)
   Compiling libz-rs-sys v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys)
   Compiling libz-rs-sys-cdylib v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys-cdylib)
    Finished `release` profile [optimized] target(s) in 3.25s
$
$ cargo clean && cargo build --release && nm target/release/libz_rs.so | grep -i gz
     Removed 25 files, 3.1MiB total
   Compiling zlib-rs v0.5.0 (/home/ubuntu/tmp/zlib-rs/zlib-rs)
   Compiling libz-rs-sys v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys)
   Compiling libz-rs-sys-cdylib v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys-cdylib)
    Finished `release` profile [optimized] target(s) in 3.27s
00000000000082d4 t _ZN7zlib_rs5c_api9gz_header5flags17h99a88144c91719a2E
$

For good measure, I first followed the cdylib README.md and tried with a 1-line modification of the minimal zpipe.c example first:

$ cargo clean && cargo build --release && nm target/release/libz_rs.so | grep -i gzdopen
     Removed 25 files, 3.1MiB total
   Compiling zlib-rs v0.5.0 (/home/ubuntu/tmp/zlib-rs/zlib-rs)
   Compiling libz-rs-sys v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys)
   Compiling libz-rs-sys-cdylib v0.5.0 (/home/ubuntu/tmp/zlib-rs/libz-rs-sys-cdylib)
    Finished `release` profile [optimized] target(s) in 3.25s

$ cc -o zpipe zpipe.c target/release/libz_rs.so -I .
/usr/bin/ld: /tmp/cckGDWTg.o: in function `main':
zpipe.c:(.text+0x60c): undefined reference to `gzdopen'
collect2: error: ld returned 1 exit status

$ git diff
diff --git a/libz-rs-sys-cdylib/zpipe.c b/libz-rs-sys-cdylib/zpipe.c
index bda0ce6..ea5c07b 100644
--- a/libz-rs-sys-cdylib/zpipe.c
+++ b/libz-rs-sys-cdylib/zpipe.c
@@ -201,6 +201,7 @@ int main(int argc, char **argv)
     SET_BINARY_MODE(stdin);
     SET_BINARY_MODE(stdout);

+    gzdopen(-2, "w");
     /* do compression if no arguments */
     if (argc == 1) {
         ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);

And here's the output from the bwa-mem2 patched Makefile:

$ git diff
diff --git a/Makefile b/Makefile
index 7e9fb7d..958b86e 100644
--- a/Makefile
+++ b/Makefile
@@ -55,11 +55,11 @@ CPPFLAGS+=  -DENABLE_PREFETCH -DV17=1 -DMATE_SORT=0 $(MEM_FLAGS)

 ifeq ($(uname_arch),arm64)     # OS/X has memset_s etc already
 INCLUDES=   -Isrc $(SSE2NEON_FLAGS) $(SSE2NEON_INCLUDES) -D__STDC_WANT_LIB_EXT1__
-LIBS=          -lpthread -lm -lz -L. -lbwa $(STATIC_GCC)
+LIBS=          -lpthread -lm -L. -lbwa $(STATIC_GCC)
 SAFE_STR_LIB=
 else
 INCLUDES=   -Isrc -Iext/safestringlib/include
-LIBS=          -lpthread -lm -lz -L. -lbwa -Lext/safestringlib -lsafestring $(STATIC_GCC)
+LIBS=          -lpthread -lm -L../zlib-rs/libz-rs-sys-cdylib/target/release/ -L. -lbwa -Lext/safestringlib -lsafestring $(STATIC_GCC)
 SAFE_STR_LIB=    ext/safestringlib/libsafestring.a
 ifeq ($(uname_arch),aarch64)
 INCLUDES+= $(SSE2NEON_FLAGS) $(SSE2NEON_INCLUDES)
diff --git a/ext/safestringlib b/ext/safestringlib
index 245c4b8..e399109 160000
--- a/ext/safestringlib
+++ b/ext/safestringlib
@@ -1 +1 @@
-Subproject commit 245c4b8cff1d2e7338b7f3a82828fc8e72b29549
+Subproject commit e399109428240ffc52aedca1cb93098426fac18d-dirty

... and its corresponding error, so you can see that other symbols aren't public/visible either:

$ make -j4
g++ -std=c++14 -g -O3 -fpermissive   src/main.o libbwa.a -lpthread -lm -L../zlib-rs/libz-rs-sys-cdylib/target/release/ -L. -lbwa -Lext/safestringlib -lsafestring  -o bwa-mem2
/usr/bin/ld: libbwa.a(fastmap.o): in function `main_mem(int, char**)':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/fastmap.cpp:905:(.text+0x1740): undefined reference to `gzdopen'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/fastmap.cpp:933:(.text+0x2520): undefined reference to `gzdopen'
/usr/bin/ld: libbwa.a(utils.o): in function `err_xzopen_core':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:84:(.text+0x1b80): undefined reference to `gzopen'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:79:(.text+0x1bc4): undefined reference to `gzdopen'
/usr/bin/ld: libbwa.a(utils.o): in function `err_gzread.part.0':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:149:(.text+0x1d58): undefined reference to `gzerror'
/usr/bin/ld: libbwa.a(utils.o): in function `ks_getuntil2(__kstream_t*, int, __kstring_t*, int*, int) [clone .constprop.0]':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:144:(.text+0x1e2c): undefined reference to `gzread'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:149:(.text+0x2018): undefined reference to `gzerror'
/usr/bin/ld: libbwa.a(utils.o): in function `kseq_read(kseq_t*)':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:144:(.text+0x2158): undefined reference to `gzread'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:144:(.text+0x21e4): undefined reference to `gzread'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:144:(.text+0x23c0): undefined reference to `gzread'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:144:(.text+0x256c): undefined reference to `gzread'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:149:(.text+0x26e4): undefined reference to `gzerror'
/usr/bin/ld: libbwa.a(utils.o): in function `err_gzread':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:144:(.text+0x2874): undefined reference to `gzread'
/usr/bin/ld: libbwa.a(utils.o): in function `err_gzclose':
/home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:280:(.text+0x2d9c): undefined reference to `gzclose'
/usr/bin/ld: /home/ubuntu/tmp/bwa-mem2-2.2.1/src/utils.cpp:283:(.text+0x2db4): undefined reference to `zError'
collect2: error: ld returned 1 exit status
make: *** [Makefile:153: bwa-mem2] Error 1

I'm either doing something wrong (PEBKAC) or there's some sort of regression in #335, #49, ...?

I can see some outstanding symbol visibility issues in #34, perhaps it's a known issue ATM?

The same issue is also present in #365

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions