zeux/volk

mold linker symbol mismatch warning

mokafolio opened this issue · 7 comments

Hi,

When linking volk using mold linker, I get a ton of warnings (one for each definition) like:

mold: warning: symbol type mismatch: vkGetDeviceQueue2
>>> defined in Submodules/volk/libvolk.a(volk.c.o) as STT_OBJECT
>>> defined in /home/moka/vulkan/1.3.250.1/x86_64/lib/libvulkan.so as STT_FUNC

I am on arch linux using mold linker 2.0. The warning seems to be added in the 2.0 version of the linker so I am not entirely sure if this issue is with mold or volk at this point.

I am linking volk with cmake via the volk target. Mold is enabled like this: cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fuse-ld=mold" .. . For what it's worth, the same happens if I compile volk into my own c/cpp file.

Any ideas welcome,
Thanks!

zeux commented

You should not be linking libvulkan when using volk.

I am not, at least not on purpose. Could it be that SDL pulls in vulkan somehow?

I just checked, the same issue persists when removing SDL from the equation. The only cmake subfolder I go into that calls find_package(Vulkan ...) is volk. I will do some more invastigating, certainly odd.

I put a minimal example to reproduce the issue over here: https://github.com/mokafolio/Volkmold. Build using:

mkdir build
cd build
cmake -GNinja -DCMAKE_CXX_FLAGS="-fuse-ld=mold" ..
ninja
zeux commented

Works fine for me:

~/Volkmold/build $ cmake -GNinja -DCMAKE_CXX_FLAGS="-fuse-ld=mold" ..
-- The CXX compiler identification is GNU 12.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
 Vulkan as target
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/zeux/Volkmold/build
~/Volkmold/build $ ninja
(0.145) [2/2] Linking CXX executable Volkmold

However, I do see libvulkan.so appended in the command line. This should not happen. I think it's happening because of declared dependency on Vulkan::Vulkan in volk's CMakeLists.txt via target_link_libraries here:

    if(TARGET volk)
      target_link_libraries(volk PUBLIC Vulkan::Vulkan)
    endif()
    target_link_libraries(volk_headers INTERFACE Vulkan::Vulkan)

These are wrong, but I'd need to go back in CMake history to see why they were added / how to best fix it, as we need an include dependency from Vulkan::Vulkan but not the libraries.

zeux commented

Ok yeah this is due to a dependency on Vulkan::Vulkan, which should not be here. What needs to happen is either that we only depend on Vulkan::Headers, or that we grab the include path from Vulkan::Vulkan and manually add it to volk. I have a patch for the latter that seems to work but I need to look at whether we can just rely on Vulkan::Headers as it's simpler.

zeux commented

Posted a patch that seems to be the most straightforward way to handle this atm. Vulkan::Headers is new as of CMake 3.21, so for now we need to rely on the variables set by FindVulkan.cmake as I understand it.

I just tested your branch and can confirm that it fixes the warnings on mold 2.0. Thanks for the blazingly fast turnaround! Feel free to close the issue once you merge the PR!