Skip to content

Commit

Permalink
ghostscript: use system-wide openjpeg
Browse files Browse the repository at this point in the history
The following error occurs when using `imagemagickBig`:

    $ ./result/bin/identify sample.jp2
    [1]    699089 IOT instruction (core dumped)  ./result/bin/identify sample.jp2

When looking at the call-trace it seems as if certain symbols, e.g.
`opj_malloc` are mixed up:

    NixOS#8  0x00007f78c79ad2f5 in MagickSignalHandler.cold () from /nix/store/bqy80qiw6czqh7vsmmmivwdswp9zzjgl-imagemagick-7.1.0-29/lib/libMagickCore-7.Q16HDRI.so.10
    NixOS#9  <signal handler called>
    NixOS#10 0x00007f78c5a6095f in opj_malloc () from /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9
    NixOS#11 0x00007f78c5a60981 in opj_calloc () from /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9
    NixOS#12 0x00007f78c4f48e24 in opj_create_decompress () from /nix/store/qwalb0kjz1p9c4j48qkk6ql47ds2lnhh-openjpeg-2.4.0/lib/libopenjp2.so.7

The `opj_create_decompress()` is called from the `openjpeg`-integration
of `imagemagick` and thus shouldn't affect `ghostscript` at all.
However, `ghostscript` (`libgs.so` to be precise) also exposes e.g.
`opj_malloc`:

    $ objdump -t /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9.55|grep opj_malloc
    0000000000205940 g     F .text	000000000000002b              opj_malloc

Because of that, two incompatible symbols are used in the same process
and thus the `identify`-call breaks because the wrong one is used. To
work around that I decided to use the system-wide openjpeg instead.
I'm not sure why `libgs.so` wants to expose these symbols anyways, but
with that workaround the problem is solved.

Even though it's mentioned that ghostscript's openjpeg is heavily
patched, I think that this is somewhat outdated or at least irrelevant
considering that both ArchLinux[1] and Fedora[2] use the system-wide
`openjpeg` instead.

[1] https://github.com/archlinux/svntogit-packages/blob/bafcb5473b59d5386dd110d1cb249372dce9ea6c/trunk/PKGBUILD#L50
[2] https://src.fedoraproject.org/rpms/ghostscript/blob/e4eec13ab6ace2bad64b740d352964bbf61d1aa7/f/ghostscript.spec#_245
  • Loading branch information
Ma27 committed Apr 22, 2022
1 parent 3e5baa1 commit d921815
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkgs/misc/ghostscript/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ config, stdenv, lib, fetchurl, pkg-config, zlib, expat, openssl, autoconf
, libjpeg, libpng, libtiff, freetype, fontconfig, libpaper, jbig2dec
, libiconv, ijs, lcms2, fetchpatch, callPackage, bash, buildPackages
, libiconv, ijs, lcms2, fetchpatch, callPackage, bash, buildPackages, openjpeg
, cupsSupport ? config.ghostscript.cups or (!stdenv.isDarwin), cups
, x11Support ? cupsSupport, xlibsWrapper # with CUPS, X11 only adds very little
}:
Expand Down Expand Up @@ -61,7 +61,7 @@ stdenv.mkDerivation rec {
buildInputs = [
zlib expat openssl
libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
libiconv ijs lcms2 bash
libiconv ijs lcms2 bash openjpeg
]
++ lib.optional x11Support xlibsWrapper
++ lib.optional cupsSupport cups
Expand All @@ -72,8 +72,7 @@ stdenv.mkDerivation rec {
export CCAUX=$CC_FOR_BUILD
${lib.optionalString cupsSupport ''export CUPSCONFIG="${cups.dev}/bin/cups-config"''}
# requires in-tree (heavily patched) openjpeg
rm -rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs
rm -rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs openjpeg
sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib.dev}/include@" -i configure.ac
Expand Down

0 comments on commit d921815

Please sign in to comment.