This patch fixes cross-architecture compilation,
by allowing flags like -target and --sysroot to be set for
architecture testing and compilation.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
You shouldn't need to do this. CMAKE_${LANG}_FLAGS is implicitly read by CMake when constructing the compiler command line.
-Chris
It looks to me like CMAKE_CXX_FLAGS is applied explicitly in add_compiler_rt_object_libraries, which makes me think that we do need to add them explicitly:
foreach(libname ${libnames}) add_library(${libname} OBJECT ${LIB_SOURCES}) set_target_compile_flags(${libname} ${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS})
This is not true for add_compiler_rt_runtime. If I set CMAKE_CXX_FLAGS and CMAKE_C_FLAGS without this patch, the flags passed do not end up in the compile commands when building the builtins.
Why not do the same as add_compiler_rt_object_libraries and do this in add_compiler_rt_runtime?
add_compiler_rt_runtime is used to build both c and c++ sources, depending on the object being built. In addition, the other objects using this function already add SANITIZER_COMMON_CFLAGS, which contains the necessary compilation flags (added via check_c[xx]_compiler_flags). The builtins are the only object which are built without the SANITIZER_COMMON_CFLAGS, and therefore don't have any of the user-specified compilation flags.
SANITIZER_COMMON_CFLAGS are strictly for the sanitizers. Why not have a builtins equivalent? Im trying to understand why the builtins and sanitizers are being treated differently in handling of the flags.
I could add a builtins equivalent, if that seems like a better approach. It's a non-trivial diff though.
After further investigation, I think the patch in its current form is still the best solution.
The sanitizers add CMAKE_CXX_FLAGS, inside of add_compiler_rt_object_libraries. The builtins, which are C sources, require an analagous addition of CMAKE_C_FLAGS.
However, because of the shared usage of add_compiler_rt_runtime to compile non-C objects, the flags cannot be added in that function.
That makes the current location the most correct location to add the flags.