-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
htslib protocol plugins (https/S3) cannot be loaded on macOS #1176
Comments
This (also reported in bioconda/bioconda-recipes#15415 (comment)) is a macOS problem whereby when both static libhts.a and shared libhts.dylib are linked into or loaded into a running program, two separate copies of the library's functions and global variables (notably hfile.c's I believe this problem is limited to macOS. The proper fix needs thinking about, and may involve finally linking htsfile/tabix/samtools/etc against libhts.dylib dynamically and/or rethinking linking the plugins against libhts. In the meantime, rebuilding the plugins with this patch should make this work on macOS: diff --git a/Makefile b/Makefile
index 245b7a1..e0d8b18 100644
--- a/Makefile
+++ b/Makefile
@@ -310,8 +312,8 @@ hts-object-files: $(LIBHTS_OBJS)
%.so: %.pico libhts.so
$(CC) -shared -Wl,-E $(LDFLAGS) -o $@ $< libhts.so $(LIBS) -lpthread
-%.bundle: %.o libhts.dylib
- $(CC) -bundle -Wl,-undefined,dynamic_lookup $(LDFLAGS) -o $@ $< libhts.dylib $(LIBS)
+%.bundle: %.o
+ $(CC) -bundle -Wl,-undefined,dynamic_lookup $(LDFLAGS) -o $@ $< $(LIBS) and I will soon be proposing a similar update to the bioconda recipe to make the bioconda package work again in this respect. |
Thank you for identifying and taking care of the problem! |
Backport symbol name typo fix; apply simplified form of upcoming fix for samtools/htslib#1176. Patches applicable to HTSlib 1.11; will not be needed for future upstream versions.
Backport symbol name typo fix; apply simplified form of upcoming fix for samtools/htslib#1176. Patches applicable to HTSlib 1.11; will not be needed for future upstream versions.
This is resolved in the bioconda package (by way of a local patch), but not yet resolved in HTSlib itself. So let's keep this open as a reminder that I still have to make an HTSlib PR for this. |
PR samtools#1072 changed plugin linking so that plugins are linked back to the dynamic libhts.so/.dylib, to facilitate use when libhts is itself dynamically dlopen()ed with RTLD_LOCAL, e.g., by the Python runtime which uses default dlopen() flags which on Linux means RTLD_LOCAL. This broke plugin loading on macOS when opening plugins in an executable in which libhts.a has been statically linked, as there were then two copies of the library globals (notably hfile.c::schemes), one from the executable's libhts.a and one from the plugin's libhts.NN.dylib. (The Linux loading model does not suffer from this issue.) The default dlopen() flag on macOS is RTLD_GLOBAL, so this can be fixed by reverting the change (on macOS only) and depending on the symbols supplied by a static libhts.a, a dynamically linked libhts.NN.dylib, or a RTLD_GLOBALly dlopen()ed libhts.NN.dylib. This rebreaks the case of dlopen()ing libhts on macOS while explicitly specifying RTLD_LOCAL, but this is not a common case. Fixes samtools#1176. Disable the `plugins-dlhts -l` test case on macOS. Add a test of accessing plugins from an executable with a statically linked libhts.a (namely, htsfile) to test/test.pl.
PR samtools#1072 changed plugin linking so that plugins are linked back to the dynamic libhts.so/.dylib, to facilitate use when libhts is itself dynamically dlopen()ed with RTLD_LOCAL, e.g., by the Python runtime which uses default dlopen() flags which on Linux means RTLD_LOCAL. This broke plugin loading on macOS when opening plugins in an executable in which libhts.a has been statically linked, as there were then two copies of the library globals (notably hfile.c::schemes), one from the executable's libhts.a and one from the plugin's libhts.NN.dylib. (The Linux loading model does not suffer from this issue.) The default dlopen() flag on macOS is RTLD_GLOBAL, so this can be fixed by reverting the change (on macOS only) and depending on the symbols supplied by a static libhts.a, a dynamically linked libhts.NN.dylib, or a RTLD_GLOBALly dlopen()ed libhts.NN.dylib. This rebreaks the case of dlopen()ing libhts on macOS while explicitly specifying RTLD_LOCAL, but this is not a common case. Fixes samtools#1176. Disable the `plugins-dlhts -l` test case on macOS. Add a test of accessing plugins from an executable with a statically linked libhts.a (namely, htsfile) to test/test.pl.
PR #1072 changed plugin linking so that plugins are linked back to the dynamic libhts.so/.dylib, to facilitate use when libhts is itself dynamically dlopen()ed with RTLD_LOCAL, e.g., by the Python runtime which uses default dlopen() flags which on Linux means RTLD_LOCAL. This broke plugin loading on macOS when opening plugins in an executable in which libhts.a has been statically linked, as there were then two copies of the library globals (notably hfile.c::schemes), one from the executable's libhts.a and one from the plugin's libhts.NN.dylib. (The Linux loading model does not suffer from this issue.) The default dlopen() flag on macOS is RTLD_GLOBAL, so this can be fixed by reverting the change (on macOS only) and depending on the symbols supplied by a static libhts.a, a dynamically linked libhts.NN.dylib, or a RTLD_GLOBALly dlopen()ed libhts.NN.dylib. This rebreaks the case of dlopen()ing libhts on macOS while explicitly specifying RTLD_LOCAL, but this is not a common case. Fixes #1176. Disable the `plugins-dlhts -l` test case on macOS. Add a test of accessing plugins from an executable with a statically linked libhts.a (namely, htsfile) to test/test.pl.
htslib 1.11 cannot read any files using HTTPS or S3 on macOS. I tested with the following files:
This error persists using the bioconda's htslib 1.11 or the one I built on macOS using the following steps:
It seems that the plugin bundle is loaded after registering the protocol handler. I came across with this issue while investigating brentp/cyvcf2#174 which links to htslib 1.10. Version 1.10 can read the two files fine using the build from bioconda or self-compiled:
The text was updated successfully, but these errors were encountered: