Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,176 @@
set(ASAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ASAN_TESTSUITES)
set(ASAN_DYNAMIC_TESTSUITES)
# Before Windows 8 (CMAKE_SYSTEM_VERSION 6.2), reserving large regions of shadow
# memory allocated physical memory for page tables, which made it very
# unreliable. Remove the asan tests from check-all in this configuration.
set(SHADOW_MAPPING_UNRELIABLE FALSE)
if(OS_NAME MATCHES "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
${CMAKE_SYSTEM_VERSION} LESS 6.2)
set(SHADOW_MAPPING_UNRELIABLE TRUE)
message(WARNING "Disabling ASan tests because they are unreliable on Windows 7 and earlier")
endif()
if (SHADOW_MAPPING_UNRELIABLE)
set(EXCLUDE_FROM_ALL TRUE)
endif()
macro(get_bits_for_arch arch bits)
if (${arch} MATCHES "i386|arm|mips|mipsel")
set(${bits} 32)
elseif (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|mips64|mips64el|s390x")
set(${bits} 64)
else()
message(FATAL_ERROR "Unknown target architecture: ${arch}")
endif()
endmacro()
set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND ASAN_TEST_DEPS asan)
if(NOT APPLE AND COMPILER_RT_HAS_LLD)
list(APPEND ASAN_TEST_DEPS lld)
endif()
endif()
set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
if(APPLE)
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
endif()
foreach(arch ${ASAN_TEST_ARCH})
if(ANDROID)
set(ASAN_TEST_TARGET_ARCH ${arch}-android)
else()
set(ASAN_TEST_TARGET_ARCH ${arch})
endif()
set(ASAN_TEST_IOS "0")
pythonize_bool(ASAN_TEST_IOS)
set(ASAN_TEST_IOSSIM "0")
pythonize_bool(ASAN_TEST_IOSSIM)
string(TOLOWER "-${arch}-${OS_NAME}" ASAN_TEST_CONFIG_SUFFIX)
get_bits_for_arch(${arch} ASAN_TEST_BITS)
get_test_cc_for_arch(${arch} ASAN_TEST_TARGET_CC ASAN_TEST_TARGET_CFLAGS)
if(ANDROID)
set(ASAN_TEST_DYNAMIC True)
else()
set(ASAN_TEST_DYNAMIC False)
endif()
string(TOUPPER ${arch} ARCH_UPPER_CASE)
set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
)
list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
string(TOLOWER "-${arch}-${OS_NAME}-dynamic" ASAN_TEST_CONFIG_SUFFIX)
set(ASAN_TEST_DYNAMIC True)
set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
list(APPEND ASAN_DYNAMIC_TESTSUITES
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
endif()
endforeach()
# iOS and iOS simulator test suites
# These are not added into "check-all", in order to run these tests, use
# "check-asan-iossim-x86_64" and similar. They also require that an extra env
# variable to select which iOS device or simulator to use, e.g.:
# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
if(APPLE)
set(EXCLUDE_FROM_ALL ON)
set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
set(ASAN_TEST_IOS "1")
pythonize_bool(ASAN_TEST_IOS)
set(ASAN_TEST_DYNAMIC True)
foreach(arch ${DARWIN_iossim_ARCHS})
set(ASAN_TEST_IOSSIM "1")
pythonize_bool(ASAN_TEST_IOSSIM)
set(ASAN_TEST_TARGET_ARCH ${arch})
set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-iossim")
get_bits_for_arch(${arch} ASAN_TEST_BITS)
string(TOUPPER ${arch} ARCH_UPPER_CASE)
set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
)
add_lit_testsuite(check-asan-iossim-${arch} "AddressSanitizer iOS Simulator ${arch} tests"
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
DEPENDS ${ASAN_TEST_DEPS})
endforeach()
foreach (arch ${DARWIN_ios_ARCHS})
set(ASAN_TEST_IOSSIM "0")
pythonize_bool(ASAN_TEST_IOSSIM)
set(ASAN_TEST_TARGET_ARCH ${arch})
set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-ios")
get_bits_for_arch(${arch} ASAN_TEST_BITS)
string(TOUPPER ${arch} ARCH_UPPER_CASE)
set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
)
add_lit_testsuite(check-asan-ios-${arch} "AddressSanitizer iOS ${arch} tests"
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
DEPENDS ${ASAN_TEST_DEPS})
endforeach()
set(EXCLUDE_FROM_ALL OFF)
endif()
# Add unit tests.
if(COMPILER_RT_INCLUDE_TESTS)
set(ASAN_TEST_DYNAMIC False)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
set(ASAN_TEST_DYNAMIC True)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg)
endif()
# FIXME: support unit test in the android test runner
if (NOT ANDROID)
list(APPEND ASAN_TEST_DEPS AsanUnitTests)
list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
list(APPEND ASAN_DYNAMIC_TEST_DEPS AsanDynamicUnitTests)
list(APPEND ASAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
endif()
endif()
endif()
add_lit_testsuite(check-asan "Running the AddressSanitizer tests"
${ASAN_TESTSUITES}
DEPENDS ${ASAN_TEST_DEPS})
set_target_properties(check-asan PROPERTIES FOLDER "Compiler-RT Misc")
if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
add_lit_testsuite(check-asan-dynamic
"Running the AddressSanitizer tests with dynamic runtime"
${ASAN_DYNAMIC_TESTSUITES}
DEPENDS ${ASAN_DYNAMIC_TEST_DEPS})
set_target_properties(check-asan-dynamic
PROPERTIES FOLDER "Compiler-RT Misc")
endif()
# Reset EXCLUDE_FROM_ALL to its initial value.
if (SHADOW_MAPPING_UNRELIABLE)
set(EXCLUDE_FROM_ALL FALSE)
endif()

View File

@@ -0,0 +1,11 @@
def getRoot(config):
if not config.parent:
return config
return getRoot(config.parent)
root = getRoot(config)
if root.android != "1":
config.unsupported = True
config.substitutions.append( ("%device", "/data/local/tmp/Output") )

View File

@@ -0,0 +1,19 @@
// Check that with empty ASAN_OPTIONS, ASan reports on OS X actually crash
// the process (abort_on_error=1). See also Linux/abort_on_error.cc.
// RUN: %clangxx_asan %s -o %t
// Intentionally don't inherit the default ASAN_OPTIONS.
// RUN: env ASAN_OPTIONS="" not --crash %run %t 2>&1 | FileCheck %s
// When we use lit's default ASAN_OPTIONS, we shouldn't crash.
// RUN: not %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: ios
#include <stdlib.h>
int main() {
char *x = (char*)malloc(10 * sizeof(char));
free(x);
return x[5];
// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
}

View File

@@ -0,0 +1,41 @@
// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=368.
// RUN: %clangxx_asan %s -Wno-deprecated-declarations -flat_namespace -bundle -undefined suppress -o %t.bundle
// RUN: %clangxx_asan %s -Wno-deprecated-declarations -o %t -framework Foundation && not %run %t 2>&1 | FileCheck %s
// NSCreateObjectFileImageFromFile/NSLinkModule isn't available on iOS
// UNSUPPORTED: ios
#import <Foundation/Foundation.h>
#import <mach-o/dyld.h>
#include <string>
int main(int argc, char *argv[]) {
for (int i = 0; i < 10; i++) {
NSObjectFileImage im;
std::string path = std::string(argv[0]) + ".bundle";
NSObjectFileImageReturnCode rc =
NSCreateObjectFileImageFromFile(path.c_str(), &im);
if (rc != NSObjectFileImageSuccess) {
fprintf(stderr, "Could not load bundle.\n");
exit(-1);
}
NSModule handle = NSLinkModule(im, "a.bundle", 0);
if (handle == 0) {
fprintf(stderr, "Could not load bundle.\n");
exit(-1);
}
printf("h: %p\n", handle);
}
char *ptr = (char *)malloc(10);
ptr[10] = 'x'; // BOOM
}
// CHECK: AddressSanitizer: heap-buffer-overflow
// CHECK: WRITE of size 1
// CHECK: {{#0 .* in main}}
// CHECK: is located 0 bytes to the right of 10-byte region

View File

@@ -0,0 +1,16 @@
// Make sure __asan_gen_* strings have the correct prefixes on Darwin
// ("L" in __TEXT,__cstring, "l" in __TEXT,__const
// RUN: %clang_asan %s -S -o %t.s
// RUN: cat %t.s | FileCheck %s || exit 1
// UNSUPPORTED: ios
int x, y, z;
int main() { return 0; }
// CHECK: .section{{.*}}__TEXT,__const
// CHECK: l___asan_gen_
// CHECK: .section{{.*}}__TEXT,__cstring,cstring_literals
// CHECK: L___asan_gen_
// CHECK: L___asan_gen_
// CHECK: L___asan_gen_

View File

@@ -0,0 +1,30 @@
// Check that when having a DYLD_ROOT_PATH set, the symbolizer still works.
// RUN: %clangxx_asan -O0 %s -o %t
// RUN: %env_asan_opts=verbosity=2 DYLD_ROOT_PATH="/" ASAN_SYMBOLIZER_PATH=$(which atos) \
// RUN: not %run %t 2>&1 | FileCheck %s
//
// Due to a bug in atos, this only works on x86_64.
// REQUIRES: asan-64-bits
// Path returned by `which atos` is invalid on iOS.
// UNSUPPORTED: ios
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
char *x = (char*)malloc(10 * sizeof(char));
memset(x, 0, 10);
int res = x[argc];
free(x);
free(x + argc - 1); // BOOM
// CHECK: Using atos at user-specified path:
// CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
// CHECK: #0 0x{{.*}} in {{.*}}free
// CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer-dyld-root-path.cc:[[@LINE-4]]
// CHECK: freed by thread T0 here:
// CHECK: #0 0x{{.*}} in {{.*}}free
// CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer-dyld-root-path.cc:[[@LINE-8]]
// CHECK: allocated by thread T0 here:
// CHECK: atos-symbolizer-dyld-root-path.cc:[[@LINE-13]]
return res;
}

View File

@@ -0,0 +1,27 @@
// Check that the `atos` symbolizer works.
// RUN: %clangxx_asan -O0 %s -o %t
// RUN: %env_asan_opts=verbosity=2 ASAN_SYMBOLIZER_PATH=$(which atos) not %run %t 2>&1 | FileCheck %s
// Path returned by `which atos` is invalid on iOS.
// UNSUPPORTED: ios, i386-darwin
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
char *x = (char*)malloc(10 * sizeof(char));
memset(x, 0, 10);
int res = x[argc];
free(x);
free(x + argc - 1); // BOOM
// CHECK: Using atos at user-specified path:
// CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
// CHECK: #0 0x{{.*}} in {{.*}}free
// CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-4]]
// CHECK: freed by thread T0 here:
// CHECK: #0 0x{{.*}} in {{.*}}free
// CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-8]]
// CHECK: allocated by thread T0 here:
// CHECK: atos-symbolizer.cc:[[@LINE-13]]
return res;
}

View File

@@ -0,0 +1,48 @@
// RUN: %clang_asan -O0 %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
// Since ASan is built with -fomit-frame-pointer, backtrace is not able to
// symbolicate the trace past ASan runtime on i386. (This is fixed in
// latest OS X.)
// REQUIRES: asan-64-bits
#include <execinfo.h>
#include <sanitizer/common_interface_defs.h>
#include <stdio.h>
#include <stdlib.h>
void death_function() {
fprintf(stderr, "DEATH CALLBACK\n");
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
fprintf(stderr, "%s\n", strs[i]);
}
free(strs);
fprintf(stderr, "END OF BACKTRACE\n");
}
int fault_function() {
char *x = (char*)malloc(10 * sizeof(char));
free(x);
return x[5]; // BOOM
}
int main() {
__sanitizer_set_death_callback(death_function);
fault_function();
return 0;
}
// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
// CHECK: {{READ of size 1 at 0x.* thread T0}}
// CHECK: {{ #0 0x.* in fault_function}}
// CHECK: DEATH CALLBACK
// CHECK: death_function
// CHECK: fault_function
// CHECK: main
// CHECK: END OF BACKTRACE

