[compiler-rt] r326644 - Adding Msan support to FreeBSD
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 3 03:43:12 PST 2018
Author: kamil
Date: Sat Mar 3 03:43:11 2018
New Revision: 326644
URL: http://llvm.org/viewvc/llvm-project?rev=326644&view=rev
Log:
Adding Msan support to FreeBSD
Summary:
Enabling the memory sanitizer support for FreeBSD, most of unit tests are compatible.
- Adding fstat and stressor_r interceptors.
- Updating the struct link_map access since most likely the struct Obj_Entry had been updated since.
- Disabling few unit tests until further work is needed (or we can assume it can work in real world code).
Patch by: David CARLIER
Reviewers: vitalybuka, krytarowski
Reviewed By: vitalybuka
Subscribers: eugenis, dim, srhines, emaste, kubamracek, mgorny, fedor.sergeev, hintonda, llvm-commits, #sanitizers
Differential Revision: https://reviews.llvm.org/D43080
Modified:
compiler-rt/trunk/cmake/config-ix.cmake
compiler-rt/trunk/lib/msan/CMakeLists.txt
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
compiler-rt/trunk/test/msan/dtls_test.c
compiler-rt/trunk/test/msan/getutent.cc
compiler-rt/trunk/test/msan/iconv.cc
compiler-rt/trunk/test/msan/lit.cfg
compiler-rt/trunk/test/msan/pthread_getattr_np_deadlock.cc
compiler-rt/trunk/test/msan/pvalloc.cc
compiler-rt/trunk/test/msan/strlen_of_shadow.cc
compiler-rt/trunk/test/msan/textdomain.cc
compiler-rt/trunk/test/msan/tls_reuse.cc
compiler-rt/trunk/test/msan/tsearch.cc
compiler-rt/trunk/test/msan/tzset.cc
Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Sat Mar 3 03:43:11 2018
@@ -530,7 +530,7 @@ else()
endif()
if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
- OS_NAME MATCHES "Linux|NetBSD")
+ OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
set(COMPILER_RT_HAS_MSAN TRUE)
else()
set(COMPILER_RT_HAS_MSAN FALSE)
Modified: compiler-rt/trunk/lib/msan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/CMakeLists.txt?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/msan/CMakeLists.txt Sat Mar 3 03:43:11 2018
@@ -17,8 +17,11 @@ set(MSAN_RTL_CXX_SOURCES
set(MSAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
+append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC -ftls-model=initial-exec MSAN_RTL_CFLAGS)
append_rtti_flag(OFF MSAN_RTL_CFLAGS)
-append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE MSAN_RTL_CFLAGS)
+if(NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE MSAN_RTL_CFLAGS)
+endif()
# Prevent clang from generating libc calls.
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding MSAN_RTL_CFLAGS)
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Sat Mar 3 03:43:11 2018
@@ -681,7 +681,7 @@ INTERCEPTOR(int, putenv, char *string) {
return res;
}
-#if SANITIZER_NETBSD
+#if SANITIZER_FREEBSD || SANITIZER_NETBSD
INTERCEPTOR(int, fstat, int fd, void *buf) {
ENSURE_MSAN_INITED();
int res = REAL(fstat)(fd, buf);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Sat Mar 3 03:43:11 2018
@@ -3590,7 +3590,7 @@ INTERCEPTOR(char *, strerror, int errnum
// * GNU version returns message pointer, which points to either buf or some
// static storage.
#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || \
- SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD
+ SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD || SANITIZER_FREEBSD
// POSIX version. Spec is not clear on whether buf is NULL-terminated.
// At least on OSX, buf contents are valid even when the call fails.
INTERCEPTOR(int, strerror_r, int errnum, char *buf, SIZE_T buflen) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Sat Mar 3 03:43:11 2018
@@ -24,7 +24,7 @@
// FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
// incorporates the map structure.
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
- ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 544)))
+ ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 560)))
// Get sys/_types.h, because that tells us whether 64-bit inodes are
// used in struct dirent below.
#include <sys/_types.h>
Modified: compiler-rt/trunk/test/msan/dtls_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/dtls_test.c?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/dtls_test.c (original)
+++ compiler-rt/trunk/test/msan/dtls_test.c Sat Mar 3 03:43:11 2018
@@ -5,6 +5,8 @@
Regression test for a bug in msan/glibc integration,
see https://sourceware.org/bugzilla/show_bug.cgi?id=16291
and https://github.com/google/sanitizers/issues/547
+
+ XFAIL: freebsd
*/
#ifndef BUILD_SO
Modified: compiler-rt/trunk/test/msan/getutent.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/getutent.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/getutent.cc (original)
+++ compiler-rt/trunk/test/msan/getutent.cc Sat Mar 3 03:43:11 2018
@@ -1,14 +1,18 @@
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
+#ifndef __FreeBSD__
#include <utmp.h>
+#endif
#include <utmpx.h>
#include <sanitizer/msan_interface.h>
int main(void) {
+#ifndef __FreeBSD__
setutent();
while (struct utmp *ut = getutent())
__msan_check_mem_is_initialized(ut, sizeof(*ut));
endutent();
+#endif
setutxent();
while (struct utmpx *utx = getutxent())
Modified: compiler-rt/trunk/test/msan/iconv.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/iconv.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/iconv.cc (original)
+++ compiler-rt/trunk/test/msan/iconv.cc Sat Mar 3 03:43:11 2018
@@ -15,7 +15,7 @@ int main(void) {
char inbuf_[100];
strcpy(inbuf_, "sample text");
char outbuf_[100];
-#if defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__NetBSD__)
// Some OSes expect the 2nd argument of iconv(3) to be of type const char **
const char *inbuf = inbuf_;
#else
Modified: compiler-rt/trunk/test/msan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/lit.cfg?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/lit.cfg (original)
+++ compiler-rt/trunk/test/msan/lit.cfg Sat Mar 3 03:43:11 2018
@@ -29,7 +29,7 @@ config.substitutions.append( ("%clangxx_
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
-if config.host_os not in ['Linux', 'NetBSD']:
+if config.host_os not in ['Linux', 'NetBSD', 'FreeBSD']:
config.unsupported = True
# For mips64, mips64el we have forced store_context_size to 1 because these
Modified: compiler-rt/trunk/test/msan/pthread_getattr_np_deadlock.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/pthread_getattr_np_deadlock.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/pthread_getattr_np_deadlock.cc (original)
+++ compiler-rt/trunk/test/msan/pthread_getattr_np_deadlock.cc Sat Mar 3 03:43:11 2018
@@ -1,6 +1,7 @@
// RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && %run %t
// Regression test for a deadlock in pthread_getattr_np
+// UNSUPPORTED: freebsd
#include <assert.h>
#include <pthread.h>
Modified: compiler-rt/trunk/test/msan/pvalloc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/pvalloc.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/pvalloc.cc (original)
+++ compiler-rt/trunk/test/msan/pvalloc.cc Sat Mar 3 03:43:11 2018
@@ -4,6 +4,7 @@
// RUN: MSAN_OPTIONS=allocator_may_return_null=0 not %run %t psm1 2>&1 | FileCheck %s
// RUN: MSAN_OPTIONS=allocator_may_return_null=1 %run %t psm1 2>&1
+// pvalloc is Linux only
// UNSUPPORTED: win32, freebsd, netbsd
// Checks that pvalloc overflows are caught. If the allocator is allowed to
Modified: compiler-rt/trunk/test/msan/strlen_of_shadow.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/strlen_of_shadow.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/strlen_of_shadow.cc (original)
+++ compiler-rt/trunk/test/msan/strlen_of_shadow.cc Sat Mar 3 03:43:11 2018
@@ -2,6 +2,8 @@
// Check that strlen() and similar intercepted functions can be called on shadow
// memory.
+// The mem_to_shadow's part might need rework
+// XFAIL: freebsd
#include <assert.h>
#include <stdint.h>
Modified: compiler-rt/trunk/test/msan/textdomain.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/textdomain.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/textdomain.cc (original)
+++ compiler-rt/trunk/test/msan/textdomain.cc Sat Mar 3 03:43:11 2018
@@ -1,4 +1,5 @@
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
+// textdomain() is not a part of libc on FreeBSD and NetBSD.
// UNSUPPORTED: netbsd, freebsd
#include <libintl.h>
Modified: compiler-rt/trunk/test/msan/tls_reuse.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/tls_reuse.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/tls_reuse.cc (original)
+++ compiler-rt/trunk/test/msan/tls_reuse.cc Sat Mar 3 03:43:11 2018
@@ -1,6 +1,7 @@
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
// Check that when TLS block is reused between threads, its shadow is cleaned.
+// XFAIL: freebsd
#include <pthread.h>
#include <stdio.h>
Modified: compiler-rt/trunk/test/msan/tsearch.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/tsearch.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/tsearch.cc (original)
+++ compiler-rt/trunk/test/msan/tsearch.cc Sat Mar 3 03:43:11 2018
@@ -1,7 +1,7 @@
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
// tdestroy is a GNU extension
-// UNSUPPORTED: netbsd
+// UNSUPPORTED: netbsd, freebsd
#include <assert.h>
#include <search.h>
Modified: compiler-rt/trunk/test/msan/tzset.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/tzset.cc?rev=326644&r1=326643&r2=326644&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/tzset.cc (original)
+++ compiler-rt/trunk/test/msan/tzset.cc Sat Mar 3 03:43:11 2018
@@ -1,4 +1,5 @@
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
+// XFAIL: freebsd
#include <stdlib.h>
#include <string.h>
More information about the llvm-commits
mailing list