This is an archive of the discontinued LLVM Phabricator instance.

light up UBSan for ARMv7
ClosedPublic

Authored by garious on May 15 2014, 2:56 PM.

Details

Summary

You can expect UBSan to be built under any of the following conditions:

1) CMAKE_C_COMPILER is GCC built to cross-compile to ARM
2) CMAKE_C_COMPILER is Clang built to cross-compile to ARM (ARM is default target)
3) CMAKE_C_COMPILER is Clang and CMAKE_C_FLAGS contains -target and --sysroot

Diff Detail

Repository
rL LLVM

Event Timeline

garious updated this revision to Diff 9458.May 15 2014, 2:56 PM
garious retitled this revision from to light up UBSan for ARMv7.
garious updated this object.
garious edited the test plan for this revision. (Show Details)
garious added reviewers: samsonov, eugenis, kcc.
garious added a subscriber: Unknown Object (MLST).
rsmith added inline comments.May 22 2014, 6:07 PM
CMakeLists.txt
219 ↗(On Diff #9458)

I don't understand what this change is doing: we don't want to run ARM tests if the native arch isn't ARM.

rengolin added inline comments.
CMakeLists.txt
219 ↗(On Diff #9458)

yeah, it does look odd...

CMakeLists.txt
219 ↗(On Diff #9458)

The macro checks if CMAKE_C_COMPILER can target a particular architecture. If successful, it the build will generate a compiler-rt runtime with an ${arch} suffix.

Before this patch, we could only compile for ARM from a toolchain running on an ARM processor. With this patch, we can cross-compile if the combination "-march=armv7", CMAKE_C_COMPILER and CMAKE_CXX_FLAGS successfully links.

From the X86 build, this patch does nothing. From an ARM-only build, it generates only ARM runtime libraries.

Some examples:

Combinations that cause the ARM runtimes to be generated:
arm-linux-gnueabi-g++ -march=armv7 simple.cc
clang++ -march=armv7 -target arm-linux-gnueabi --sysroot=... -B... simple.cc

Combinations that do nothing:
Bad flag on X86: g++ -march=armv7 simple.cc
Wrong sysroot on X86: clang++ -march=armv7 simple.cc
Arch mismatch: aarch64-linux-gnu-g++ -march=armv7 simple.cc

Right, I hadn't seen that. When using Phab, it's always good to do the diff -U99, so that you can get a larger context surrounding your code, so that we can easily see that it was inside an IF that was ARM specific. :)

garious updated this revision to Diff 9845.May 27 2014, 1:02 PM
garious added reviewers: rengolin, ygorshenin.
garious removed a subscriber: rengolin.

Extended this patch to include AArch64 and other compiler-rt libs that build on ARM.

Note that ASan does not include AArch64. Build error:

Objects of target "RTLSanCommon.aarch64" referenced but no such target exists.

Also, exactly half the UBSan test suite passes on AArch64. The other half depends on ASan being built.

garious updated this revision to Diff 9847.May 27 2014, 2:29 PM

This fixes the caveats from the last version. UBSan now only tests in conjunction with ASan if ASan is supported. All ubsan, sanitizer_common and profile tests now pass on both armv7 and armv8.

ASan for AArch64 is not included because, although the library builds successfully and tests can be run (via qemu), the ASan runtime fails to initialize.

Any objections? This patch only affects ARM builds.

samsonov edited edge metadata.May 28 2014, 5:28 PM

I'm OK with this change if it doesn't break arm-android.

eugenis edited edge metadata.May 29 2014, 2:47 AM

I don't think it will break android, but with cmake one never knows for sure.

garious closed this revision.May 29 2014, 12:09 PM
garious updated this revision to Diff 9927.

Closed by commit rL209835 (authored by @garious).