Skip to content

Commit d1fd977

Browse files
brad0korli
andauthored
[compiler-rt][sanitizer] add Haiku support (#134772)
Co-authored-by: Jérôme Duval <[email protected]>
1 parent 90a202f commit d1fd977

27 files changed

+693
-80
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
569569
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
570570
list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
571571
endif()
572+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
573+
list(APPEND SANITIZER_COMMON_LINK_LIBS root)
574+
list(APPEND SANITIZER_COMMON_LINK_LIBS bsd)
575+
endif()
572576

573577
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
574578
set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT ON)

compiler-rt/cmake/config-ix.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING
760760
list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
761761

762762
if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
763-
(OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS" OR
763+
(OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS|Haiku" OR
764764
(OS_NAME MATCHES "Windows" AND NOT CYGWIN AND
765765
(NOT MINGW OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))))
766766
set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
@@ -875,7 +875,7 @@ else()
875875
endif()
876876

877877
if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
878-
OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia|SunOS")
878+
OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia|SunOS|Haiku")
879879
set(COMPILER_RT_HAS_UBSAN TRUE)
880880
else()
881881
set(COMPILER_RT_HAS_UBSAN FALSE)

compiler-rt/lib/asan/asan_linux.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
#include "sanitizer_common/sanitizer_platform.h"
1515
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
16-
SANITIZER_SOLARIS
16+
SANITIZER_SOLARIS || SANITIZER_HAIKU
17+
18+
# if SANITIZER_HAIKU
19+
# define _DEFAULT_SOURCE
20+
# endif
1721

1822
# include <dlfcn.h>
1923
# include <fcntl.h>
@@ -22,7 +26,9 @@
2226
# include <stdio.h>
2327
# include <sys/mman.h>
2428
# include <sys/resource.h>
25-
# include <sys/syscall.h>
29+
# if !SANITIZER_HAIKU
30+
# include <sys/syscall.h>
31+
# endif
2632
# include <sys/time.h>
2733
# include <sys/types.h>
2834
# include <unistd.h>
@@ -37,7 +43,7 @@
3743
# include "sanitizer_common/sanitizer_libc.h"
3844
# include "sanitizer_common/sanitizer_procmaps.h"
3945

40-
# if SANITIZER_FREEBSD
46+
# if SANITIZER_FREEBSD || SANITIZER_HAIKU
4147
# include <sys/link_elf.h>
4248
# endif
4349

@@ -54,6 +60,8 @@
5460
# elif SANITIZER_NETBSD
5561
# include <link_elf.h>
5662
# include <ucontext.h>
63+
# elif SANITIZER_HAIKU
64+
extern "C" void *_DYNAMIC;
5765
# else
5866
# include <link.h>
5967
# include <sys/ucontext.h>
@@ -162,6 +170,12 @@ static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size,
162170
return 0;
163171
}
164172

173+
# if SANITIZER_HAIKU
174+
if (!info->dlpi_name[0] ||
175+
internal_strncmp(info->dlpi_name, "/boot/system/runtime_loader",
176+
sizeof("/boot/system/runtime_loader") - 1) == 0)
177+
return 0;
178+
# endif
165179
# if SANITIZER_LINUX
166180
// Ignore vDSO. glibc versions earlier than 2.15 (and some patched
167181
// by distributors) return an empty name for the vDSO entry, so

compiler-rt/lib/asan/asan_malloc_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "sanitizer_common/sanitizer_platform.h"
1717
#if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \
18-
SANITIZER_NETBSD || SANITIZER_SOLARIS
18+
SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_HAIKU
1919

2020
# include "asan_allocator.h"
2121
# include "asan_interceptors.h"

compiler-rt/lib/asan/asan_posix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void AfterFork(bool fork_child) {
180180

181181
void InstallAtForkHandler() {
182182
# if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \
183-
(SANITIZER_LINUX && SANITIZER_SPARC)
183+
(SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU
184184
// While other Linux targets use clone in internal_fork which doesn't
185185
// trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a
186186
// hang.

compiler-rt/lib/asan/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ if(NOT APPLE)
109109
append_list_if(COMPILER_RT_HAS_LIBM -lm ASAN_UNITTEST_NOINST_LINK_FLAGS)
110110
append_list_if(COMPILER_RT_HAS_LIBDL -ldl ASAN_UNITTEST_NOINST_LINK_FLAGS)
111111
append_list_if(COMPILER_RT_HAS_LIBRT -lrt ASAN_UNITTEST_NOINST_LINK_FLAGS)
112+
append_list_if(HAIKU -lbsd ASAN_UNITTEST_NOINST_LINK_FLAGS)
112113
append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread ASAN_UNITTEST_NOINST_LINK_FLAGS)
113114
append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS)
114115
endif()

compiler-rt/lib/asan/tests/asan_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ TEST(AddressSanitizer, DISABLED_StressStackReuseAndExceptionsTest) {
11631163
}
11641164
#endif
11651165

1166-
#if !defined(_WIN32)
1166+
#if !defined(_WIN32) && !defined(__HAIKU__)
11671167
TEST(AddressSanitizer, MlockTest) {
11681168
EXPECT_EQ(0, mlockall(MCL_CURRENT));
11691169
EXPECT_EQ(0, mlock((void *)0x12345, 0x5678));

compiler-rt/lib/interception/interception.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#if !SANITIZER_LINUX && !SANITIZER_FREEBSD && !SANITIZER_APPLE && \
2121
!SANITIZER_NETBSD && !SANITIZER_WINDOWS && !SANITIZER_FUCHSIA && \
22-
!SANITIZER_SOLARIS
22+
!SANITIZER_SOLARIS && !SANITIZER_HAIKU
2323
# error "Interception doesn't work on this operating system."
2424
#endif
2525

@@ -368,7 +368,7 @@ inline void DoesNotSupportStaticLinking() {}
368368
#define INCLUDED_FROM_INTERCEPTION_LIB
369369

370370
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
371-
SANITIZER_SOLARIS
371+
SANITIZER_SOLARIS || SANITIZER_HAIKU
372372

373373
# include "interception_linux.h"
374374
# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)

compiler-rt/lib/interception/interception_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "interception.h"
1515

1616
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
17-
SANITIZER_SOLARIS
17+
SANITIZER_SOLARIS || SANITIZER_HAIKU
1818

1919
#include <dlfcn.h> // for dlsym() and dlvsym()
2020

compiler-rt/lib/interception/interception_linux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
15-
SANITIZER_SOLARIS
15+
SANITIZER_SOLARIS || SANITIZER_HAIKU
1616

1717
#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
1818
# error interception_linux.h should be included from interception library only

0 commit comments

Comments
 (0)