conda-forge / graphviz-feedstock

A conda-smithy repository for graphviz.
BSD 3-Clause "New" or "Revised" License
5 stars 29 forks source link

gvpack segfault in Docker Linux: Relink with libm for IFUNC symbol `cos' #119

Closed mharradon closed 1 year ago

mharradon commented 1 year ago

Solution to issue cannot be found in the documentation.

Issue

Hello,

I'm currently seeing a segfault when running gvpack inside an Ubuntu 18.04.6 docker container:

(base) root@b0b20daff04e:/# conda create --name gv graphviz
...
(base) root@b0b20daff04e:/# conda activate gv
(gv) root@b0b20daff04e:/# gvpack
gvpack: Relink `/var/overmind/miniconda/envs/gv/bin/../lib/graphviz/../libgts-0.7.so.5' with `/lib/x86_64-linux-gnu/libm.so.6' for IFUNC symbol `cos'
Segmentation fault

I see the same result in a much larger environment with a newer conda version as well.

Thanks in advance! Apologies if I'm sharing this in the wrong place.

Installed packages

# packages in environment at /var/overmind/miniconda/envs/gv:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
atk-1.0                   2.38.0               hd4edc92_1    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
cairo                     1.16.0            h35add3b_1015    conda-forge
expat                     2.5.0                hcb278e6_1    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.12.1               hca18f0e_1    conda-forge
fribidi                   1.0.10               h36c2ea0_0    conda-forge
gdk-pixbuf                2.42.10              h6b639ba_2    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
giflib                    5.2.1                h0b41bf4_3    conda-forge
graphite2                 1.3.14               h295c915_1
graphviz                  7.1.0                h2e5815a_0    conda-forge
gtk2                      2.24.33              h90689f9_2    conda-forge
gts                       0.7.6                h64030ff_2    conda-forge
harfbuzz                  6.0.0                h3ff4399_1    conda-forge
icu                       72.1                 hcb278e6_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libdeflate                1.18                 h0b41bf4_0    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgd                     2.3.3                hfa28ad5_6    conda-forge
libglib                   2.74.1               h606061b_1    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
libjpeg-turbo             2.1.5.1              h0b41bf4_0    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
librsvg                   2.54.4               h7abd40a_0    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libtiff                   4.5.0                ha587672_6    conda-forge
libtool                   2.4.7                h27087fc_0    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp                   1.3.0                hb47c5f0_0    conda-forge
libwebp-base              1.3.0                h0b41bf4_0    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libxml2                   2.10.3               hfdac1af_6    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
pango                     1.50.14              hd33c08f_0    conda-forge
pcre2                     10.40                hc3806b6_0    conda-forge
pixman                    0.40.0               h36c2ea0_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.0.10               h7f98852_0    conda-forge
xorg-libsm                1.2.3             hd9c2040_1000    conda-forge
xorg-libx11               1.8.4                h0b41bf4_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h0b41bf4_2    conda-forge
xorg-libxrender           0.9.10            h7f98852_1003    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-xextproto            7.3.0             h0b41bf4_1003    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.10               h5eee18b_1
zlib                      1.2.13               h166bdaf_4    conda-forge
zstd                      1.5.4                hc292b87_0

Environment info

active environment : gv
    active env location : /var/overmind/miniconda/envs/gv
            shell level : 2
       user config file : /root/.condarc
 populated config files : /root/.condarc
          conda version : 22.9.0
    conda-build version : 3.22.0
         python version : 3.9.13.final.0
       virtual packages : __cuda=11.2=0
                          __linux=5.15.49=0
                          __glibc=2.27=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /var/overmind/miniconda  (writable)
      conda av data dir : /var/overmind/miniconda/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /var/overmind/miniconda/pkgs
                          /root/.conda/pkgs
       envs directories : /var/overmind/miniconda/envs
                          /root/.conda/envs
               platform : linux-64
             user-agent : conda/22.9.0 requests/2.28.1 CPython/3.9.13 Linux/5.15.49-linuxkit ubuntu/18.04.6 glibc/2.27
                UID:GID : 0:0
             netrc file : None
           offline mode : False
mharradon commented 1 year ago

I confirmed the segfault reproduces in the local docker build for graphviz-feedstock. I believe I fixed the issue by building statically here: #120 . I'm not sure if this is a good solution.

mharradon commented 1 year ago

I suggest that #120 is closed in favor of #123 unless there are other issues with those flags.

mharradon commented 1 year ago

Any update on this? Would it be possible to accept #123? If gvpack is tested it segfaults in the current recipe build on Linux. The simple compiler flag changes used in the Anaconda build (#123) fix it.

nehaljwani commented 1 year ago

Hello @mharradon, thank you for reporting this issue and providing a potential workaround.

I spent some time digging to find out why this is happening. The actual problem lies with the conda-forge build of ligbts. It should be having libm.so as a dependency, but currently it isn't:

$ ldd /path/to/env/lib/libgts-0.7.so.5
    linux-vdso.so.1 (0x00007ff9e6fac000)
    libglib-2.0.so.0 => /path/to/env/lib/./libglib-2.0.so.0 (0x00007ff9e6dfb000)
    libc.so.6 => /lib64/libc.so.6 (0x00007ff9e6bf2000)
    libiconv.so.2 => /path/to/env/lib/././libiconv.so.2 (0x00007ff9e6b09000)
    librt.so.1 => /lib64/librt.so.1 (0x00007ff9e6b04000)
    libpcre2-8.so.0 => /path/to/env/lib/././libpcre2-8.so.0 (0x00007ff9e6a64000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff9e6a5f000)
    /lib64/ld-linux-x86-64.so.2 (0x00007ff9e6fae000)

$ nm /path/to/env/lib/libgts-0.7.so.5 | grep sincos
                 U sincos

To confirm my hunch, I forcefully added a dependency and the issue went away:

$ patchelf --add-needed /lib64/libm.so.6 /path/to/env/ib/libgts-0.7.so.5

Adding LDFLAGS=-L$PREFIX/lib during graphviz's seems to fix this issue because it ends up removing: --Wl,--as-needed from $LDFLAGS. This comes from the default flags set by the compiler activation package. This removal changes the ordering of dependencies, thereby hiding the actual issue.

I've reported this issue at https://github.com/conda-forge/gts-feedstock/issues/5 and also provided a patch to fix their build. Once a new build is installed, the issue with gvpack will resolve automatically.

mharradon commented 1 year ago

Thank you!

nehaljwani commented 1 year ago

The new build of gts is out. And it resolves the issue:

(/root/dev) root@1fd19801e0b7:~# conda list gts
# packages in environment at /root/dev:
#
# Name                    Version                   Build  Channel
gts                       0.7.6                h64030ff_2    conda-forge
(/root/dev) root@1fd19801e0b7:~# objdump -p ./dev/lib/libgts.so  | grep NEEDED
  NEEDED               libglib-2.0.so.0
  NEEDED               libc.so.6
(/root/dev) root@1fd19801e0b7:~# gvpack --help
gvpack: Relink `/root/dev/bin/../lib/graphviz/../libgts-0.7.so.5' with `/lib/x86_64-linux-gnu/libm.so.6' for IFUNC symbol `cos'
Segmentation fault
(/root/dev) root@1fd19801e0b7:~# conda update gts -c conda-forge
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /root/dev

  added / updated specs:
    - gts

The following packages will be UPDATED:

  gts                                      0.7.6-h64030ff_2 --> 0.7.6-h977cf35_4

Proceed ([y]/n)?

Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(/root/dev) root@1fd19801e0b7:~# objdump -p ./dev/lib/libgts.so  | grep NEEDED
  NEEDED               libglib-2.0.so.0
  NEEDED               libm.so.6
  NEEDED               libc.so.6
(/root/dev) root@1fd19801e0b7:~# gvpack --help
gvpack: option -- unrecognized
Usage: gvpack [-gnuv?] [-m<margin>] {-array[_rc][n]] [-o<outf>] <files>
  -n          - use node granularity
  -g          - use graph granularity
  -array*     - pack as array of graphs
  -G<n>=<v>   - attach name/value attribute to output graph
  -m<n>       - set margin to <n> points
  -s<gname>   - use <gname> for name of root graph
  -o<outfile> - write output to <outfile>
  -u          - no packing; just combine graphs
  -v          - verbose
  -?          - print usage
If no files are specified, stdin is used