View File

@@ -0,0 +1,23 @@
// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=274.
// RUN: %clang_asan %s -framework Foundation -o %t
// RUN: %run %t 2>&1 | FileCheck %s
#import <Foundation/Foundation.h>
#include <stdio.h>
int main() {
NSString* version_file = @"MAJOR=35\n";
int major = 0, minor = 0, build = 0, patch = 0;
NSScanner* scanner = [NSScanner scannerWithString:version_file];
NSString *res = nil;
if ([scanner scanString:@"MAJOR=" intoString:nil] &&
[scanner scanInt:&major]) {
res = [NSString stringWithFormat:@"%d.%d.%d.%d",
major, minor, build, patch];
}
printf("%s\n", [res UTF8String]);
// CHECK: 35.0.0.0
return 0;
}

View File

@@ -0,0 +1,17 @@
// Test that AddressSanitizer moves constant strings into a separate section.
// RUN: %clang_asan -c -o %t %s
// RUN: llvm-objdump -s %t | FileCheck %s
// Check that "Hello.\n" is in __asan_cstring and not in __cstring.
// CHECK: Contents of section __asan_cstring:
// CHECK: 48656c6c {{.*}} Hello.
// CHECK: Contents of section __const:
// CHECK-NOT: 48656c6c {{.*}} Hello.
// CHECK: Contents of section __cstring:
// CHECK-NOT: 48656c6c {{.*}} Hello.
int main(int argc, char *argv[]) {
argv[0] = "Hello.\n";
return 0;
}

View File

@@ -0,0 +1,23 @@
// Test that AddressSanitizer does not re-animate dead globals when dead
// stripping is turned on.
//
// This test verifies that an out-of-bounds access on a global variable is
// detected after dead stripping has been performed. This proves that the
// runtime is able to register globals in the __DATA,__asan_globals section.
// REQUIRES: osx-ld64-live_support
// UNSUPPORTED: ios
// RUN: %clang_asan -mmacosx-version-min=10.11 -Xlinker -dead_strip -o %t %s
// RUN: llvm-nm -format=posix %t | FileCheck --check-prefix NM-CHECK %s
// RUN: not %run %t 2>&1 | FileCheck --check-prefix ASAN-CHECK %s
int alive[1] = {};
int dead[1] = {};
// NM-CHECK: {{^_alive }}
// NM-CHECK-NOT: {{^_dead }}
int main(int argc, char *argv[]) {
alive[argc] = 0;
// ASAN-CHECK: {{0x.* is located 0 bytes to the right of global variable}}
return 0;
}

View File

@@ -0,0 +1,36 @@
// In a non-forking sandbox, we fallback to dladdr(). Test that we provide
// properly demangled C++ names in that case.
// RUN: %clangxx_asan -O0 %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
// RUN: %env_asan_opts=verbosity=2 not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-DLADDR
// sandbox-exec isn't available on iOS
// UNSUPPORTED: ios
#include <stdlib.h>
class MyClass {
public:
int my_function(int n) {
char *x = (char*)malloc(n * sizeof(char));
free(x);
return x[5];
// CHECK-DLADDR: Using dladdr symbolizer
// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
// CHECK: {{READ of size 1 at 0x.* thread T0}}
// CHECK-DLADDR: failed to fork
// CHECK: {{ #0 0x.* in MyClass::my_function\(int\)}}
// CHECK: {{freed by thread T0 here:}}
// CHECK: {{ #0 0x.* in wrap_free}}
// CHECK: {{ #1 0x.* in MyClass::my_function\(int\)}}
// CHECK: {{previously allocated by thread T0 here:}}
// CHECK: {{ #0 0x.* in wrap_malloc}}
// CHECK: {{ #1 0x.* in MyClass::my_function\(int\)}}
}
};
int main() {
MyClass o;
return o.my_function(10);
}

View File

@@ -0,0 +1,26 @@
// Check that ASan dumps the CPU registers on a SIGSEGV.
// RUN: %clangxx_asan %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <stdio.h>
#include <sys/mman.h>
int main() {
fprintf(stderr, "Hello\n");
char *ptr;
ptr = (char *)mmap(NULL, 0x10000, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
assert(ptr && "failed to mmap");
fprintf(stderr, sizeof(uintptr_t) == 8 ? "p = 0x%016lx\n" : "p = 0x%08lx\n", (uintptr_t)ptr);
// CHECK: p = [[ADDR:0x[0-9]+]]
char c = *ptr; // BOOM
// CHECK: ERROR: AddressSanitizer: {{SEGV|BUS}}
// CHECK: Register values:
// CHECK: [[ADDR]]
fprintf(stderr, "World\n");
return c;
}

View File

@@ -0,0 +1,46 @@
// When DYLD-inserting the ASan dylib from a different location than the
// original, make sure we don't try to reexec.
// UNSUPPORTED: ios
// RUN: rm -rf %t && mkdir -p %t
// RUN: cp `%clang_asan -print-file-name=lib`/darwin/libclang_rt.asan_osx_dynamic.dylib \
// RUN: %t/libclang_rt.asan_osx_dynamic.dylib
// RUN: %clangxx_asan %s -o %t/a.out
// RUN: %env_asan_opts=verbosity=1 \
// RUN: DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib \
// RUN: %run %t/a.out 2>&1 \
// RUN: | FileCheck %s
// RUN: IS_OSX_10_11_OR_HIGHER=$([ `sw_vers -productVersion | cut -d'.' -f2` -lt 11 ]; echo $?)
// On OS X 10.10 and lower, if the dylib is not DYLD-inserted, ASan will re-exec.
// RUN: if [ $IS_OSX_10_11_OR_HIGHER == 0 ]; then \
// RUN: %env_asan_opts=verbosity=1 %run %t/a.out 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-NOINSERT %s; \
// RUN: fi
// On OS X 10.11 and higher, we don't need to DYLD-insert anymore, and the interceptors
// still installed correctly. Let's just check that things work and we don't try to re-exec.
// RUN: if [ $IS_OSX_10_11_OR_HIGHER == 1 ]; then \
// RUN: %env_asan_opts=verbosity=1 %run %t/a.out 2>&1 \
// RUN: | FileCheck %s; \
// RUN: fi
#include <stdio.h>
int main() {
printf("Passed\n");
return 0;
}
// CHECK-NOINSERT: exec()-ing the program with
// CHECK-NOINSERT: DYLD_INSERT_LIBRARIES
// CHECK-NOINSERT: to enable wrappers.
// CHECK-NOINSERT: Passed
// CHECK-NOT: exec()-ing the program with
// CHECK-NOT: DYLD_INSERT_LIBRARIES
// CHECK-NOT: to enable wrappers.
// CHECK: Passed

View File

@@ -0,0 +1,45 @@
// Check that when launching with DYLD_INSERT_LIBRARIES, we properly remove
// the ASan dylib from the environment variable (both when using an absolute
// or relative path) and also that the other dylibs are left untouched.
// UNSUPPORTED: ios
// RUN: rm -rf %t && mkdir -p %t
// RUN: cp `%clang_asan -print-file-name=lib`/darwin/libclang_rt.asan_osx_dynamic.dylib \
// RUN: %t/libclang_rt.asan_osx_dynamic.dylib
// RUN: %clangxx_asan %s -o %t/a.out
// RUN: %clangxx -DSHARED_LIB %s \
// RUN: -dynamiclib -o %t/dummy-so.dylib
// RUN: ( cd %t && \
// RUN: DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
// RUN: ( cd %t && \
// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
// RUN: ( cd %t && \
// RUN: %env_asan_opts=strip_env=0 \
// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 ) | FileCheck %s --check-prefix=CHECK-KEEP || exit 1
// RUN: ( cd %t && \
// RUN: DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
#if !defined(SHARED_LIB)
#include <stdio.h>
#include <stdlib.h>
int main() {
const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
printf("%s=%s\n", kEnvName, getenv(kEnvName));
// CHECK: {{DYLD_INSERT_LIBRARIES=dummy-so.dylib}}
// CHECK-KEEP: {{DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib}}
return 0;
}
#else // SHARED_LIB
void foo() {}
#endif // SHARED_LIB

View File

@@ -0,0 +1,12 @@
// Regression test with an empty (length = 0) custom section.
// RUN: %clangxx_asan -g -O0 %s -c -o %t.o
// RUN: %clangxx_asan -g -O0 %t.o -o %t -sectcreate mysegment mysection /dev/null
// RUN: %run %t 2>&1 | FileCheck %s
#include <stdio.h>
int main() {
printf("Hello, world!\n");
// CHECK: Hello, world!
}

View File

@@ -0,0 +1,13 @@
// RUN: %clang_asan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
fclose(NULL);
fprintf(stderr, "Finished.\n");
return 0;
}
// CHECK: Finished.

View File

@@ -0,0 +1,15 @@
// RUN: %clang_asan %s -o %t
// RUN: %run %t 2>&1 | FileCheck %s
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int main(int argc, const char * argv[]) {
getpwnam(NULL);
fprintf(stderr, "Finished.\n");
return 0;
}
// CHECK: Finished.

View File

@@ -0,0 +1,100 @@
// RUN: %clangxx_asan -arch x86_64 -arch x86_64h -g -O0 %s -c -o %t.o.fat
// RUN: %clangxx_asan -arch x86_64 -arch x86_64h -g %t.o.fat -o %t.fat
// RUN: lipo %t.fat -thin x86_64 -output %t.thin.x86_64 && lipo %t.thin.x86_64 -info | FileCheck %s --check-prefix=CHECK-LIPO-THIN-X86_64
// RUN: lipo %t.fat -thin x86_64h -output %t.thin.x86_64h && lipo %t.thin.x86_64h -info | FileCheck %s --check-prefix=CHECK-LIPO-THIN-X86_64H
// RUN: lipo %t.fat -extract x86_64 -output %t.fat.x86_64 && lipo %t.fat.x86_64 -info | FileCheck %s --check-prefix=CHECK-LIPO-FAT-X86_64
// RUN: lipo %t.fat -extract x86_64h -output %t.fat.x86_64h && lipo %t.fat.x86_64h -info | FileCheck %s --check-prefix=CHECK-LIPO-FAT-X86_64H
// CHECK-LIPO-THIN-X86_64: Non-fat file: {{.*}} is architecture: x86_64
// CHECK-LIPO-THIN-X86_64H: Non-fat file: {{.*}} is architecture: x86_64h
// CHECK-LIPO-FAT-X86_64: Architectures in the fat file: {{.*}} are: x86_64
// CHECK-LIPO-FAT-X86_64H: Architectures in the fat file: {{.*}} are: x86_64h
// RUN: dsymutil %t.thin.x86_64
// RUN: dsymutil %t.thin.x86_64h
// RUN: dsymutil %t.fat.x86_64
// RUN: dsymutil %t.fat.x86_64h
// Check LLVM symbolizer
// RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.thin.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.thin.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.fat.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path=$(which llvm-symbolizer) not %run %t.fat.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// Check atos
// RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.thin.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.thin.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.fat.x86_64 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path=$(which atos) not %run %t.fat.x86_64h 2>&1 | FileCheck %s --check-prefixes CHECK,CHECK-LI,CHECK-DATA
// Check dladdr
// RUN: %env_asan_opts=external_symbolizer_path= not %run %t.thin.x86_64 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path= not %run %t.thin.x86_64h 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path= not %run %t.fat.x86_64 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
// RUN: %env_asan_opts=external_symbolizer_path= not %run %t.fat.x86_64h 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-NOLI,CHECK-DATA
// Check asan_symbolize.py with llvm-symbolizer
// RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
// RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64h 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
// RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
// RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64h 2>&1 | %asan_symbolize | FileCheck %s --check-prefixes CHECK,CHECK-LI
// Check asan_symbolize.py with atos
// RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
// RUN: %env_asan_opts=symbolize=0 not %run %t.thin.x86_64h 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
// RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
// RUN: %env_asan_opts=symbolize=0 not %run %t.fat.x86_64h 2>&1 | %asan_symbolize --force-system-symbolizer | FileCheck %s --check-prefixes CHECK,CHECK-LI
// REQUIRES: x86-target-arch
// REQUIRES: x86_64h
// UNSUPPORTED: ios
#include <sanitizer/common_interface_defs.h>
#include <stdio.h>
#include <stdlib.h>
#if __x86_64h__
// Unused functions and globals, just to mess up the offsets in x86_64h.
void dummy(char *a, char *b) {
while (*a == *b) {
a[0] = b[0];
a[1] = b[1];
a[2] = b[2];
a[3] = b[3];
fprintf(stderr, "dummy\n");
}
fprintf(stderr, "dummy\n");
}
long dummy_global;
long dummy_global2[100];
#endif
extern "C"
long faulty_global = 10;
void check_data_symbolication() {
char data[100];
__sanitizer_symbolize_global(&faulty_global, "%g", data, sizeof(data));
fprintf(stderr, "symbolized global: %s\n", data);
// CHECK-DATA: symbolized global: faulty_global
}
extern "C"
void faulty_func(char *p) {
*p = 'x'; // BOOM
// CHECK: AddressSanitizer: global-buffer-overflow
// CHECK-LI: #0 0x{{.*}} in faulty_func{{.*}} {{.*}}haswell-symbolication.cc:[[@LINE-2]]
// CHECK-NOLI: #0 0x{{.*}} in faulty_func{{.*}} {{.*}}haswell-symbolication
// CHECK: is located 2 bytes to the right of global variable 'faulty_global'
// CHECK-NOT: LLVMSymbolizer: error reading file
}
int main() {
check_data_symbolication();
char *p = (char *)(void *)&faulty_global;
p += 10;
faulty_func(p);
return 0;
}

View File

@@ -0,0 +1,36 @@
// Check the presence of interface symbols in the ASan runtime dylib.
// If you're changing this file, please also change
// ../Linux/interface_symbols.c
// RUN: %clangxx_asan -dead_strip -O2 %s -o %t.exe
//
// note: we can not use -D on Darwin.
// RUN: nm -g `%clang_asan %s -fsanitize=address -### 2>&1 | grep "libclang_rt.asan_osx_dynamic.dylib" | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \
// RUN: | grep " [TU] " \
// RUN: | grep -o "\(__asan_\|__ubsan_\|__sancov_\|__sanitizer_\)[^ ]*" \
// RUN: | grep -v "__sanitizer_syscall" \
// RUN: | grep -v "__sanitizer_weak_hook" \
// RUN: | grep -v "__sanitizer_mz" \
// RUN: | grep -v "__sancov_lowest_stack" \
// RUN: | sed -e "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \
// RUN: > %t.exports
//
// RUN: grep -e "INTERFACE_\(WEAK_\)\?FUNCTION" \
// RUN: %p/../../../../lib/asan/asan_interface.inc \
// RUN: %p/../../../../lib/ubsan/ubsan_interface.inc \
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface.inc \
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface_posix.inc \
// RUN: %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc \
// RUN: | grep -v "__sanitizer_weak_hook" \
// RUN: | sed -e "s/.*(//" -e "s/).*//" > %t.imports
//
// RUN: cat %t.imports | sort | uniq > %t.imports-sorted
// RUN: cat %t.exports | sort | uniq > %t.exports-sorted
//
// RUN: echo
// RUN: echo "=== NOTE === If you see a mismatch below, please update sanitizer_interface.inc files."
// RUN: diff %t.imports-sorted %t.exports-sorted
// UNSUPPORTED: ios
int main() { return 0; }

Some files were not shown because too many files have changed in this diff Show More