Comment 3 for bug 1861026

Revision history for this message
Jamie Strandboge (jdstrand) wrote : Re: python3-magic 'undefined symbol: magic_open' on UC devices but not classic (ctypes issue)

Thanks Chris! We discussed this more on irc and found that python has fallbacks. It will use ldconfig -p, but also gcc and ld to try to find things. I found that by looking at strace, I was able to workaround this by adjusting the snapcraft.yaml to have:

  buildme:
    source: .
    plugin: python
    override-build: |
      snapcraftctl build
      # cd into the gnu triplet then create libmagic.so symlink for both
      # 'ld -t -L ... -lmagic' (from the staged binutils) and
      # 'stat(.../magic.so)'. LP: #1861026
      orig=$(pwd)
      libmagic=$(find "$SNAPCRAFT_PART_INSTALL"/usr/lib -name libmagic.so.1.0.0)
      cd $(dirname $libmagic)
      ln -sf libmagic.so.1.0.0 libmagic.so
      cd $orig
    stage-packages:
    - binutils
    - libmagic1
    - python3-magic

Now it works:

$ cat /etc/lsb-release
DISTRIB_ID="Ubuntu Core"
DISTRIB_RELEASE=16
DISTRIB_DESCRIPTION="Ubuntu Core 16"

$ test-python3-magic /bin/ls
/bin/ls: application/x-sharedlib

I discovered this by looking at strace (eg, snap run --strace="-o ./trace" test-python3-magic /bin/ls) and found things like:

4902 execve("/snap/test-python3-magic/x5/usr/sbin/ld", ["ld", "-t", "-L", "/var/lib/snapd/lib/gl", "-L", "/var/lib/snapd/lib/gl32", "-L", "/var/lib/snapd/void", "-L", "", "-L", "/snap/test-python3-magic/x5/lib", "-L", "/snap/test-python3-magic/x5/usr/"..., "-L", "/snap/test-python3-magic/x5/lib/"..., "-L", "/snap/test-python3-magic/x5/usr/"..., "-o", "/dev/null", "-lmagic"], 0x7ffde43b0578 /* 44 vars */) = -1 ENOENT (No such file or directory)

The trick was noticing that I needed *both* an ld in PATH in the snap (so I stage binutils) *and* the magic.so symlink to point to what is shipped (the override-build). This could possibly be achieved with a layout (does $SNAPCRAFT_ARCH_TRIPLET work with layouts?).