Skip to content

Commit

Permalink
Merged master:e0dc3dba3bd1 into amd-gfx:ae92c01db53a
Browse files Browse the repository at this point in the history
Local branch amd-gfx ae92c01 Merged master:3a6bfcf2f902 into amd-gfx:664c2001cf10
Remote branch master e0dc3db [mlir][Linalg] NFC - Cleanup explicitly instantiated paterns 1/n - LinalgToStandard.cpp
  • Loading branch information
Sw authored and Sw committed Oct 9, 2020
2 parents ae92c01 + e0dc3db commit 02a8883
Show file tree
Hide file tree
Showing 60 changed files with 2,551 additions and 617 deletions.
9 changes: 9 additions & 0 deletions clang/test/CodeGen/debug-info-block-expr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
// Verify that the desired DIExpression are generated for blocks.

void test() {
// CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
__block int i;
// CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
^ { i = 1; }();
}
2 changes: 1 addition & 1 deletion compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ else()
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
OS_NAME MATCHES "Darwin|Linux|NetBSD|Fuchsia")
OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|Fuchsia")
set(COMPILER_RT_HAS_LSAN TRUE)
else()
set(COMPILER_RT_HAS_LSAN FALSE)
Expand Down
6 changes: 5 additions & 1 deletion compiler-rt/lib/asan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ append_rtti_flag(OFF ASAN_CFLAGS)
set(ASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})

if(ANDROID)
list(APPEND ASAN_CFLAGS -fno-emulated-tls)
list(APPEND ASAN_DYNAMIC_LINK_FLAGS -fuse-ld=lld)
# Put most Sanitizer shared libraries in the global group. For more details, see
# android-changes-for-ndk-developers.md#changes-to-library-search-order
if (COMPILER_RT_HAS_Z_GLOBAL)
Expand Down Expand Up @@ -232,7 +234,9 @@ else()
-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers)
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
# but requires a special option to enable it.
if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
# This is used/compatible with ANDROID because we force `lld` on ANDROID (line 90).
# Therefore we don't want to add it for ANDROID.
if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT AND NOT ANDROID)
list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
endif()
set_property(SOURCE
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/asan/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ if(APPLE)
endif()
if(ANDROID)
list(APPEND ASAN_UNITTEST_COMMON_LINK_FLAGS -pie)
list(APPEND ASAN_UNITTEST_COMMON_LINK_FLAGS -fuse-ld=lld)
endif()

set(ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS
Expand Down Expand Up @@ -288,6 +289,7 @@ if(ANDROID)
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
$<TARGET_OBJECTS:RTLSanCommon.${arch}>
$<TARGET_OBJECTS:RTUbsan.${arch}>
$<TARGET_OBJECTS:RTUbsan_cxx.${arch}>
${COMPILER_RT_GTEST_SOURCE}
Expand Down
9 changes: 8 additions & 1 deletion compiler-rt/lib/lsan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include_directories(..)

set(LSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
set(LSAN_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
append_rtti_flag(OFF LSAN_CFLAGS)

set(LSAN_COMMON_SOURCES
Expand Down Expand Up @@ -33,6 +34,11 @@ set(LSAN_HEADERS

set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})

if(ANDROID)
list(APPEND LSAN_CFLAGS -fno-emulated-tls)
list(APPEND LSAN_LINK_FLAGS -fuse-ld=lld)
endif()

add_compiler_rt_object_libraries(RTLSanCommon
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${LSAN_COMMON_SUPPORTED_ARCH}
Expand Down Expand Up @@ -61,7 +67,7 @@ if(COMPILER_RT_HAS_LSAN)
RTSanitizerCommonCoverage
RTSanitizerCommonSymbolizer
CFLAGS ${LSAN_CFLAGS}
LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
LINK_FLAGS ${LSAN_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
LINK_LIBS ${LSAN_LINK_LIBS}
PARENT_TARGET lsan)
else()
Expand All @@ -78,6 +84,7 @@ if(COMPILER_RT_HAS_LSAN)
$<TARGET_OBJECTS:RTLSanCommon.${arch}>
ADDITIONAL_HEADERS ${LSAN_HEADERS}
CFLAGS ${LSAN_CFLAGS}
LINK_FLAGS ${LSAN_LINK_FLAGS}
PARENT_TARGET lsan)
endforeach()
endif()
Expand Down
43 changes: 34 additions & 9 deletions compiler-rt/lib/lsan/lsan_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ static const char kSuppressionLeak[] = "leak";
static const char *kSuppressionTypes[] = { kSuppressionLeak };
static const char kStdSuppressions[] =
#if SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT
// For more details refer to the SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT
// definition.
"leak:*pthread_exit*\n"
// For more details refer to the SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT
// definition.
"leak:*pthread_exit*\n"
#endif // SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT
#if SANITIZER_MAC
// For Darwin and os_log/os_trace: https://reviews.llvm.org/D35173
"leak:*_os_trace*\n"
// For Darwin and os_log/os_trace: https://reviews.llvm.org/D35173
"leak:*_os_trace*\n"
#endif
// TLS leak in some glibc versions, described in
// https://sourceware.org/bugzilla/show_bug.cgi?id=12650.
"leak:*tls_get_addr*\n";
// TLS leak in some glibc versions, described in
// https://sourceware.org/bugzilla/show_bug.cgi?id=12650.
"leak:*tls_get_addr*\n";

void InitializeSuppressions() {
CHECK_EQ(nullptr, suppression_ctx);
Expand Down Expand Up @@ -294,6 +294,22 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
kReachable);
}
}
#if SANITIZER_ANDROID
if (HAS_ANDROID_THREAD_PROPERTIES_API) {
auto *cb = +[](void *dtls_begin, void *dtls_end, uptr /*dso_idd*/,
void *arg) -> void {
ScanRangeForPointers(reinterpret_cast<uptr>(dtls_begin),
reinterpret_cast<uptr>(dtls_end),
reinterpret_cast<Frontier *>(arg), "DTLS",
kReachable);
};

// FIXME: There might be a race-condition here (and in Bionic) if the
// thread is suspended in the middle of updating its DTLS. IOWs, we
// could scan already freed memory. (probably fine for now)
__libc_iterate_dynamic_tls(os_id, cb, frontier);
}
#else
if (dtls && !DTLSInDestruction(dtls)) {
for (uptr j = 0; j < dtls->dtv_size; ++j) {
uptr dtls_beg = dtls->dtv[j].beg;
Expand All @@ -309,6 +325,7 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
// this and continue.
LOG_THREADS("Thread %d has DTLS under destruction.\n", os_id);
}
#endif
}
}
}
Expand Down Expand Up @@ -575,8 +592,16 @@ static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads,
}

static bool CheckForLeaks() {
#if SANITIZER_ANDROID
// Presence of the ThreadProperties API implies the presence of
// TLS support, which is required for calling __lsan_is_turned_off().
// Therefore, this check must preceed that.
if (!HAS_ANDROID_THREAD_PROPERTIES_API)
return false;
#endif

if (&__lsan_is_turned_off && __lsan_is_turned_off())
return false;
return false;
EnsureMainThreadIDIsCorrect();
CheckForLeaksParam param;
LockStuffAndStopTheWorld(CheckForLeaksCallback, &param);
Expand Down
9 changes: 3 additions & 6 deletions compiler-rt/lib/lsan/lsan_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@
// To enable LeakSanitizer on a new architecture, one needs to implement the
// internal_clone function as well as (probably) adjust the TLS machinery for
// the new architecture inside the sanitizer library.
#if (SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC) && \
(SANITIZER_WORDSIZE == 64) && \
#if (SANITIZER_LINUX || SANITIZER_MAC) && (SANITIZER_WORDSIZE == 64) && \
(defined(__x86_64__) || defined(__mips64) || defined(__aarch64__) || \
defined(__powerpc64__) || defined(__s390x__))
#define CAN_SANITIZE_LEAKS 1
#elif defined(__i386__) && \
(SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC)
#elif defined(__i386__) && (SANITIZER_LINUX || SANITIZER_MAC)
#define CAN_SANITIZE_LEAKS 1
#elif defined(__arm__) && \
SANITIZER_LINUX && !SANITIZER_ANDROID
#elif defined(__arm__) && SANITIZER_LINUX
#define CAN_SANITIZE_LEAKS 1
#elif SANITIZER_NETBSD || SANITIZER_FUCHSIA
#define CAN_SANITIZE_LEAKS 1
Expand Down
33 changes: 30 additions & 3 deletions compiler-rt/lib/lsan/lsan_common_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,28 @@ static bool IsLinker(const LoadedModule& module) {

__attribute__((tls_model("initial-exec")))
THREADLOCAL int disable_counter;
bool DisabledInThisThread() { return disable_counter > 0; }
void DisableInThisThread() { disable_counter++; }
bool DisabledInThisThread() {
#if SANITIZER_ANDROID
// LSAN is only enabled with Android-S and up.
if (!HAS_ANDROID_THREAD_PROPERTIES_API)
return true;
#endif
return disable_counter > 0;
}
void DisableInThisThread() {
#if SANITIZER_ANDROID
// LSAN is only enabled with Android-S and up.
if (!HAS_ANDROID_THREAD_PROPERTIES_API)
return;
#endif
disable_counter++;
}
void EnableInThisThread() {
#if SANITIZER_ANDROID
// LSAN is only enabled with Android-S and up.
if (!HAS_ANDROID_THREAD_PROPERTIES_API)
return;
#endif
if (disable_counter == 0) {
DisableCounterUnderflow();
}
Expand Down Expand Up @@ -95,7 +114,15 @@ static int ProcessGlobalRegionsCallback(struct dl_phdr_info *info, size_t size,

// Scans global variables for heap pointers.
void ProcessGlobalRegions(Frontier *frontier) {
if (!flags()->use_globals) return;
if (!flags()->use_globals) {
#if SANITIZER_ANDROID
// There are known malloc'ed global variables from libc[++] on Android.
// If use_globals is turnt off, we could see leaks.
// Issue a warning in case users turn it off by accident.
Report("use_globals=0 on Android could lead to false reports.");
#endif
return;
}
dl_iterate_phdr(ProcessGlobalRegionsCallback, frontier);
}

Expand Down
5 changes: 3 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@
//
// FIXME: do we have anything like this on Mac?
#ifndef SANITIZER_CAN_USE_PREINIT_ARRAY
#if ((SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_OPENBSD || \
SANITIZER_FUCHSIA || SANITIZER_NETBSD) && !defined(PIC)
#if (SANITIZER_LINUX || SANITIZER_OPENBSD || SANITIZER_FUCHSIA || \
SANITIZER_NETBSD) && \
!defined(PIC)
#define SANITIZER_CAN_USE_PREINIT_ARRAY 1
// Before Solaris 11.4, .preinit_array is fully supported only with GNU ld.
// FIXME: Check for those conditions.
Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ ALWAYS_INLINE uptr *get_android_tls_ptr() {
return reinterpret_cast<uptr *>(&__get_tls()[TLS_SLOT_SANITIZER]);
}

// Bionic provides this API since 31.
extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_get_static_tls_bounds(void **,
void **);
extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_iterate_dynamic_tls(
pid_t, void (*cb)(void *, void *, uptr, void *), void *);

#define HAS_ANDROID_THREAD_PROPERTIES_API (&__libc_iterate_dynamic_tls != 0)

#else
#define HAS_ANDROID_THREAD_PROPERTIES_API (0)
#endif // SANITIZER_ANDROID

} // namespace __sanitizer
Expand Down
17 changes: 13 additions & 4 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,19 @@ int GetSizeFromHdr(struct dl_phdr_info *info, size_t size, void *data) {

#if !SANITIZER_GO
static void GetTls(uptr *addr, uptr *size) {
#if SANITIZER_LINUX && !SANITIZER_ANDROID
#if SANITIZER_ANDROID
if (HAS_ANDROID_THREAD_PROPERTIES_API) {
void *start_addr;
void *end_addr;
__libc_get_static_tls_bounds(&start_addr, &end_addr);
*addr = reinterpret_cast<uptr>(start_addr);
*size =
reinterpret_cast<uptr>(end_addr) - reinterpret_cast<uptr>(start_addr);
} else {
*addr = 0;
*size = 0;
}
#elif SANITIZER_LINUX && !SANITIZER_ANDROID
#if defined(__x86_64__) || defined(__i386__) || defined(__s390__)
*addr = ThreadSelf();
*size = GetTlsSize();
Expand Down Expand Up @@ -504,9 +516,6 @@ static void GetTls(uptr *addr, uptr *size) {
#elif SANITIZER_OPENBSD
*addr = 0;
*size = 0;
#elif SANITIZER_ANDROID
*addr = 0;
*size = 0;
#elif SANITIZER_SOLARIS
// FIXME
*addr = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,15 @@
#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO \
(!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_FUCHSIA && \
SI_NOT_RTEMS && !SI_SOLARIS)
#define SANITIZER_INTERCEPT_MEMALIGN \
(!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_RTEMS)
#define SANITIZER_INTERCEPT_MEMALIGN \
(!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_RTEMS && \
!SI_ANDROID)
#define SANITIZER_INTERCEPT_PVALLOC \
(!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_FUCHSIA && \
SI_NOT_RTEMS && !SI_SOLARIS)
#define SANITIZER_INTERCEPT_CFREE \
(!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_FUCHSIA && \
SI_NOT_RTEMS && !SI_SOLARIS)
SI_NOT_RTEMS && !SI_SOLARIS && !SI_ANDROID)
#define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC && SI_NOT_RTEMS)
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE \
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/test/asan/TestCases/coverage-and-lsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
// RUN: %sancov print %t-dir/*.sancov 2>&1
//
// REQUIRES: leak-detection

// FIXME: sancov paths not work with adb
// UNSUPPORTED: android
int *g = new int;
int main(int argc, char **argv) {
g = 0;
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/test/asan/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ def build_invocation(compile_flags):
config.available_features.add('fast-unwinder-works')

# Turn on leak detection on 64-bit Linux.
leak_detection_android = config.android and 'android-thread-properties-api' in config.available_features and (config.target_arch == 'x86_64' or config.target_arch == 'i386' or config.target_arch == 'i686' or config.target_arch == 'aarch64' )
leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch == 'x86_64' or config.target_arch == 'i386')
leak_detection_mac = (config.host_os == 'Darwin') and (config.target_arch == 'x86_64')
leak_detection_netbsd = (config.host_os == 'NetBSD') and (config.target_arch in ['x86_64', 'i386'])
if leak_detection_linux or leak_detection_mac or leak_detection_netbsd:
if leak_detection_android or leak_detection_linux or leak_detection_mac or leak_detection_netbsd:
config.available_features.add('leak-detection')

# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
Expand Down
24 changes: 21 additions & 3 deletions compiler-rt/test/lit.common.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
# BFD linker in 64-bit android toolchains fails to find libc++_shared.so, which
# is a transitive shared library dependency (via asan runtime).
if config.android:
# These are needed for tests to upload/download temp files, such as
# suppression-files, to device.
config.substitutions.append( ('%device_rundir', "/data/local/tmp/Output") )
# FIXME: May need to select specific device with `-s SERIAL`
config.substitutions.append( ('%push_to_device', "adb push ") )
config.substitutions.append( ('%pull_from_device', "adb pull ") )
config.substitutions.append( ('%adb_shell ', "adb shell ") )
# Prepend the flag so that it can be overridden.
config.target_cflags = "-pie -fuse-ld=gold " + config.target_cflags
if config.android_ndk_version < 19:
Expand All @@ -69,7 +76,11 @@
# just contains a handful of ABI functions", which makes most C++ code fail
# to link. In r19 and later we just use the default which is libc++.
config.cxx_mode_flags.append('-stdlib=libstdc++')

else:
config.substitutions.append( ('%device_rundir', "") )
config.substitutions.append( ('%push_to_device', "echo ") )
config.substitutions.append( ('%pull_from_device', "echo ") )
config.substitutions.append( ('%adb_shell', "echo ") )
config.environment = dict(os.environ)

# Clear some environment variables that might affect Clang.
Expand Down Expand Up @@ -341,10 +352,15 @@ def get_macos_aligned_version(macos_vers):
if config.android_serial:
env['ANDROID_SERIAL'] = config.android_serial
config.environment['ANDROID_SERIAL'] = config.android_serial

# Must use lld because Bionic's TLS layout is not compatible with the Gold convention.
# The buildbot script will guarantee lld is built/included.
# The check for `has_lld` somehow missed that it exists and always marked tests as "unsupported".
config.use_lld = True
config.has_lld = True
adb = os.environ.get('ADB', 'adb')
try:
android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"], env=env).rstrip()
android_api_codename = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.codename"], env=env).rstrip().decode("utf-8")
except (subprocess.CalledProcessError, OSError):
lit_config.fatal("Failed to read ro.build.version.sdk (using '%s' as adb)" % adb)
try:
Expand All @@ -355,6 +371,8 @@ def get_macos_aligned_version(macos_vers):
config.available_features.add('android-26')
if android_api_level >= 28:
config.available_features.add('android-28')
if android_api_level >= 31 or android_api_codename == 'S':
config.available_features.add('android-thread-properties-api')

# Prepare the device.
android_tmpdir = '/data/local/tmp/Output'
Expand All @@ -374,7 +392,7 @@ def get_macos_aligned_version(macos_vers):
from distutils.version import LooseVersion
ver = LooseVersion(ver_line.split()[-1].decode())
# 2.27 introduced some incompatibilities
if ver >= LooseVersion("2.27"):
if ver >= LooseVersion("2.27") and not config.android:
config.available_features.add("glibc-2.27")

sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
Expand Down
Loading

0 comments on commit 02a8883

Please sign in to comment.