Linuxbrew / legacy-linuxbrew

:skull: This repository is defunct, because it has been split into https://github.com/Linuxbrew/brew and https://github.com/Linuxbrew/homebrew-core
http://linuxbrew.sh
Other
2.23k stars 297 forks source link

BWA can't find libgcc_s.so.1 (standalone) #437

Closed Sterbic closed 6 years ago

Sterbic commented 9 years ago

I have an issue when with BWA installed through the provided formula. I'm running linuxbrew standalone on Ubuntu 14.04.

[M::bwa_idx_load_from_disk] read 0 ALT contigs
[M::process] read 3668 sequences (10002530 bp)...
[M::process] read 3962 sequences (10000515 bp)...
libgcc_s.so.1 must be installed for pthread_cancel to work
Aborted (core dumped)

I have checked the lib folder of my installation of linuxbrew and the file is there but BWA seems unable to find it.

Could the issue be with the formula using the binary instead of compiling from source?

sjackman commented 9 years ago

Hmm. Please report

brew list --versions gcc patchelf bwa
ldd `which bwa`
ls -l `brew --prefix`/lib/libgcc_s.so.1
ls -l `brew --prefix gcc`/lib/libgcc_s.so.1

As a workaround, try brew install -s bwa

Sterbic commented 9 years ago
$ brew list --versions gcc patchelf bwa
gcc 4.9.2
patchelf 0.8
bwa 0.7.12

$ ldd `which bwa`
    linux-vdso.so.1 (0x00007ffeb87fe000)
    libm.so.6 => /share/linuxbrew/.linuxbrew/lib/libm.so.6 (0x00007f27cebf1000)
    libz.so.1 => /share/linuxbrew/.linuxbrew/lib/libz.so.1 (0x00007f27ce9de000)
    libpthread.so.0 => /share/linuxbrew/.linuxbrew/lib/libpthread.so.0 (0x00007f27ce7c2000)
    librt.so.1 => /share/linuxbrew/.linuxbrew/lib/librt.so.1 (0x00007f27ce5ba000)
    libc.so.6 => /share/linuxbrew/.linuxbrew/lib/libc.so.6 (0x00007f27ce242000)
    /share/linuxbrew/.linuxbrew/opt/glibc/lib/ld-linux-x86-64.so.2 (0x00007f27ceee2000)

$ ls -l `brew --prefix`/lib/libgcc_s.so.1
lrwxrwxrwx 1 - - 37 Lip 11 19:55 /share/linuxbrew/.linuxbrew/lib/libgcc_s.so.1 -> ../Cellar/gcc/4.9.2/lib/libgcc_s.so.1

$ ls -l `brew --prefix gcc`/lib/libgcc_s.so.1
-rwxr-xrwx 1 - - 387124 Lip 11 16:48 /share/linuxbrew/.linuxbrew/opt/gcc/lib/libgcc_s.so.1

Installing from source did fix the issue.

I also tried the following:

  1. install gcc-4.9 standalone deps
  2. install gcc-4.9 standalone through the fixes that are still in the pull request #200
  3. complete standalone installation
  4. checkout master branch
  5. brew pin gcc, as gcc-5 installation fails
  6. brew update and braw tap homebrew/science
  7. brew install bwa
brew install bwa
==> Installing bwa from homebrew/homebrew-science
==> Downloading https://linuxbrew.bintray.com/bottles-science/bwa-0.7.12.x86_64_
==> Pouring bwa-0.7.12.x86_64_linux.bottle.tar.gz
Error: undefined method `prepend_path' for #<Object:0x0000000194fee8>
Warning: Bottle installation failed: building from source.
==> Downloading https://downloads.sf.net/project/bio-bwa/bwa-0.7.12.tar.bz2
...
sjackman commented 9 years ago

Error: undefined method 'prepend_path' for #<Object:0x0000000194fee8> this error was caused by a bug that I introduced last night (unrelated to this issue). It's fixed now.

It's interesting that libgcc_s.so.1 does not show up in the list of shared dependencies of bwa, but is apparently loaded dynamically by libpthread.so.0 (pthread_cancel).

sjackman commented 9 years ago

I don't have an immediate fix for you. I'm glad that the workaround of building from source works for you. I'll let this issue sit for a bit, and see if further information shows up from someone else.

Sterbic commented 9 years ago

It's not listed as a dependency of libpthread.so.0 either.

$ ldd /share/linuxbrew/.linuxbrew/lib/libpthread.so.0
    linux-vdso.so.1 (0x00007ffcc01ab000)
    libc.so.6 => /share/linuxbrew/.linuxbrew/Cellar/glibc/2.19/lib/libc.so.6 (0x00007f123f0ae000)
    /share/linuxbrew/.linuxbrew/Cellar/glibc/2.19/lib/ld-linux-x86-64.so.2 (0x00007f123f426000)

Same result when using readelf. Quite strange...

$ readelf -d /share/linuxbrew/.linuxbrew/lib/libpthread.so.0 | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
sjackman commented 9 years ago

I suspect that it's being loaded dynamically using libdl (dlopen) in libpthread.so.0 (pthread_cancel).

sjackman commented 8 years ago

I've found the cause of this issue and a workaround. The RPATH of the glibc shared libraries is not set. libpthread.so.0 requires libgcc_s.so.1, even though it's not reported by readelf -d libpthread.so.0. It must be loaded dynamically by dlopen. libc.so.6 has no idea where to find libgcc_s.so.1. One hacky but easy workaround is

ln -s `brew --prefix`/lib/libgcc_s.so.1 `brew --prefix glibc`/lib

Another fix is to use patchelf to set the RPATH of libpthread.so.0. Finally, you can use ldconfig like so:

echo `brew --prefix gcc`/lib >>`brew --prefix glibc`/etc/ld.so.conf
ldconfig
sjackman commented 6 years ago

This issue was resolved by symlinking libgcc_s.so.1 into opt/glibc/lib/ when gcc is installed.