Skip to content

Commit dc261d2

Browse files
committed
[sanitizers] Fix internal__exit on Solaris
`TestCases/log-path_test.cpp` currently `FAIL`s on Solaris: $ env ASAN_OPTIONS=log_path=`for((i=0;i<10000;i++)); do echo -n $i; done` ./log-path_test.cpp.tmp ==5031==ERROR: Path is too long: 01234567... Segmentation Fault (core dumped) The `SEGV` happens here: Thread 2 received signal SIGSEGV, Segmentation fault. [Switching to Thread 1 (LWP 1)] 0x00000000 in ?? () (gdb) where #0 0x00000000 in ?? () #1 0x080a1e63 in __interceptor__exit (status=1) at /vol/gcc/src/llvm/llvm/local/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:3808 #2 0x08135ea8 in __sanitizer::internal__exit (exitcode=1) at /vol/gcc/src/llvm/llvm/local/projects/compiler-rt/lib/sanitizer_common/sanitizer_solaris.cc:139 when `__interceptor__exit` tries to call `__interception::real__exit` which is `NULL` at this point because the interceptors haven't been initialized yet. Ultimately, the problem lies elsewhere, however: `internal__exit` in `sanitizer_solaris.cpp` calls `_exit` itself since there doesn't exit a non-intercepted version in `libc`. Using the `syscall` interface instead isn't usually an option on Solaris because that interface isn't stable. However, in the case of `SYS_exit` it can be used nonetheless: `SYS_exit` has remained unchanged since at least Solaris 2.5.1 in 1996, and this is what this patch does. Tested on `amd64-pc-solaris2.11`. Differential Revision: https://reviews.llvm.org/D88404
1 parent f33f8a2 commit dc261d2

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,6 @@ uptr internal_sched_yield() {
426426
return internal_syscall(SYSCALL(sched_yield));
427427
}
428428

429-
void internal__exit(int exitcode) {
430-
#if SANITIZER_FREEBSD || SANITIZER_OPENBSD
431-
internal_syscall(SYSCALL(exit), exitcode);
432-
#else
433-
internal_syscall(SYSCALL(exit_group), exitcode);
434-
#endif
435-
Die(); // Unreachable.
436-
}
437-
438429
unsigned int internal_sleep(unsigned int seconds) {
439430
struct timespec ts;
440431
ts.tv_sec = seconds;
@@ -451,6 +442,17 @@ uptr internal_execve(const char *filename, char *const argv[],
451442
}
452443
#endif // !SANITIZER_SOLARIS && !SANITIZER_NETBSD
453444

445+
#if !SANITIZER_NETBSD
446+
void internal__exit(int exitcode) {
447+
#if SANITIZER_FREEBSD || SANITIZER_OPENBSD || SANITIZER_SOLARIS
448+
internal_syscall(SYSCALL(exit), exitcode);
449+
#else
450+
internal_syscall(SYSCALL(exit_group), exitcode);
451+
#endif
452+
Die(); // Unreachable.
453+
}
454+
#endif // !SANITIZER_NETBSD
455+
454456
// ----------------- sanitizer_common.h
455457
bool FileExists(const char *filename) {
456458
if (ShouldMockFailureToOpen(filename))

compiler-rt/lib/sanitizer_common/sanitizer_solaris.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ DECLARE__REAL_AND_INTERNAL(uptr, sched_yield, void) {
160160
return sched_yield();
161161
}
162162

163-
DECLARE__REAL_AND_INTERNAL(void, _exit, int exitcode) {
164-
_exit(exitcode);
165-
}
166-
167163
DECLARE__REAL_AND_INTERNAL(uptr, execve, const char *filename,
168164
char *const argv[], char *const envp[]) {
169165
return _REAL(execve)(filename, argv, envp);

0 commit comments

Comments
 (0)