Skip to content

Commit 480eea4

Browse files
committed
Revert "[Sanitizers] Get link map on FreeBSD via documented API"
This reverts commit 92e267a, as it appears Android is missing dlinfo(3).
1 parent b8ebc11 commit 480eea4

11 files changed

+15
-49
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ uptr internal_getpid() {
6666
return pid;
6767
}
6868

69-
int internal_dlinfo(void *handle, int request, void *p) {
70-
UNIMPLEMENTED();
71-
}
72-
7369
uptr GetThreadSelf() { return reinterpret_cast<uptr>(thrd_current()); }
7470

7571
tid_t GetTid() { return GetThreadSelf(); }

compiler-rt/lib/sanitizer_common/sanitizer_libc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ unsigned int internal_sleep(unsigned int seconds);
7272
uptr internal_getpid();
7373
uptr internal_getppid();
7474

75-
int internal_dlinfo(void *handle, int request, void *p);
76-
7775
// Threading
7876
uptr internal_sched_yield();
7977

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,6 @@ uptr internal_getppid() {
735735
return internal_syscall(SYSCALL(getppid));
736736
}
737737

738-
int internal_dlinfo(void *handle, int request, void *p) {
739-
return dlinfo(handle, request, p);
740-
}
741-
742738
uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count) {
743739
#if SANITIZER_FREEBSD
744740
return internal_syscall(SYSCALL(getdirentries), fd, (uptr)dirp, count, NULL);

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ uptr internal_getpid() {
208208
return getpid();
209209
}
210210

211-
int internal_dlinfo(void *handle, int request, void *p) {
212-
UNIMPLEMENTED();
213-
}
214-
215211
int internal_sigaction(int signum, const void *act, void *oldact) {
216212
return sigaction(signum,
217213
(const struct sigaction *)act, (struct sigaction *)oldact);

compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,6 @@ uptr internal_getppid() {
265265
return _REAL(getppid);
266266
}
267267

268-
int internal_dlinfo(void *handle, int request, void *p) {
269-
DEFINE__REAL(int, dlinfo, void *a, int b, void *c);
270-
return _REAL(dlinfo, handle, request, p);
271-
}
272-
273268
uptr internal_getdents(fd_t fd, void *dirp, unsigned int count) {
274269
DEFINE__REAL(int, __getdents30, int a, void *b, size_t c);
275270
return _REAL(__getdents30, fd, dirp, count);

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include <netinet/ip_mroute.h>
5353
//
5454
#include <dirent.h>
55-
#include <dlfcn.h>
5655
#include <fstab.h>
5756
#include <fts.h>
5857
#include <glob.h>
@@ -87,15 +86,9 @@
8786

8887
// Include these after system headers to avoid name clashes and ambiguities.
8988
#include "sanitizer_internal_defs.h"
90-
#include "sanitizer_libc.h"
9189
#include "sanitizer_platform_limits_freebsd.h"
9290

9391
namespace __sanitizer {
94-
void *__sanitizer_get_link_map_by_dlopen_handle(void *handle) {
95-
void *p = nullptr;
96-
return internal_dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
97-
}
98-
9992
unsigned struct_cap_rights_sz = sizeof(cap_rights_t);
10093
unsigned struct_utsname_sz = sizeof(struct utsname);
10194
unsigned struct_stat_sz = sizeof(struct stat);

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
#include "sanitizer_platform.h"
2121
#include "sanitizer_platform_limits_posix.h"
2222

23+
// FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
24+
// incorporates the map structure.
25+
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
26+
((link_map *)((handle) == nullptr ? nullptr : ((char *)(handle) + 560)))
2327
// Get sys/_types.h, because that tells us whether 64-bit inodes are
2428
// used in struct dirent below.
2529
#include <sys/_types.h>
2630

2731
namespace __sanitizer {
28-
void *__sanitizer_get_link_map_by_dlopen_handle(void *handle);
29-
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
30-
(link_map *)__sanitizer_get_link_map_by_dlopen_handle(handle)
31-
3232
extern unsigned struct_utsname_sz;
3333
extern unsigned struct_stat_sz;
3434
#if defined(__powerpc64__)

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ struct urio_command {
213213
#include <dev/wscons/wsdisplay_usl_io.h>
214214
#include <fs/autofs/autofs_ioctl.h>
215215
#include <dirent.h>
216-
#include <dlfcn.h>
217216
#include <glob.h>
218217
#include <grp.h>
219218
#include <ifaddrs.h>
@@ -259,15 +258,9 @@ struct urio_command {
259258

260259
// Include these after system headers to avoid name clashes and ambiguities.
261260
#include "sanitizer_internal_defs.h"
262-
#include "sanitizer_libc.h"
263261
#include "sanitizer_platform_limits_netbsd.h"
264262

265263
namespace __sanitizer {
266-
void *__sanitizer_get_link_map_by_dlopen_handle(void* handle) {
267-
void *p = nullptr;
268-
return internal_dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
269-
}
270-
271264
unsigned struct_utsname_sz = sizeof(struct utsname);
272265
unsigned struct_stat_sz = sizeof(struct stat);
273266
unsigned struct_rusage_sz = sizeof(struct rusage);

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
#include "sanitizer_internal_defs.h"
2020
#include "sanitizer_platform.h"
2121

22-
namespace __sanitizer {
23-
void *__sanitizer_get_link_map_by_dlopen_handle(void *handle);
24-
# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
25-
(link_map *)__sanitizer_get_link_map_by_dlopen_handle(handle)
22+
#define _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, shift) \
23+
((link_map *)((handle) == nullptr ? nullptr : ((char *)(handle) + (shift))))
2624

25+
#if defined(__x86_64__)
26+
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
27+
_GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 264)
28+
#elif defined(__i386__)
29+
#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
30+
_GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 136)
31+
#endif
32+
33+
namespace __sanitizer {
2734
extern unsigned struct_utsname_sz;
2835
extern unsigned struct_stat_sz;
2936
extern unsigned struct_rusage_sz;

compiler-rt/lib/sanitizer_common/sanitizer_rtems.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ uptr internal_getpid() {
4949
return getpid();
5050
}
5151

52-
int internal_dlinfo(void *handle, int request, void *p) {
53-
UNIMPLEMENTED();
54-
}
55-
5652
bool FileExists(const char *filename) {
5753
struct stat st;
5854
if (stat(filename, &st))

0 commit comments

Comments
 (0)