AvtechScientific / ASL

Advanced Simulation Library - hardware accelerated multiphysics simulation platform.
http://asl.org.il
GNU Affero General Public License v3.0
217 stars 55 forks source link

tests linking fails when LDFLAGS contain "-Wl,--as-needed" #11

Closed bircoph closed 9 years ago

bircoph commented 9 years ago

Hi,

with --as-needed in LDFLAGS (default it Gentoo) tests fail to link:

cd /var/tmp/portage/sci-libs/asl-0.1.5-r1/work/asl-0.1.5_build/test/testACL && /usr/bin/cmake -E cmake_link_script CMakeFiles/testMatrixOfElements.dir/link.txt --verbose=1
/usr/lib64/ccache/bin/x86_64-pc-linux-gnu-g++   -O2 -pipe  -fpermissive  -Wno-deprecated   -Wl,--as-needed  CMakeFiles/testMatrixOfElements.dir/testMatrixOfElements.cc.o  -o testMatrixOfElements -rdynamic ../../src/libasl.so.0.1.5 ../../src/acl/libaslacl.so.0.1.5 ../../src/acl/Operators/libaslacloperators.so.0.1.5 ../../src/acl/aclMath/libaslaclmath.so.0.1.5 -lOpenCL ../../src/math/libaslmath.so.0.1.5 ../../src/data/libasldata.so.0.1.5 ../../src/libaslcommon.so.0.1.5
../../src/math/libaslmath.so.0.1.5: undefined reference to `asl::generateDataContainer_SP(asl::Block const&, acl::VectorOfElements const&, unsigned int)'
../../src/math/libaslmath.so.0.1.5: undefined reference to `asl::offset(asl::Block const&, int)'
collect2: error: ld returned 1 exit status
test/testACL/CMakeFiles/testMatrixOfElements.dir/build.make:102: recipe for target 'test/testACL/testMatrixOfElements' failed

This happens due to incorrect order of library arguments: libasl.so.0.1.5 should follow libaslmath.so.0.1.5 because libaslmath uses symbols from libasl.

On the other hand testACL/CMakeLists.txt contains:

target_link_libraries(testMatrixOfElements aslacl aslmath asldata asl)

which looks valid (asl is the last library on the list).

This problem starts with >=cmake-3.1.0: for 3.0.2 such problem is not reproducible, for 3.1.0 and later versions it takes place. Current version of cmake used for the build is 3.3.0.

Full build log is available here: https://bpaste.net/show/56abb9c2f641

ghisvail commented 9 years ago

Same thing happening on up-to-date Debian Testing using CMake 3.2.2.

Nicely spotted @bircoph !

ghisvail commented 9 years ago

As a temporary fix, I commented out the non-building test and the rest of the testsuite builds successfully. Unfortunately, neither make test nor ctest seems to be doing anything.

EDIT: typo

bircoph commented 9 years ago

Unfortunately, neither make test nor ctest seems to be doing anything.

This happens when running from the top build directory.

cd test && ctest

works.

@AvtechScientific, it will be nice to have top-level CTestTestfile.cmake which includes test/CTestTestfile.cmake (or test subdirectory).

AvtechScientific commented 9 years ago

We look for a newer system to reproduce the errors, in the meanwhile, could you, please, check whether swapping aslmath and asldata helps:

target_link_libraries(testMatrixOfElements aslacl asldata aslmath asl)

bircoph commented 9 years ago

target_link_libraries(testMatrixOfElements aslacl asldata aslmath asl)

It still fails to build:

FAILED: : && /usr/lib64/ccache/bin/x86_64-pc-linux-gnu-g++   -march=native -O2 -funswitch-loops -fpredictive-commoning -ftree-vectorize -ftree-slp-vectorize -fvect-cost-model  -fgcse-after-reload -ftree-partial-pre -ftree-loop-im -fweb -frename-registers -fomit-frame-pointer -fexcess-precision=fast -pipe -frecord-gcc-switches -fno-stack-protector -fvisibility-inlines-hidden  -fpermissive  -Wno-deprecated  -march=native -O2 -funswitch-loops -fpredictive-commoning -pipe -Wl,-O1,--as-needed,--sort-common,-z,combreloc,-z,relro,-z,now,--relax,--hash-style=gnu test/testACL/CMakeFiles/testMatrixOfElements.dir/testMatrixOfElements.cc.o  -o test/testACL/testMatrixOfElements  -rdynamic src/libasl.so.0.1.5 src/acl/libaslacl.so.0.1.5 src/acl/Operators/libaslacloperators.so.0.1.5 src/acl/aclMath/libaslaclmath.so.0.1.5 -lOpenCL src/data/libasldata.so.0.1.5 src/math/libaslmath.so.0.1.5 src/libaslcommon.so.0.1.5 && :
src/math/libaslmath.so.0.1.5: undefined reference to `asl::generateDataContainer_SP(asl::Block const&, acl::VectorOfElements const&, unsigned int)'
src/math/libaslmath.so.0.1.5: undefined reference to `asl::offset(asl::Block const&, int)'
collect2: error: ld returned 1 exit status

Please note that if in the build command one moves "src/libasl.so.0.1.5" to the end of the list, build is fine. Now the question is how to move it there, because it is already on the end of the list in test/testACL/CMakeLists.txt. I have no idea what and why moves it around during cmake run.

ghisvail commented 9 years ago

@bircoph Most ASL binaries are quite underlinked (see #13), which is likely to be the source of the missing references.

bircoph commented 9 years ago

Current git head fixes this for me.