[compiler-rt] r349745 - Revert "[sanitizer] Support running without fd 0, 1, 2."
Ilya Biryukov via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 20 04:50:03 PST 2018
Author: ibiryukov
Date: Thu Dec 20 04:50:03 2018
New Revision: 349745
URL: http://llvm.org/viewvc/llvm-project?rev=349745&view=rev
Log:
Revert "[sanitizer] Support running without fd 0,1,2."
This reverts commit r349699.
Reason: the commit breaks compilation of sanitizer_rtems.cc when
building for RTEMS.
Removed:
compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_solaris.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Dec 20 04:50:03 2018
@@ -381,10 +381,6 @@ uptr internal_filesize(fd_t fd) {
return (uptr)st.st_size;
}
-uptr internal_dup(int oldfd) {
- return internal_syscall(SYSCALL(dup), oldfd);
-}
-
uptr internal_dup2(int oldfd, int newfd) {
#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
return internal_syscall(SYSCALL(dup3), oldfd, newfd, 0);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Thu Dec 20 04:50:03 2018
@@ -174,10 +174,6 @@ uptr internal_filesize(fd_t fd) {
return (uptr)st.st_size;
}
-uptr internal_dup(int oldfd) {
- return dup(oldfd);
-}
-
uptr internal_dup2(int oldfd, int newfd) {
return dup2(oldfd, newfd);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_netbsd.cc Thu Dec 20 04:50:03 2018
@@ -169,11 +169,6 @@ uptr internal_filesize(fd_t fd) {
return (uptr)st.st_size;
}
-uptr internal_dup(int oldfd) {
- DEFINE__REAL(int, dup, int a);
- return _REAL(dup, oldfd);
-}
-
uptr internal_dup2(int oldfd, int newfd) {
DEFINE__REAL(int, dup2, int a, int b);
return _REAL(dup2, oldfd, newfd);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Thu Dec 20 04:50:03 2018
@@ -166,7 +166,7 @@ fd_t OpenFile(const char *filename, File
fd_t res = internal_open(filename, flags, 0660);
if (internal_iserror(res, errno_p))
return kInvalidFd;
- return ReserveStandardFds(res);
+ return res;
}
void CloseFile(fd_t fd) {
@@ -269,8 +269,13 @@ bool IsAbsolutePath(const char *path) {
void ReportFile::Write(const char *buffer, uptr length) {
SpinMutexLock l(mu);
+ static const char *kWriteError =
+ "ReportFile::Write() can't output requested buffer!\n";
ReopenIfNecessary();
- internal_write(fd, buffer, length);
+ if (length != internal_write(fd, buffer, length)) {
+ internal_write(fd, kWriteError, internal_strlen(kWriteError));
+ Die();
+ }
}
bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end) {
@@ -318,21 +323,6 @@ const char *SignalContext::Describe() co
return "UNKNOWN SIGNAL";
}
-fd_t ReserveStandardFds(fd_t fd) {
- CHECK_GE(fd, 0);
- if (fd > 2)
- return fd;
- bool used[3] = {false, false, false};
- while (fd <= 2) {
- used[fd] = true;
- fd = internal_dup(fd);
- }
- for (int i = 0; i <= 2; ++i)
- if (used[i])
- internal_close(i);
- return fd;
-}
-
} // namespace __sanitizer
#endif // SANITIZER_POSIX
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h Thu Dec 20 04:50:03 2018
@@ -49,7 +49,6 @@ uptr internal_filesize(fd_t fd); // -1
uptr internal_stat(const char *path, void *buf);
uptr internal_lstat(const char *path, void *buf);
uptr internal_fstat(fd_t fd, void *buf);
-uptr internal_dup(int oldfd);
uptr internal_dup2(int oldfd, int newfd);
uptr internal_readlink(const char *path, char *buf, uptr bufsize);
uptr internal_unlink(const char *path);
@@ -100,9 +99,6 @@ uptr internal_execve(const char *filenam
bool IsStateDetached(int state);
-// Move the fd out of {0, 1, 2} range.
-fd_t ReserveStandardFds(fd_t fd);
-
} // namespace __sanitizer
#endif // SANITIZER_POSIX_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc Thu Dec 20 04:50:03 2018
@@ -200,7 +200,7 @@ fd_t OpenFile(const char *filename, File
fd_t res = open(filename, flags, 0660);
if (internal_iserror(res, errno_p))
return kInvalidFd;
- return ReserveStandardFds(res);
+ return res;
}
void CloseFile(fd_t fd) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_solaris.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_solaris.cc?rev=349745&r1=349744&r2=349745&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_solaris.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_solaris.cc Thu Dec 20 04:50:03 2018
@@ -88,8 +88,8 @@ uptr internal_open(const char *filename,
}
uptr OpenFile(const char *filename, bool write) {
- return ReserveStandardFds(
- internal_open(filename, write ? O_WRONLY | O_CREAT : O_RDONLY, 0660));
+ return internal_open(filename,
+ write ? O_WRONLY | O_CREAT : O_RDONLY, 0660);
}
DECLARE__REAL_AND_INTERNAL(uptr, read, fd_t fd, void *buf, uptr count) {
Removed: compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc?rev=349744&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/no-fd.cc (removed)
@@ -1,39 +0,0 @@
-// RUN: %clangxx_asan -O0 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=debug=1,verbosity=2 %run %t 2>&1 | FileCheck %s
-
-// Test ASan initialization
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-void parent(int argc, char **argv) {
- fprintf(stderr, "hello\n");
- // CHECK: hello
- close(0);
- close(1);
- dup2(2, 3);
- close(2);
- char *const newargv[] = {argv[0], (char *)"x", nullptr};
- execv(argv[0], newargv);
- perror("execve");
- exit(1);
-}
-
-void child() {
- assert(dup(3) == 0);
- assert(dup(3) == 1);
- assert(dup(3) == 2);
- fprintf(stderr, "world\n");
- // CHECK: world
-}
-
-int main(int argc, char **argv) {
- if (argc == 1) {
- parent(argc, argv);
- } else {
- child();
- }
-}
More information about the llvm-commits
mailing list