Fails building with lld and libc++
Describe the bug Doesn't build with clang, llvm, lld and libc++.
List relevant hardware/software information
- OS: Arch Linux
- Packages:
-
- linux615-tkg-eevdf-llvm 6.15.rc2-273
-
-
mangohud-git0.8.1.r31.gd416a83-1
-
-
-
clang19.1.7-1
-
-
-
llvm19.1.7-1
-
-
-
lld19.1.7-1
-
-
-
libc++19.1.7-1
-
To Reproduce Steps to reproduce the behavior:
-
sudo pacman -S clang llvm lld libc++ - Edit
/etc/makepkg.conf:
export CC=clang
export CXX=clang++
CXXFLAGS="... -stdlib=libc++"
LDFLAGS="... -fuse-ld=lld"
-
git clone https://aur.archlinux.org/mangohud-git.git -
makepkg -sirc
Expected behavior It should build.
Additional context Unless it's not a supported build type, it should work. Possibly related to #1240 and #1419.
Can you narrow it down a bit? mangohud seems to compile fine with clang, just some warnings.
libc++ could be the culprit.
Nvm, still fails without libc++ too, this time complains about lld linker.
[105/106] Linking target src/libMangoHud.so
FAILED: src/libMangoHud.so
clang++ -o src/libMangoHud.so src/libMangoHud.a.p/vulkan.cpp.o src/libMangoHud.a.p/mesa_util_os_socket.c.o src/libMangoHud.a.p/mesa_util_os_time.c.o src/libMangoHud.a.p/hud_elements.cpp.o src/libMangoHud.a.p/overlay.cpp.o src/libMangoHud.a.p/overlay_params.cpp.o src/libMangoHud.a.p/font.cpp.o src/libMangoHud.a.p/keybinds.cpp.o src/libMangoHud.a.p/font_unispace.c.o src/libMangoHud.a.p/logging.cpp.o src/libMangoHud.a.p/config.cpp.o src/libMangoHud.a.p/gpu.cpp.o src/libMangoHud.a.p/blacklist.cpp.o src/libMangoHud.a.p/file_utils.cpp.o src/libMangoHud.a.p/nvidia.cpp.o src/libMangoHud.a.p/gpu_fdinfo.cpp.o src/libMangoHud.a.p/amdgpu.cpp.o src/libMangoHud.a.p/cpu.cpp.o src/libMangoHud.a.p/memory.cpp.o src/libMangoHud.a.p/iostats.cpp.o src/libMangoHud.a.p/notify.cpp.o src/libMangoHud.a.p/elfhacks.c.o src/libMangoHud.a.p/real_dlsym.c.o src/libMangoHud.a.p/pci_ids.cpp.o src/libMangoHud.a.p/battery.cpp.o src/libMangoHud.a.p/control.cpp.o src/libMangoHud.a.p/device.cpp.o src/libMangoHud.a.p/net.cpp.o src/libMangoHud.a.p/shell.cpp.o src/libMangoHud.a.p/wayland_keybinds.cpp.o src/libMangoHud.a.p/dbus.cpp.o src/libMangoHud.a.p/loaders_loader_dbus.cpp.o src/libMangoHud.a.p/meson-generated_.._.._vk_enum_to_str.c.o -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,-soname,libMangoHud.so -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs -fuse-ld=lld -flto=auto -march=rocketlake -mtune=rocketlake -O3 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wp,-D_GLIBCXX_ASSERTIONS -flto=auto -Wl,--start-group src/libMangoHud.a subprojects/imgui-1.89.9/libimgui.a subprojects/spdlog-1.14.1/src/libspdlog.a subprojects/implot-0.16/libimplot.a -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--exclude-libs,ALL -lGL -static-libstdc++ -Wl,--version-script,/tmp/makepkg/mangohud-git/src/MangoHud/src/mangohud.version /usr/lib/libxkbcommon.so /usr/lib/libwayland-client.so -Wl,--end-group -pthread
ld.lld: error: version script assignment of 'global' to symbol 'dlsym' failed: symbol not defined
ld.lld: error: version script assignment of 'global' to symbol 'mangohud_find_glx_ptr' failed: symbol not defined
ld.lld: error: version script assignment of 'global' to symbol 'mangohud_find_egl_ptr' failed: symbol not defined
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[106/106] Linking target src/libMangoHud_opengl.so
FAILED: src/libMangoHud_opengl.so
clang++ -o src/libMangoHud_opengl.so src/libMangoHud_opengl.so.p/gl_glad.c.o src/libMangoHud_opengl.so.p/gl_gl_renderer.cpp.o src/libMangoHud_opengl.so.p/gl_gl_hud.cpp.o src/libMangoHud_opengl.so.p/gl_inject_egl.cpp.o src/libMangoHud_opengl.so.p/hud_elements.cpp.o src/libMangoHud_opengl.so.p/overlay.cpp.o src/libMangoHud_opengl.so.p/overlay_params.cpp.o src/libMangoHud_opengl.so.p/font.cpp.o src/libMangoHud_opengl.so.p/keybinds.cpp.o src/libMangoHud_opengl.so.p/font_unispace.c.o src/libMangoHud_opengl.so.p/logging.cpp.o src/libMangoHud_opengl.so.p/config.cpp.o src/libMangoHud_opengl.so.p/gpu.cpp.o src/libMangoHud_opengl.so.p/blacklist.cpp.o src/libMangoHud_opengl.so.p/file_utils.cpp.o src/libMangoHud_opengl.so.p/nvidia.cpp.o src/libMangoHud_opengl.so.p/gpu_fdinfo.cpp.o src/libMangoHud_opengl.so.p/amdgpu.cpp.o src/libMangoHud_opengl.so.p/cpu.cpp.o src/libMangoHud_opengl.so.p/memory.cpp.o src/libMangoHud_opengl.so.p/iostats.cpp.o src/libMangoHud_opengl.so.p/notify.cpp.o src/libMangoHud_opengl.so.p/elfhacks.c.o src/libMangoHud_opengl.so.p/real_dlsym.c.o src/libMangoHud_opengl.so.p/pci_ids.cpp.o src/libMangoHud_opengl.so.p/battery.cpp.o src/libMangoHud_opengl.so.p/control.cpp.o src/libMangoHud_opengl.so.p/device.cpp.o src/libMangoHud_opengl.so.p/net.cpp.o src/libMangoHud_opengl.so.p/shell.cpp.o src/libMangoHud_opengl.so.p/wayland_keybinds.cpp.o src/libMangoHud_opengl.so.p/dbus.cpp.o src/libMangoHud_opengl.so.p/loaders_loader_dbus.cpp.o src/libMangoHud_opengl.so.p/mesa_util_os_socket.c.o src/libMangoHud_opengl.so.p/mesa_util_os_time.c.o -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,-soname,libMangoHud_opengl.so -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs -fuse-ld=lld -flto=auto -march=rocketlake -mtune=rocketlake -O3 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wp,-D_GLIBCXX_ASSERTIONS -flto=auto -Wl,--start-group src/libMangoHud.a subprojects/imgui-1.89.9/libimgui.a subprojects/spdlog-1.14.1/src/libspdlog.a subprojects/implot-0.16/libimplot.a -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--exclude-libs,ALL -lGL -static-libstdc++ -Wl,--version-script,/tmp/makepkg/mangohud-git/src/MangoHud/src/mangohud.version /usr/lib/libxkbcommon.so /usr/lib/libwayland-client.so -Wl,--end-group -pthread
ld.lld: error: version script assignment of 'global' to symbol 'dlsym' failed: symbol not defined
ld.lld: error: version script assignment of 'global' to symbol 'mangohud_find_glx_ptr' failed: symbol not defined
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
==> ERROR: A failure occurred in build().
Aborting...
==> Removing installed dependencies...
Narrowed it down. Removed lld too, it builds with just clang.
It fails with libc++, it also fails with lld. Both broken, separate issues.
So the libc++ fails are in my original build-fail.txt. First issue is that. After that, even removing libc++ from makepkg.conf, it fails because of lld linker too. That's in my last comment. (Interestingly enough, it works with mold linker)
So in summary:
- clang = builds
- clang + mold = builds
- clang + lld + libc++ = fails (because of libc++)
- clang + lld = fails (because of lld)
These are fails, not warnings. So guess both libc++ and lld part of the build process would need to be fixed. As they seem separate from each other on why they fail.
the libc++ failure is an issue in the cmocka header having a #define fail _fail macro, it's not really fixable except upstream (report it to https://gitlab.com/cmocka/cmocka). of course, it would be a breaking change for them to get rid of it, but just having a macro with a basic name like that is not great
the error: version script assignment are from using a --version-script that defines a global: symbol that isn't actually defined. ld.bfd/mold ignore these (or print a warning), but lld errors on it since 19. e.g. the link of libMangoHud.so throws
ld.lld: error: version script assignment of 'global' to symbol 'dlsym' failed: symbol not defined
ld.lld: error: version script assignment of 'global' to symbol 'mangohud_find_glx_ptr' failed: symbol not defined
ld.lld: error: version script assignment of 'global' to symbol 'mangohud_find_egl_ptr' failed: symbol not defined
but libMangoHud.so does not define any of those symbols (it uses dlsym but doesn't define it, and the other 2 aren't linked to). same deal for the other .so's
the 'correct' fix would be to have a separate .version file per-SO to only mention what is used, the workaround fix would be to pass -Wl,--undefined-version for lld to not complain (can add it to link_args = cc.get_supported_link_arguments()).
the libc++ failure is an issue in the cmocka header
(this also only affects the tests which were disabled in 0c11540e)