llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.94k stars 11.53k forks source link

Linker Error while compiling SOFA #68188

Open sandeep-amd opened 11 months ago

sandeep-amd commented 11 months ago

Hi,

While trying to compile SOFA(https://github.com/sofa-framework/sofa => branch "v23.06") with LLVM 16 , we are getting linker errors as below,

ld.lld: error: undefined reference due to --no-allow-shlib-undefined: vtable for sofa::linearalgebra::FullVector<double>
>>> referenced by ../../../lib/libSofa.Component.Constraint.Lagrangian.Solver.so.23.06.00
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Sofa/Component/Haptics/CMakeFiles/Sofa.Component.Haptics.dir/build.make:176: lib/libSofa.Component.Haptics.so.23.06.00] Error 1
make[2]: Leaving directory '/home/amd/sandeep/sofa/sofa/build'
make[1]: *** [CMakeFiles/Makefile2:9861: Sofa/Component/Haptics/CMakeFiles/Sofa.Component.Haptics.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

To reproduce this, we have provided a single line command with all the object files attached . The command to reproduce this issue is as below,

/home/amd/compiler/llvm_16_src/llvm_install/bin/clang++ -fPIC -O3 -march=znver3 -flto -Wl,--no-allow-shlib-undefined -O3 -DNDEBUG -flto  -Wl,--no-allow-shlib-undefined -shared -Wl,-soname,libSofa.Component.Haptics.so.23.06.00 -o ./libSofa.Component.Haptics.so.23.06.00 ./init.cpp.o ./ForceFeedback.cpp.o ./LCPForceFeedback.cpp.o ./NullForceFeedback.cpp.o ./NullForceFeedbackT.cpp.o  -Wl,-rpath,/home/amd/sandeep/sofa/sofa/build/lib: ./libSofa.Component.Constraint.Lagrangian.Solver.so.23.06.00 ./libSofa.Simulation.Core.so.23.06.00 ./libSofa.Core.so.23.06.00 ./libSofa.DefaultType.so.23.06.00 ./libSofa.LinearAlgebra.so.23.06.00 ./libSofa.Helper.so.23.06.00 ./libSofa.Topology.so.23.06.00 ./libSofa.Geometry.so.23.06.00 ./libSofa.Type.so.23.06.00 ./libSofa.Compat.so.23.06.00 ./libSofa.Component.Compat.so.23.06.00 ./libSofa.Config.so.23.06.00

We have attached the object files required to reproduce this issue. Please do let us know the solution.

Thanks, Sofa_Obj.tar.gz

Sandeep.

llvmbot commented 11 months ago

@llvm/issue-subscribers-c-1

Hi, While trying to compile SOFA(https://github.com/sofa-framework/sofa => branch "v23.06") with LLVM 16 , we are getting linker errors as below, **ld.lld: error: undefined reference due to --no-allow-shlib-undefined: vtable for sofa::linearalgebra::FullVector<double> >>> referenced by ../../../lib/libSofa.Component.Constraint.Lagrangian.Solver.so.23.06.00 clang-16: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [Sofa/Component/Haptics/CMakeFiles/Sofa.Component.Haptics.dir/build.make:176: lib/libSofa.Component.Haptics.so.23.06.00] Error 1 make[2]: Leaving directory '/home/amd/sandeep/sofa/sofa/build' make[1]: *** [CMakeFiles/Makefile2:9861: Sofa/Component/Haptics/CMakeFiles/Sofa.Component.Haptics.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....** To reproduce this, we have provided a single line command with all the object files attached . The command to reproduce this issue is as below, **/home/amd/compiler/llvm_16_src/llvm_install/bin/clang++ -fPIC -O3 -march=znver3 -flto -Wl,--no-allow-shlib-undefined -O3 -DNDEBUG -flto -Wl,--no-allow-shlib-undefined -shared -Wl,-soname,libSofa.Component.Haptics.so.23.06.00 -o ./libSofa.Component.Haptics.so.23.06.00 ./init.cpp.o ./ForceFeedback.cpp.o ./LCPForceFeedback.cpp.o ./NullForceFeedback.cpp.o ./NullForceFeedbackT.cpp.o -Wl,-rpath,/home/amd/sandeep/sofa/sofa/build/lib: ./libSofa.Component.Constraint.Lagrangian.Solver.so.23.06.00 ./libSofa.Simulation.Core.so.23.06.00 ./libSofa.Core.so.23.06.00 ./libSofa.DefaultType.so.23.06.00 ./libSofa.LinearAlgebra.so.23.06.00 ./libSofa.Helper.so.23.06.00 ./libSofa.Topology.so.23.06.00 ./libSofa.Geometry.so.23.06.00 ./libSofa.Type.so.23.06.00 ./libSofa.Compat.so.23.06.00 ./libSofa.Component.Compat.so.23.06.00 ./libSofa.Config.so.23.06.00** We have attached the object files required to reproduce this issue. Please do let us know the solution. Thanks, [Sofa_Obj.tar.gz](https://github.com/llvm/llvm-project/files/12800919/Sofa_Obj.tar.gz) Sandeep.
DimitryAndric commented 11 months ago

Usually this is because you have a class (in this case sofa::linearalgebra::FullVector) for which there is no object file (aka "translation unit") where its vtable is defined: the term for this is a "vtable anchor".

In most cases it can be solved by putting an out-of-line constructor or destructor definition for such a class in one, and only one, .cpp file.

sandeep-amd commented 11 months ago

In this case, constructor definitions exists in the FullVector.h file.

public:

    FullVector()
        : linearalgebra::BaseVector()
        , data(nullptr), cursize(0), allocsize(0)
    {
    }

    FullVector(const FullVector& vect)
        : linearalgebra::BaseVector()
        , data(nullptr), cursize(0), allocsize(0)
    {
        (*this) = vect;
    }

So, instead you want me to put it in a .cpp file ?

Also, the same code builds perfectly with GCC and AOCC(based on llvm 14) without any code changes.

sandeep-amd commented 11 months ago

Also, tried with the solution i.e putting an out-of-line constructor definition in the FullVector.cpp and just keeping declaration in Fullvector.h. But i still get the same linker issue.

PS: This same code works fine without any changes with AOCC 4.0(based on LLVM 14 compiler).