This is an archive of the discontinued LLVM Phabricator instance.

gn build: Add check-hwasan target.
ClosedPublic

Authored by pcc on Jan 15 2019, 2:03 AM.

Details

Summary

The Android sanitizer tests are currently some of the most difficult
to run correctly, requiring at least 3 build directories which have
to be configured in just the right way and built in the correct order
(see e.g. [1] and the functions that it calls).

This patch adds a check-hwasan target which greatly simplifies running
the hwasan tests for gn users, taking advantage of its support for
multiple toolchains. With this the tests can be run simply by setting
an NDK path and running "ninja check-hwasan" with a compatible Android
device connected. The Linux/x86_64 and Android/aarch64 targets are
tested in parallel.

[1] https://github.com/llvm/llvm-zorg/blob/master/zorg/buildbot/builders/sanitizers/buildbot_android.sh

Diff Detail

Event Timeline

pcc created this revision.Jan 15 2019, 2:03 AM
thakis accepted this revision.Jan 15 2019, 6:13 AM

Nice!!

llvm/utils/gn/secondary/compiler-rt/test/hwasan/BUILD.gn
47

Why do you need the android special case here?

llvm/utils/gn/secondary/compiler-rt/test/test.gni
15

Oooh I guess this would be tricky to do when using GN's config stuff for target flags. Hmm…

This revision is now accepted and ready to land.Jan 15 2019, 6:13 AM
pcc marked an inline comment as done.Jan 15 2019, 2:39 PM
pcc added inline comments.
llvm/utils/gn/secondary/compiler-rt/test/hwasan/BUILD.gn
47

Digging into this more I suppose it's more like a special case for running the tests on the host (I'll adjust the condition here and add a FIXME to make that clear). The reason why it's necessary is that the sanitizer runtime will expect to find llvm-symbolizer in llvm_tools_dir (via $PATH) when running the tests natively because of this code here:
http://llvm-cs.pcc.me.uk/projects/compiler-rt/test/lit.common.cfg#88
The lit code also expects to be able to find other tools like lld-link and llvm-config (and I believe the compiler as well) in the same location, so the way things work now it needs to point to the host toolchain (unless we want to do a two-stage bootstrap just to run the sanitizer tests, which seems like something that we could support but most likely controlled by an is_bootstrap_build type thing in args.gn).

Either way the host toolchain binary isn't going to work on a non-native architecture because the architecture of llvm-config has to match the architecture of the sanitizer. So it seems like we should aim to make native consistent with non-native by always using //llvm/tools/llvm-symbolizer here and adjusting lit to use the stage2 llvm-symbolizer binary in native builds.

This revision was automatically updated to reflect the committed changes.