[cfi] Test cross-dso CFI on Android.
Reviewers: vitalybuka, pcc Subscribers: llvm-commits, srhines Differential Revision: https://reviews.llvm.org/D38911 llvm-svn: 315922
This commit is contained in:
		
							parent
							
								
									d5d36a162d
								
							
						
					
					
						commit
						1993de54ee
					
				| 
						 | 
					@ -5,5 +5,9 @@ def getRoot(config):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
root = 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
 | 
					  config.unsupported = True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,9 @@
 | 
				
			||||||
// Tests that shadow is read-only most of the time.
 | 
					// Tests that shadow is read-only most of the time.
 | 
				
			||||||
// REQUIRES: cxxabi
 | 
					// REQUIRES: cxxabi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Uses private API that is not available on Android.
 | 
				
			||||||
 | 
					// UNSUPPORTED: android
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <dlfcn.h>
 | 
					#include <dlfcn.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,9 @@
 | 
				
			||||||
// CFI-icall is not implemented in thinlto mode => ".cfi" suffixes are missing
 | 
					// CFI-icall is not implemented in thinlto mode => ".cfi" suffixes are missing
 | 
				
			||||||
// in sanstats output.
 | 
					// in sanstats output.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FIXME: %t.stats must be transferred from device to host for this to work on Android.
 | 
				
			||||||
 | 
					// XFAIL: android
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ABase {};
 | 
					struct ABase {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct A : ABase {
 | 
					struct A : ABase {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,8 @@ if config.lto_supported:
 | 
				
			||||||
  diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi '
 | 
					  diag = '-fno-sanitize-trap=cfi -fsanitize-recover=cfi '
 | 
				
			||||||
  non_dso = '-fvisibility=hidden '
 | 
					  non_dso = '-fvisibility=hidden '
 | 
				
			||||||
  dso = '-fsanitize-cfi-cross-dso -fvisibility=default '
 | 
					  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"%clang_cfi ", clang_cfi + non_dso))
 | 
				
			||||||
  config.substitutions.append((r"%clangxx_cfi ", clang_cfi + cxx + 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))
 | 
					  config.substitutions.append((r"%clang_cfi_diag ", clang_cfi + non_dso + diag))
 | 
				
			||||||
| 
						 | 
					@ -33,5 +35,8 @@ if config.lto_supported:
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
  config.unsupported = True
 | 
					  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:
 | 
					if lit_config.params.get('check_supported', None) and config.unsupported:
 | 
				
			||||||
  raise BaseException("Tests unsupported")
 | 
					  raise BaseException("Tests unsupported")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -201,6 +201,19 @@ if config.host_os == 'Darwin':
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
  config.substitutions.append( ("%macos_min_target_10_11", "") )
 | 
					  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")
 | 
					sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
 | 
				
			||||||
if os.path.exists(sancovcc_path):
 | 
					if os.path.exists(sancovcc_path):
 | 
				
			||||||
  config.available_features.add("has_sancovcc")
 | 
					  config.available_features.add("has_sancovcc")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue