Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WebDrake opened this issue Jan 27, 2021 · 0 comments
Open

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

WebDrake opened this issue Jan 27, 2021 · 0 comments

Comments

@WebDrake
Copy link
Contributor

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.

WebDrake added a commit to WebDrake/ldc2.snap that referenced this issue Mar 25, 2021
By default snapcraft will rewrite the RPATH of binaries to link against
libraries in the core snap.  However, the prebuilt binaries used in the
LDC package are designed and expected to link against host system libs.
To allow them to do this we need to explicitly instruct snapcraft using
the `no-patchelf` build attribute.

For background see:
https://forum.snapcraft.io/t/librt-so-1-undefined-symbol-clock-nanosleep/16246/2

This should allow LTO builds with LDC >= 1.21.0 to work on more recent
systems (e.g. Ubuntu 20.04+).

Fixes ldc-developers#121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant