Skip to content

Commit 97116b9

Browse files
korlibrad0
authored andcommitted
[compiler-rt][sanitizer] add Haiku support
1 parent 0d68bad commit 97116b9

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
@@ -174,7 +174,7 @@ static void AfterFork(bool fork_child) {
174174

175175
void InstallAtForkHandler() {
176176
# if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \
177-
(SANITIZER_LINUX && SANITIZER_SPARC)
177+
(SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU
178178
// While other Linux targets use clone in internal_fork which doesn't
179179
// trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a
180180
// 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

compiler-rt/lib/sanitizer_common/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(SANITIZER_SOURCES_NOTERMINATION
1111
sanitizer_flags.cpp
1212
sanitizer_flag_parser.cpp
1313
sanitizer_fuchsia.cpp
14+
sanitizer_haiku.cpp
1415
sanitizer_libc.cpp
1516
sanitizer_libignore.cpp
1617
sanitizer_linux.cpp
@@ -28,6 +29,7 @@ set(SANITIZER_SOURCES_NOTERMINATION
2829
sanitizer_procmaps_common.cpp
2930
sanitizer_procmaps_bsd.cpp
3031
sanitizer_procmaps_fuchsia.cpp
32+
sanitizer_procmaps_haiku.cpp
3133
sanitizer_procmaps_linux.cpp
3234
sanitizer_procmaps_mac.cpp
3335
sanitizer_procmaps_solaris.cpp
@@ -227,6 +229,9 @@ set(SANITIZER_COMMON_DEFINITIONS
227229

228230
# note: L not I, this is nodefaultlibs for msvc
229231
append_list_if(MSVC /Zl SANITIZER_COMMON_CFLAGS)
232+
if(HAIKU)
233+
list(APPEND SANITIZER_COMMON_CFLAGS -I/system/develop/headers/private -I/system/develop/headers/private/system/arch/x86_64 -I/system/develop/headers/private/system)
234+
endif()
230235
set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
231236

232237
# Too many existing bugs, needs cleanup.

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,39 @@ static void ioctl_table_fill() {
4848
++ioctl_table_size; \
4949
}
5050

51+
_(FIONBIO, READ, sizeof(int));
52+
#if !SANITIZER_HAIKU
5153
_(FIOASYNC, READ, sizeof(int));
5254
_(FIOCLEX, NONE, 0);
5355
_(FIOGETOWN, WRITE, sizeof(int));
54-
_(FIONBIO, READ, sizeof(int));
5556
_(FIONCLEX, NONE, 0);
5657
_(FIOSETOWN, READ, sizeof(int));
58+
#endif
5759
_(SIOCATMARK, WRITE, sizeof(int));
5860
_(SIOCGIFCONF, CUSTOM, 0);
5961
_(SIOCGPGRP, WRITE, sizeof(int));
6062
_(SIOCSPGRP, READ, sizeof(int));
61-
#if !SANITIZER_SOLARIS
63+
#if !SANITIZER_SOLARIS && !SANITIZER_HAIKU
6264
_(TIOCCONS, NONE, 0);
6365
#endif
64-
_(TIOCEXCL, NONE, 0);
66+
#if !SANITIZER_HAIKU
6567
_(TIOCGETD, WRITE, sizeof(int));
68+
_(TIOCNOTTY, NONE, 0);
69+
_(TIOCPKT, READ, sizeof(int));
70+
_(TIOCSETD, READ, sizeof(int));
71+
_(TIOCSTI, READ, sizeof(char));
72+
#endif
73+
_(TIOCEXCL, NONE, 0);
6674
_(TIOCGPGRP, WRITE, pid_t_sz);
6775
_(TIOCGWINSZ, WRITE, struct_winsize_sz);
6876
_(TIOCMBIC, READ, sizeof(int));
6977
_(TIOCMBIS, READ, sizeof(int));
7078
_(TIOCMGET, WRITE, sizeof(int));
7179
_(TIOCMSET, READ, sizeof(int));
72-
_(TIOCNOTTY, NONE, 0);
7380
_(TIOCNXCL, NONE, 0);
7481
_(TIOCOUTQ, WRITE, sizeof(int));
75-
_(TIOCPKT, READ, sizeof(int));
7682
_(TIOCSCTTY, NONE, 0);
77-
_(TIOCSETD, READ, sizeof(int));
7883
_(TIOCSPGRP, READ, pid_t_sz);
79-
_(TIOCSTI, READ, sizeof(char));
8084
_(TIOCSWINSZ, READ, struct_winsize_sz);
8185

8286
#if !SANITIZER_IOS

compiler-rt/lib/sanitizer_common/sanitizer_errno.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
# define __errno_location ___errno
3030
#elif SANITIZER_WINDOWS
3131
# define __errno_location _errno
32+
#elif SANITIZER_HAIKU
33+
# define __errno_location _errnop
3234
#endif
3335

3436
extern "C" int *__errno_location();

compiler-rt/lib/sanitizer_common/sanitizer_errno_codes.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@
2121

2222
namespace __sanitizer {
2323

24-
#define errno_ENOMEM 12
25-
#define errno_EBUSY 16
26-
#define errno_EINVAL 22
27-
#define errno_ERANGE 34
28-
#define errno_ENAMETOOLONG 36
29-
#define errno_ENOSYS 38
24+
#ifdef __HAIKU__
25+
# define errno_ENOMEM (0x80000000)
26+
# define errno_EBUSY (0x80000000 + 14)
27+
# define errno_EINVAL (0x80000000 + 5)
28+
# define errno_ERANGE (0x80007000 + 17)
29+
# define errno_ENAMETOOLONG (0x80000000 + 0x6004)
30+
# define errno_ENOSYS (0x80007009)
31+
#else
32+
# define errno_ENOMEM 12
33+
# define errno_EBUSY 16
34+
# define errno_EINVAL 22
35+
# define errno_ERANGE 34
36+
# define errno_ENAMETOOLONG 36
37+
# define errno_ENOSYS 38
38+
#endif
3039

3140
// Those might not present or their value differ on different platforms.
3241
extern const int errno_EOWNERDEAD;

0 commit comments

Comments
 (0)