GPUOpen-Drivers / llpc

LLVM-Based Pipeline Compiler
MIT License
165 stars 115 forks source link

llpc/tool/vfx/vfxParser.cpp sometimes build without -fPIC, causes failed linking #1594

Closed RarogCmex closed 1 month ago

RarogCmex commented 2 years ago

I'm Gentoo Linux proxy maintainer, working for packaging AMDVLK for Gentoo. There are weird bug where

/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: compiler/vfx/libvfx.a(vfxSection.cpp.o): warning: relocation against _ZN3Vfx23GetSubStateMemberHelperINS_25SectionVertexInputBindingEM31VkVertexInputBindingDescriptionjXadL_ZNS2_6strideEEEE12getMemberPtrEPv' in read-only section `.text._ZN3Vfx10ParserInitC2Ev[_ZN3Vfx10ParserInitC5Ev]'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: compiler/vfx/libvfx.a(vfxParser.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN3Vfx7Section13m_sectionInfoB5cxx11E' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

Here is the build stage of vfxParser.cpp.o from log:

[2123/2557] /usr/bin/x86_64-pc-linux-gnu-g++ -DLITTLEENDIAN_CPU -DLLPC_CLIENT_INTERFACE_MAJOR_VERSION=52 -DPAL_CLIENT_INTERFACE_MAJOR_VERSION=687 -DVFX_SUPPORT_VK_PIPELINE -I/var/tmp/portage/media-libs/amdvlk-2021.4.2/work/llpc/tool/vfx -I/var/tmp/portage/media-libs/amdvlk-2021.4.2/work/llpc/tool/vfx/../../imported/spirv -I/var/tmp/portage/media-libs/amdvlk-2021.4.2/work/llpc/tool/vfx/../../include -I/var/tmp/portage/media-libs/amdvlk-2021.4.2/work/xgl/icd/api/include/khronos -I/var/tmp/portage/media-libs/amdvlk-2021.4.2/work/llpc/include/khronos  -march=ivybridge -O2 -pipe -mmmx -msse -msse2 -msse3 -mssse3 -mcx16 -msahf -maes -mpclmul -mpopcnt -mavx -msse4.2 -msse4.1 -mrdrnd -mf16c -mfsgsbase -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=15360 -std=gnu++14 -MD -MT compiler/vfx/CMakeFiles/vfx.dir/vfxPipelineDoc.cpp.o -MF compiler/vfx/CMakeFiles/vfx.dir/vfxPipelineDoc.cpp.o.d -o compiler/vfx/CMakeFiles/vfx.dir/vfxPipelineDoc.cpp.o -c /var/tmp/portage/media-libs/amdvlk-2021.4.2/work/llpc/tool/vfx/vfxPipelineDoc.cpp

It does not have -fPIC flag

RarogCmex commented 2 years ago

I've tried to add -fPIC manually in Gentoo ebuild, but it still builds without Here it the complete build log with all circumstances: build.log

kuhar commented 2 years ago

Thanks for reporting, @RarogCmex. Are you able to provide the full cmake invocation used?

RarogCmex commented 2 years ago

Are you able to provide the full cmake invocation used?

If it doesn't have in build log, I'm not able.

I think incorrect behavior of cmake can be caused by https://github.com/GPUOpen-Drivers/llpc/blob/dev/tool/vfx/Makefile.apicompilertoolvfx However, I am not C++ programmer, so I'm not sure.

kuhar commented 2 years ago

I found this in the log:

cmake -C /var/tmp/portage/media-libs/amdvlk-2021.4.2/work/xgl_build-abi_x86_64.amd64/gentoo_common_config.cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_WAYLAND_SUPPORT=yes -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=/var/tmp/portage/media-libs/amdvlk-2021.4.2/work/xgl_build-abi_x86_64.amd64/gentoo_toolchain.cmake  /var/tmp/portage/media-libs/amdvlk-2021.4.2/work/xgl

Where can we find the gentoo .cmake files?

RarogCmex commented 2 years ago

I should brief introduce you into Gentoo Ebuild system. It uses ebuild files, in ebuild there are eclass methods, which performs build. In ebuild there are cmake_compile method (may be hidden if we use default ones) which perform cmake build

gentoo_common_config.cmake comes from cmake-utils.eclass helper: https://github.com/gentoo/gentoo/blob/master/eclass/cmake-utils.eclass

    local common_config=${BUILD_DIR}/gentoo_common_config.cmake
    local libdir=$(get_libdir)
    cat > "${common_config}" <<- _EOF_ || die
        SET (CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build")
        SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
        SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
        SET (CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "")
        SET (CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "")
        SET (CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules")
    _EOF_
RarogCmex commented 2 years ago

I've pack all generated .cmake files: cmake-files.tar.gz

RarogCmex commented 2 years ago

Also Gentoo ebuild file (instructions for Gentoo portage package manager) amdvlk-2021.4.2.ebuild.zip

AndrewAmmerlaan commented 2 years ago

/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: compiler/vfx/libvfx.a(vfxParser.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN3Vfx7Section13m_sectionInfoB5cxx11E' can not be used when making a shared object; recompile with -fPIC

This kind of error occurs when you've compiled something with -fPIC (default on Gentoo) and try to link it to something that has not been compiled with -fPIC. Very likely the sources contain something that has been pre-compiled without -fPIC, the solution is usually to delete the pre-compiled file and force it to be rebuild by the build system. If that doesn't work you can try building the entire thing without -fPIC (though that might cause problems down the line).

RarogCmex commented 2 years ago

@AndrewAmmerlaan Sorry, sure, cpt. Obvious. I've wondering why llpc/tool/vfx/vfxParser.cpp are building without -fPIC despite it should be build with it and there is no other visible reasons why it shouldn't. Even if I force -fPIC it builds without, so reason for this exist, but I can't find it.