ldc-developers / ldc2.snap

Snap package definition for LDC, the LLVM-based D compiler
11 stars 4 forks source link

LTO fails for snap package >= 1.21 on Ubuntu 20.04 #121

Open WebDrake opened 3 years ago

WebDrake commented 3 years ago

When trying to build a simple "Hello World" with LTO, I get the following error:

$ ldmd2 -flto=full hello.d
/usr/bin/ld.gold: error: /snap/ldc2/158/lib/LLVMgold-ldc.so: could not load plugin library: /snap/core/current/lib/x86_64-linux-gnu/librt.so.1: undefined symbol: __clock_nanosleep, version GLIBC_PRIVATE
/usr/bin/ld.gold: error: hello.o:1:3: invalid character
/usr/bin/ld.gold: error: hello.o:1:3: syntax error, unexpected $end
/usr/bin/ld.gold: error: hello.o: not an object or archive
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1

The same underlying upstream package (1.21.0) does not reproduce the problem when unzipped and run directly on the host Ubuntu 20.04 system. The snap packages themselves work fine with LTO on Ubuntu 18.04.

In the 1.20 package the LLVMgold-ldc.so library links to the following shared libs:

$ ldd /snap/ldc2/current/lib/LLVMgold-ldc.so 
    linux-vdso.so.1 (0x00007ffd2779b000)
    libz.so.1 => /snap/core/current/lib/x86_64-linux-gnu/libz.so.1 (0x00007fc5cc7bd000)
    libpthread.so.0 => /snap/core/current/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc5cc5a0000)
    libm.so.6 => /snap/core/current/lib/x86_64-linux-gnu/libm.so.6 (0x00007fc5cc297000)
    libgcc_s.so.1 => /snap/core/current/lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc5cc081000)
    libc.so.6 => /snap/core/current/lib/x86_64-linux-gnu/libc.so.6 (0x00007fc5cbcb7000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc5cf8ee000)

From 1.21 onward librt is also required:

$ ldd /snap/ldc2/current/lib/LLVMgold-ldc.so 
    linux-vdso.so.1 (0x00007ffd391d0000)
    libz.so.1 => /snap/core/current/lib/x86_64-linux-gnu/libz.so.1 (0x00007ff2ead96000)
    librt.so.1 => /snap/core/current/lib/x86_64-linux-gnu/librt.so.1 (0x00007ff2eab8e000)
    libdl.so.2 => /snap/core/current/lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff2ea98a000)
    libpthread.so.0 => /snap/core/current/lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff2ea76d000)
    libm.so.6 => /snap/core/current/lib/x86_64-linux-gnu/libm.so.6 (0x00007ff2ea464000)
    libgcc_s.so.1 => /snap/core/current/lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff2ea24e000)
    libc.so.6 => /snap/core/current/lib/x86_64-linux-gnu/libc.so.6 (0x00007ff2e9e82000)
    /lib64/ld-linux-x86-64.so.2 (0x00007ff2edd9d000)

The libraries concerned are all present in the core snap, so I presume this is a clash between the ld.gold in use (external to the snap) and the librt inside the core snap.