[PATCH] D61110: [NFC][Sanitizer] Extract GetFuncAddr from GetRealFunctionAddress
Julian Lettner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 10:44:39 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359213: [NFC][Sanitizer] Extract GetFuncAddr from GetRealFunctionAddress (authored by yln, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D61110?vs=196566&id=196679#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61110/new/
https://reviews.llvm.org/D61110
Files:
compiler-rt/trunk/lib/interception/interception_linux.cc
compiler-rt/trunk/lib/interception/interception_linux.h
compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc
Index: compiler-rt/trunk/lib/interception/interception_linux.cc
===================================================================
--- compiler-rt/trunk/lib/interception/interception_linux.cc
+++ compiler-rt/trunk/lib/interception/interception_linux.cc
@@ -35,27 +35,32 @@
bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
uptr real, uptr wrapper) {
+ *func_addr = (uptr)GetFuncAddr(func_name);
+ return real == wrapper;
+}
+
+void *GetFuncAddr(const char *name) {
#if SANITIZER_NETBSD
// FIXME: Find a better way to handle renames
- if (StrCmp(func_name, "sigaction"))
- func_name = "__sigaction14";
+ if (StrCmp(name, "sigaction"))
+ name = "__sigaction14";
#endif
- *func_addr = (uptr)dlsym(RTLD_NEXT, func_name);
- if (!*func_addr) {
+ void *addr = dlsym(RTLD_NEXT, name);
+ if (!addr) {
// If the lookup using RTLD_NEXT failed, the sanitizer runtime library is
// later in the library search order than the DSO that we are trying to
// intercept, which means that we cannot intercept this function. We still
// want the address of the real definition, though, so look it up using
// RTLD_DEFAULT.
- *func_addr = (uptr)dlsym(RTLD_DEFAULT, func_name);
+ addr = dlsym(RTLD_DEFAULT, name);
}
- return real == wrapper;
+ return addr;
}
// Android and Solaris do not have dlvsym
#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD
-void *GetFuncAddrVer(const char *func_name, const char *ver) {
- return dlvsym(RTLD_NEXT, func_name, ver);
+void *GetFuncAddrVer(const char *name, const char *ver) {
+ return dlvsym(RTLD_NEXT, name, ver);
}
#endif // !SANITIZER_ANDROID
Index: compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc
===================================================================
--- compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc
+++ compiler-rt/trunk/lib/interception/tests/interception_linux_test.cc
@@ -44,6 +44,11 @@
EXPECT_EQ(0U, dummy_address);
}
+TEST(Interception, GetFuncAddr) {
+ EXPECT_NE(GetFuncAddr("malloc"), nullptr);
+ EXPECT_EQ(GetFuncAddr("does_not_exist"), nullptr);
+}
+
TEST(Interception, Basic) {
ASSERT_TRUE(INTERCEPT_FUNCTION(isdigit));
Index: compiler-rt/trunk/lib/interception/interception_linux.h
===================================================================
--- compiler-rt/trunk/lib/interception/interception_linux.h
+++ compiler-rt/trunk/lib/interception/interception_linux.h
@@ -25,7 +25,8 @@
// returns true if a function with the given name was found.
bool GetRealFunctionAddress(const char *func_name, uptr *func_addr,
uptr real, uptr wrapper);
-void *GetFuncAddrVer(const char *func_name, const char *ver);
+void *GetFuncAddr(const char *name);
+void *GetFuncAddrVer(const char *name, const char *ver);
} // namespace __interception
#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61110.196679.patch
Type: text/x-patch
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190425/77214d49/attachment.bin>
More information about the llvm-commits
mailing list