[compiler-rt] r315922 - [cfi] Test cross-dso CFI on Android.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 11:03:11 PDT 2017
Author: eugenis
Date: Mon Oct 16 11:03:11 2017
New Revision: 315922
URL: http://llvm.org/viewvc/llvm-project?rev=315922&view=rev
Log:
[cfi] Test cross-dso CFI on Android.
Reviewers: vitalybuka, pcc
Subscribers: llvm-commits, srhines
Differential Revision: https://reviews.llvm.org/D38911
Added:
compiler-rt/trunk/test/cfi/cross-dso/util/
compiler-rt/trunk/test/cfi/cross-dso/util/cfi_stubs.h
Modified:
compiler-rt/trunk/test/cfi/cross-dso/lit.local.cfg
compiler-rt/trunk/test/cfi/cross-dso/shadow_is_read_only.cpp
compiler-rt/trunk/test/cfi/cross-dso/stats.cpp
compiler-rt/trunk/test/cfi/lit.cfg
compiler-rt/trunk/test/lit.common.cfg
Modified: compiler-rt/trunk/test/cfi/cross-dso/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/cross-dso/lit.local.cfg?rev=315922&r1=315921&r2=315922&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/cross-dso/lit.local.cfg (original)
+++ compiler-rt/trunk/test/cfi/cross-dso/lit.local.cfg Mon Oct 16 11:03:11 2017
@@ -5,5 +5,9 @@ def getRoot(config):
root = getRoot(config)
-if root.host_os not in ['Linux'] or config.android:
+if root.host_os not in ['Linux']:
+ config.unsupported = True
+
+# Android O (API level 26) has support for cross-dso cfi in libdl.so.
+if config.android and 'android-26' not in config.available_features:
config.unsupported = True
Modified: compiler-rt/trunk/test/cfi/cross-dso/shadow_is_read_only.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/cross-dso/shadow_is_read_only.cpp?rev=315922&r1=315921&r2=315922&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/cross-dso/shadow_is_read_only.cpp (original)
+++ compiler-rt/trunk/test/cfi/cross-dso/shadow_is_read_only.cpp Mon Oct 16 11:03:11 2017
@@ -12,6 +12,9 @@
// Tests that shadow is read-only most of the time.
// REQUIRES: cxxabi
+// Uses private API that is not available on Android.
+// UNSUPPORTED: android
+
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
Modified: compiler-rt/trunk/test/cfi/cross-dso/stats.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/cross-dso/stats.cpp?rev=315922&r1=315921&r2=315922&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/cross-dso/stats.cpp (original)
+++ compiler-rt/trunk/test/cfi/cross-dso/stats.cpp Mon Oct 16 11:03:11 2017
@@ -6,6 +6,9 @@
// CFI-icall is not implemented in thinlto mode => ".cfi" suffixes are missing
// in sanstats output.
+// FIXME: %t.stats must be transferred from device to host for this to work on Android.
+// XFAIL: android
+
struct ABase {};
struct A : ABase {
Added: compiler-rt/trunk/test/cfi/cross-dso/util/cfi_stubs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/cross-dso/util/cfi_stubs.h?rev=315922&view=auto
==============================================================================
--- compiler-rt/trunk/test/cfi/cross-dso/util/cfi_stubs.h (added)
+++ compiler-rt/trunk/test/cfi/cross-dso/util/cfi_stubs.h Mon Oct 16 11:03:11 2017
@@ -0,0 +1,30 @@
+// This is a hack to access CFI interface that Android has in libdl.so on
+// device, but not in the NDK.
+#include <dlfcn.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+typedef void (*cfi_slowpath_ty)(uint64_t, void *);
+typedef void (*cfi_slowpath_diag_ty)(uint64_t, void *, void *);
+
+static cfi_slowpath_ty cfi_slowpath;
+static cfi_slowpath_diag_ty cfi_slowpath_diag;
+
+__attribute__((constructor(0), no_sanitize("cfi"))) static void init() {
+ cfi_slowpath = (cfi_slowpath_ty)dlsym(RTLD_NEXT, "__cfi_slowpath");
+ cfi_slowpath_diag =
+ (cfi_slowpath_diag_ty)dlsym(RTLD_NEXT, "__cfi_slowpath_diag");
+ if (!cfi_slowpath || !cfi_slowpath_diag) abort();
+}
+
+extern "C" {
+__attribute__((visibility("hidden"), no_sanitize("cfi"))) void __cfi_slowpath(
+ uint64_t Type, void *Addr) {
+ cfi_slowpath(Type, Addr);
+}
+
+__attribute__((visibility("hidden"), no_sanitize("cfi"))) void
+__cfi_slowpath_diag(uint64_t Type, void *Addr, void *Diag) {
+ cfi_slowpath_diag(Type, Addr, Diag);
+}
+}
Modified: compiler-rt/trunk/test/cfi/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/lit.cfg?rev=315922&r1=315921&r2=315922&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/lit.cfg (original)
+++ compiler-rt/trunk/test/cfi/lit.cfg Mon Oct 16 11:03:11 2017
@@ -24,6 +24,8 @@ if config.lto_supported:
diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi '
non_dso = '-fvisibility=hidden '
dso = '-fsanitize-cfi-cross-dso -fvisibility=default '
+ if config.android:
+ dso += '-include ' + config.test_source_root + '/cross-dso/util/cfi_stubs.h '
config.substitutions.append((r"%clang_cfi ", clang_cfi + non_dso))
config.substitutions.append((r"%clangxx_cfi ", clang_cfi + cxx + non_dso))
config.substitutions.append((r"%clang_cfi_diag ", clang_cfi + non_dso + diag))
@@ -33,5 +35,8 @@ if config.lto_supported:
else:
config.unsupported = True
+if config.default_sanitizer_opts:
+ config.environment['UBSAN_OPTIONS'] = ':'.join(config.default_sanitizer_opts)
+
if lit_config.params.get('check_supported', None) and config.unsupported:
raise BaseException("Tests unsupported")
Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=315922&r1=315921&r2=315922&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Mon Oct 16 11:03:11 2017
@@ -201,6 +201,19 @@ if config.host_os == 'Darwin':
else:
config.substitutions.append( ("%macos_min_target_10_11", "") )
+if config.android:
+ adb = os.environ.get('ADB', 'adb')
+ try:
+ android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"]).rstrip()
+ except (subprocess.CalledProcessError, OSError):
+ lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb)" % adb)
+ try:
+ android_api_level = int(android_api_level_str)
+ except ValueError:
+ lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb): got '%s'" % (adb, android_api_level_str))
+ if android_api_level >= 26:
+ config.available_features.add('android-26')
+
sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
if os.path.exists(sancovcc_path):
config.available_features.add("has_sancovcc")
More information about the llvm-commits
mailing list