This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Don't require c++ headers when configuring compiler-rt builds
ClosedPublic

Authored by fjricci on Jul 18 2016, 11:17 AM.

Diff Detail

Event Timeline

fjricci updated this revision to Diff 64354.Jul 18 2016, 11:17 AM
fjricci retitled this revision from to [compiler-rt] Don't require c++ headers when configuring compiler-rt builds.
fjricci updated this object.
fjricci added reviewers: samsonov, beanz, compnerd.
fjricci added a subscriber: llvm-commits.
compnerd added inline comments.Jul 18 2016, 11:21 AM
cmake/config-ix.cmake
96

Please include a symbol that requires linkage. How about printf?

fjricci updated this revision to Diff 64372.Jul 18 2016, 1:20 PM

Add 'printf' call to simple source file

fjricci updated this revision to Diff 64382.Jul 18 2016, 2:14 PM

Fix syntax error

compnerd edited edge metadata.Jul 18 2016, 3:46 PM

LGTM, would be nice to have @beanz sign off on it as well.

compnerd accepted this revision.Jul 20 2016, 11:15 AM
compnerd edited edge metadata.
This revision is now accepted and ready to land.Jul 20 2016, 11:15 AM
This revision was automatically updated to reflect the committed changes.
beanz edited edge metadata.Jul 25 2016, 11:22 AM

Sorry for being late to this change. I was on vacation last week.

My only concern about this is that compiler-rt's tests do use C++, but that probably isn't a big enough deal to matter. We can deal with that if it ever comes up.

Sorry for being late to this change. I was on vacation last week.

My only concern about this is that compiler-rt's tests do use C++, but that probably isn't a big enough deal to matter. We can deal with that if it ever comes up.

Actually the sanitizers are using C++ while builtins only rely on C. I'm currently running into this because I'm only building libc++ for 64 bits and it tries to build sanitizers for 32 bit which obviously does not work

@Hahnfeld, I thought that while the sanitizers are written in C++ they don't actually use libcxx.

-Chris

@Hahnfeld, I thought that while the sanitizers are written in C++ they don't actually use libcxx.

-Chris

They may not, I don't know. But clang tries to link because no -nostdlib is provided

@Hahnfeld, I thought that while the sanitizers are written in C++ they don't actually use libcxx.

-Chris

They may not, I don't know. But clang tries to link because no -nostdlib is provided

The solution seems to be that simple: I posted D23005 which solves the problem for me.

Back to this revision: I think we should check that we actually have a C++ compiler (maybe without C++ headers and library), but not only a C compiler. Otherwise I think the sanitizers will definitely not build...

beanz added a comment.Aug 1 2016, 11:09 AM

@Hahnfeld, agreed with one caveat. We should actually have two versions of the test. In config-ix.cmake we should have the source be a C++ file that does not rely on libcxx headers, and in builtin-config-ix.cmake, we should have the source be C only, because the builtin libraries do not use C++ at all.

@Hahnfeld, agreed with one caveat. We should actually have two versions of the test. In config-ix.cmake we should have the source be a C++ file that does not rely on libcxx headers, and in builtin-config-ix.cmake, we should have the source be C only, because the builtin libraries do not use C++ at all.

Yep, and it looks like this is already implemented: builtin-config-ix.cmake sets TEST_COMPILE_ONLY and therefore only calls try_compile_only which produces its own SIMPLE_C.

That said, config-ix.cmake is only included from the top directory and not from lib/builtins (only base-config-ix.cmake and builtin-config-ix.cmake are).
So we should just rename back SIMPLE_SOURCE to simple.cc which makes it compile with a C++ compiler. @fjricci is that acceptable for you?

I don't think that would work for all cross-compilation scenarios. Using C++ introduces a dependency on libunwind for ARM targets unless we pass in -fno-exceptions and -fno-unwind-tables to the compilation test.

I don't think that would work for all cross-compilation scenarios. Using C++ introduces a dependency on libunwind for ARM targets unless we pass in -fno-exceptions and -fno-unwind-tables to the compilation test.

Hmm, so you also don't build the sanitizers?

beanz added a comment.Aug 4 2016, 9:38 AM

@compnerd,

If you're doing a cross-compile bootstrap you need to build the builtins using lib/builtins as the top-level source directory in order to skip the sanitizer configuration completely. If you're configuring the sanitizers we need the tests to use C++.

-Chris

@beanz but we do have a bunch of C++ tests that fail miserably due to the libunwind being needed.

beanz added a comment.Aug 4 2016, 1:49 PM

@compnerd, which tests? I suspect that is a different problem. Several of the sanitizers require libunwind in order to build. If you're seeing test failures it likely means that the tests requiring libunwind aren't properly gated.

@compnerd I'm by now a bit lost: How do you compile the sanitizers without a working C++ compiler? They really do need the headers and a linkable library (I tried to add -nostdlib in D23005 but the bots didn't like it)

Or do you pass COMPILER_RT_BUILD_SANITIZERS=Off? I think this will currently not disable the sanitizer tests, maybe this needs to be fixed?
Anyway, could you try directly configuring lib/builtins as Chris suggested? This will only test for a C compiler as I pointed out above.