[compiler-rt] 480eea4 - Revert "[Sanitizers] Get link map on FreeBSD via documented API"
Dimitry Andric via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 14:26:46 PST 2020
Author: Dimitry Andric
Date: 2020-02-10T23:26:33+01:00
New Revision: 480eea4e45bc2d50647cb8a82467d023b94a8550
URL: https://github.com/llvm/llvm-project/commit/480eea4e45bc2d50647cb8a82467d023b94a8550
DIFF: https://github.com/llvm/llvm-project/commit/480eea4e45bc2d50647cb8a82467d023b94a8550.diff
LOG: Revert "[Sanitizers] Get link map on FreeBSD via documented API"
This reverts commit 92e267a94dc4272511be674062f8a3e8897b7083, as it
appears Android is missing dlinfo(3).
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
compiler-rt/lib/sanitizer_common/sanitizer_libc.h
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp
compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
index 6d1ad7946770..6e2c6137f0ce 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
@@ -66,10 +66,6 @@ uptr internal_getpid() {
return pid;
}
-int internal_dlinfo(void *handle, int request, void *p) {
- UNIMPLEMENTED();
-}
-
uptr GetThreadSelf() { return reinterpret_cast<uptr>(thrd_current()); }
tid_t GetTid() { return GetThreadSelf(); }
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
index ec0a6ded009b..3d5db35d68ba 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
@@ -72,8 +72,6 @@ unsigned int internal_sleep(unsigned int seconds);
uptr internal_getpid();
uptr internal_getppid();
-int internal_dlinfo(void *handle, int request, void *p);
-
// Threading
uptr internal_sched_yield();
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 9baf9066900c..15252462686d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -735,10 +735,6 @@ uptr internal_getppid() {
return internal_syscall(SYSCALL(getppid));
}
-int internal_dlinfo(void *handle, int request, void *p) {
- return dlinfo(handle, request, p);
-}
-
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
#if SANITIZER_FREEBSD
return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index c025f70df028..6999e4c0613b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -208,10 +208,6 @@ uptr internal_getpid() {
return getpid();
}
-int internal_dlinfo(void *handle, int request, void *p) {
- UNIMPLEMENTED();
-}
-
int internal_sigaction(int signum, const void *act, void *oldact) {
return sigaction(signum,
(const struct sigaction *)act, (struct sigaction *)oldact);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
index d9aff51d8ae7..49a951e04b37 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
@@ -265,11 +265,6 @@ uptr internal_getppid() {
return _REAL(getppid);
}
-int internal_dlinfo(void *handle, int request, void *p) {
- DEFINE__REAL(int, dlinfo, void *a, int b, void *c);
- return _REAL(dlinfo, handle, request, p);
-}
-
uptr internal_getdents(fd_t fd, void *dirp, unsigned int count) {
DEFINE__REAL(int, __getdents30, int a, void *b, size_t c);
return _REAL(__getdents30, fd, dirp, count);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
index dcc6c71c07d8..f504feaecd35 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -52,7 +52,6 @@
#include <netinet/ip_mroute.h>
//
#include <dirent.h>
-#include <dlfcn.h>
#include <fstab.h>
#include <fts.h>
#include <glob.h>
@@ -87,15 +86,9 @@
// Include these after system headers to avoid name clashes and ambiguities.
#include "sanitizer_internal_defs.h"
-#include "sanitizer_libc.h"
#include "sanitizer_platform_limits_freebsd.h"
namespace __sanitizer {
-void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) {
- void *p = nullptr;
- return internal_dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
-}
-
unsigned struct_cap_rights_sz = sizeof(cap_rights_t);
unsigned struct_utsname_sz = sizeof(struct utsname);
unsigned struct_stat_sz = sizeof(struct stat);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
index 5e0ca9c7d782..f461da275ded 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
@@ -20,15 +20,15 @@
#include "sanitizer_platform.h"
#include "sanitizer_platform_limits_posix.h"
+// 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) + 560)))
// Get sys/_types.h, because that tells us whether 64-bit inodes are
// used in struct dirent below.
#include <sys/_types.h>
namespace __sanitizer {
-void *__sanitizer_get_link_map_by_dlopen_handle(void *handle);
-#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
- (link_map *)__sanitizer_get_link_map_by_dlopen_handle(handle)
-
extern unsigned struct_utsname_sz;
extern unsigned struct_stat_sz;
#if defined(__powerpc64__)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cpp
index 722cb1feb560..2c889f01e9fc 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cpp
@@ -213,7 +213,6 @@ struct urio_command {
#include <dev/wscons/wsdisplay_usl_io.h>
#include <fs/autofs/autofs_ioctl.h>
#include <dirent.h>
-#include <dlfcn.h>
#include <glob.h>
#include <grp.h>
#include <ifaddrs.h>
@@ -259,15 +258,9 @@ struct urio_command {
// Include these after system headers to avoid name clashes and ambiguities.
#include "sanitizer_internal_defs.h"
-#include "sanitizer_libc.h"
#include "sanitizer_platform_limits_netbsd.h"
namespace __sanitizer {
-void *__sanitizer_get_link_map_by_dlopen_handle(void* handle) {
- void *p = nullptr;
- return internal_dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
-}
-
unsigned struct_utsname_sz = sizeof(struct utsname);
unsigned struct_stat_sz = sizeof(struct stat);
unsigned struct_rusage_sz = sizeof(struct rusage);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
index d80280d9bf8c..2544f8ce7e56 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
@@ -19,11 +19,18 @@
#include "sanitizer_internal_defs.h"
#include "sanitizer_platform.h"
-namespace __sanitizer {
-void *__sanitizer_get_link_map_by_dlopen_handle(void *handle);
-# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
- (link_map *)__sanitizer_get_link_map_by_dlopen_handle(handle)
+#define _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, shift) \
+ ((link_map *)((handle) == nullptr ? nullptr : ((char *)(handle) + (shift))))
+#if defined(__x86_64__)
+#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
+ _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 264)
+#elif defined(__i386__)
+#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
+ _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 136)
+#endif
+
+namespace __sanitizer {
extern unsigned struct_utsname_sz;
extern unsigned struct_stat_sz;
extern unsigned struct_rusage_sz;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp
index 29bcfcfa6f15..0d2576c00ab3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp
@@ -49,10 +49,6 @@ uptr internal_getpid() {
return getpid();
}
-int internal_dlinfo(void *handle, int request, void *p) {
- UNIMPLEMENTED();
-}
-
bool FileExists(const char *filename) {
struct stat st;
if (stat(filename, &st))
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
index 73dc042b69f1..dc940817c025 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
@@ -94,10 +94,6 @@ uptr internal_getpid() {
return GetProcessId(GetCurrentProcess());
}
-int internal_dlinfo(void *handle, int request, void *p) {
- UNIMPLEMENTED();
-}
-
// In contrast to POSIX, on Windows GetCurrentThreadId()
// returns a system-unique identifier.
tid_t GetTid() {
More information about the llvm-commits
mailing list