This is an archive of the discontinued LLVM Phabricator instance.

Adapt "cross compile?" check for Apple Silicon
ClosedPublic

Authored by yln on Apr 12 2022, 2:06 PM.

Details

Summary

This piece of code tries to implement the semantics "cross compile?" to
determine CFLAGS used for test binary compilation.

if(ANDROID OR ${arch} MATCHES "arm|aarch64|riscv32|riscv64")

Since Apple Silicon, macOS runs on arm64e, so we take the wrong branch
when compiling and running tests locally "on the host" on an AS machine.

Furthermore, for Apple code, we use the separate
get_test_cflags_for_apple_platform function to determine these test
compiliation flags and get_test_cc_for_arch is only ever used in the
"compile & run on host" case, so we can short-curcuit the "cross
compile?" check here.

rdar://91446703

Diff Detail

Event Timeline

yln created this revision.Apr 12 2022, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2022, 2:06 PM
yln requested review of this revision.Apr 12 2022, 2:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2022, 2:06 PM
Herald added subscribers: Restricted Project, pcwang-thead. · View Herald Transcript
yln added a comment.Apr 12 2022, 2:07 PM

@thetruestblue please verify that this fixes the problem you saw on your AS machine.

arichardson added inline comments.Apr 12 2022, 3:47 PM
compiler-rt/cmake/config-ix.cmake
247

Could this use if(CMAKE_CROSSCOMPILING) instead?

yln added inline comments.Apr 12 2022, 7:42 PM
compiler-rt/cmake/config-ix.cmake
247

That certainly looks like a promising option. Note that we are determining the build flags for compiling tests in compiler-rt here and multiple targets are usually generated.

It seems to work for Darwin (CMAKE_CROSSCOMPILING always being false there), but I am hesitant to change this without being able to test it for other platforms.

Should we do something like this to issue warnings for a while before switching over?

+  if(ANDROID OR (NOT APPLE AND ${arch} MATCHES "arm|aarch64|riscv32|riscv64"))
+    if(NOT CMAKE_CROSSCOMPILING)
+      set(cc_mismatch TRUE)
+    endif()
+  else()
+    if(CMAKE_CROSSCOMPILING)
+      set(cc_mismatch TRUE)
+    endif()
+  endif()
+  if (cc_mismatch)
+    message(WARNING "compiler-rt test CFLAGS cross-compilation detection does not match CMAKE_CROSSCOMPILING.  "
+                    "Please go to https://reviews.llvm.org/D123633 and let us know when this happens.")
+  endif()

@thetruestblue please verify that this fixes the problem you saw on your AS machine.

This fixes tsan tests on AS.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 13 2022, 3:26 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.