Skip to content

Commit 742576d

Browse files
nikictru
authored andcommitted
[Sanitizers] Avoid overload ambiguity for interceptors (#100986)
Since glibc 2.40 some functions like openat make use of overloads when built with `-D_FORTIFY_SOURCE=2`, see: https://github.com/bminor/glibc/blob/master/io/bits/fcntl2.h This means that doing something like `(uintptr_t) openat` or `(void *) openat` is now ambiguous, breaking the compiler-rt build on new glibc versions. Fix this by explicitly casting the symbol to the expected function type before casting it to an intptr. The expected type is obtained as `decltype(REAL(func))` so we don't have to repeat the signature from INTERCEPTOR in the INTERCEPT_FUNTION macro. Fixes #100754. (cherry picked from commit 155b7a1)
1 parent 32b786c commit 742576d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler-rt/lib/interception/interception_linux.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real,
2828
uptr func, uptr trampoline);
2929
} // namespace __interception
3030

31-
#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
32-
::__interception::InterceptFunction( \
33-
#func, \
34-
(::__interception::uptr *)&REAL(func), \
35-
(::__interception::uptr)&(func), \
36-
(::__interception::uptr)&TRAMPOLINE(func))
31+
// Cast func to type of REAL(func) before casting to uptr in case it is an
32+
// overloaded function, which is the case for some glibc functions when
33+
// _FORTIFY_SOURCE is used. This disambiguates which overload to use.
34+
#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
35+
::__interception::InterceptFunction( \
36+
#func, (::__interception::uptr *)&REAL(func), \
37+
(::__interception::uptr)(decltype(REAL(func)))&(func), \
38+
(::__interception::uptr) &TRAMPOLINE(func))
3739

3840
// dlvsym is a GNU extension supported by some other platforms.
3941
#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
4042
#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
4143
::__interception::InterceptFunction( \
4244
#func, symver, \
4345
(::__interception::uptr *)&REAL(func), \
44-
(::__interception::uptr)&(func), \
46+
(::__interception::uptr)(decltype(REAL(func)))&(func), \
4547
(::__interception::uptr)&TRAMPOLINE(func))
4648
#else
4749
#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \

0 commit comments

Comments
 (0)