This is an archive of the discontinued LLVM Phabricator instance.

Fix the cross compilation of unit tests. NFC
ClosedPublic

Authored by sgundapa on Nov 30 2015, 9:12 AM.

Details

Summary

With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling
environment, the unit tests fail to link. This patch does the following changes

  • Rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the way it's used.
  • Add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that cross-compiler would be able to build/compile the unit tests
  • Add COMPILER_RT_UNITTEST_LINKFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that cross-compiler would be able to link the unit tests (if needed)

Diff Detail

Repository
rL LLVM

Event Timeline

sgundapa updated this revision to Diff 41406.Nov 30 2015, 9:12 AM
sgundapa retitled this revision from to Fix the linking of unit tests in lib/asan.
sgundapa updated this object.
sgundapa added reviewers: rengolin, samsonov.
sgundapa added a subscriber: llvm-commits.
samsonov edited edge metadata.Nov 30 2015, 10:48 AM

Out of curiosity, do you need to add ${COMPILER_RT_TEST_COMPILER_CFLAGS} to COMPILER_RT_TEST_CFLAGS as well? Otherwise the name COMPILER_RT_TEST_COMPILER_CFLAGS looks really confusing.

... or should we at least rename COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_TEST_TARGET_CFLAGS ?

At least in this scenario, asan_compile uses "CMAKE_C_FLAGS" and that exposed the issue during the linking. Ideally both compilation and linking use either COMPILER_RT_TEST_COMPILER_CFLAGS . I can push a clean up patch to rename COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_TEST_TARGET_CFLAGS.

Also, what is the difference between COMPILER_RT_TEST_COMPILER_CFLAGS and COMPILER_RT_TEST_CFLAGS ? There seem to be an awe-full lot of similar flags , I believe

sgundapa added a comment.EditedDec 8 2015, 4:27 PM

Ping, on how to proceed

Sorry for delay. I agree, this is way too confusing. So, currently:

  • COMPILER_RT_TEST_COMPILER_CFLAGS is a user-defined CMake variable and is used to compile/link lit-tests (if we're using a cross-compiler)
  • COMPILER_RT_TEST_CFLAGS are used to compile unit tests and is just a variable we construct.

I think the right change would be to:
(a) rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the way it's used.
(b) add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that cross-compiler would be able to build the tests
(c) (if needed) introduce/do smth. similar to COMPILER_RT_UNITTEST_LINKFLAGS if needed.

sgundapa updated this revision to Diff 43755.Dec 29 2015, 1:09 PM
sgundapa retitled this revision from Fix the linking of unit tests in lib/asan to Fix the cross compilation of unit tests. NFC.
sgundapa updated this object.
sgundapa edited edge metadata.
sgundapa updated this object.
sgundapa updated this object.

PING (as I pushed this patch during holiday time and there is a greater chance that this might have been unnoticed)

Right, sorry for delay caused by holidays. I will take a look later this week.

samsonov added inline comments.Jan 8 2016, 4:27 PM
cmake/Modules/AddCompilerRT.cmake
174 ↗(On Diff #43755)

No, please leave COMPILER_RT_GTEST_* variables intact: GTest is the name of unittest framework.

lib/asan/tests/CMakeLists.txt
40 ↗(On Diff #43755)

Why do you need quotes here?

sgundapa added inline comments.Jan 11 2016, 11:38 AM
cmake/Modules/AddCompilerRT.cmake
174 ↗(On Diff #43755)

Ok. I will push a new patch with out any changes to GTEST_*

lib/asan/tests/CMakeLists.txt
40 ↗(On Diff #43755)

I guess, it is generally safe to wrap a variable with quotes which holds a value with spaces/colons. Let me know if you think otherwise.
I am not an expert in CMake

samsonov added inline comments.Jan 11 2016, 4:10 PM
lib/asan/tests/CMakeLists.txt
40 ↗(On Diff #43755)

If COMPILER_RT_UNITTEST_LINKFLAGS is a list (which it's likely is, all other similar varialbes are), then you probably don't want to escape semicolons, which are treated as items delimiters.

sgundapa updated this revision to Diff 44667.Jan 12 2016, 1:37 PM
samsonov accepted this revision.Jan 12 2016, 3:05 PM
samsonov edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jan 12 2016, 3:05 PM
This revision was automatically updated to reflect the committed changes.

This patch was reverted as an empty COMPILER_RT_TEST_COMPILER_CFLAGS is causing the cmake configuration to bail out. Pushed a new patch here: http://reviews.llvm.org/D16165