This is an archive of the discontinued LLVM Phabricator instance.

Enable cross-compilation across architectures on android
ClosedPublic

Authored by fjricci on Jul 15 2016, 10:40 AM.

Details

Summary

This patch fixes cross-architecture compilation,
by allowing flags like -target and --sysroot to be set for
architecture testing and compilation.

Diff Detail

Repository
rL LLVM

Event Timeline

fjricci updated this revision to Diff 64163.Jul 15 2016, 10:40 AM
fjricci retitled this revision from to Enable cross-compilation across architectures on android.
fjricci updated this object.
fjricci added a subscriber: llvm-commits.
fjricci updated this revision to Diff 64164.Jul 15 2016, 10:43 AM

Fix CMAKE_C_FLAG spelling

fjricci updated this revision to Diff 64165.Jul 15 2016, 10:48 AM

Fix whitespace

beanz edited edge metadata.Jul 15 2016, 10:56 AM

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.

compnerd edited edge metadata.Jul 20 2016, 11:16 AM

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.

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