[PATCH] D65221: [Sanitizer][ASAN][MSAN] Fix infinite recursion on FreeBSD

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 03:02:05 PDT 2019


MaskRay added inline comments.


================
Comment at: compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:780
 #if SANITIZER_FREEBSD
+typedef int (*syctlbyname_ptr)(const char *sname, void *oldp, size_t *oldlenp,
+                          const void *newp, size_t newlen);
----------------
MaskRay wrote:
> Change it to `using` and place it inside the function.
If the signature of `internal_sysctlbyname` is the same as `sysctlbyname`, I believe the below will be simpler:

```
static void *real;
if (!real)
  real = dlsym(RTLD_NEXT, "sysctlbyname");
return (decltype(internal_sysctlbyname)*(real))(sname, oldp, oldlenp, newp, newlen);
```

I wonder if FreeBSD specific dlfunc is still relevant nowadays...

> FreeBSD dlsym(3): "in the C standard, conversions between data and function pointer types are undefined"
>

Yet, C11 J.5.7 Function pointer casts (Annex J. I guess all working C compilers support this..):

> A pointer to an object or to void may be cast to a pointer to a function, allowing data to be invoked as a function (6.5.4).

C++11 [expr.reinterpret.cast]

> Converting a function pointer to an object pointer type or vice versa is conditionally-supported.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65221/new/

https://reviews.llvm.org/D65221





More information about the llvm-commits mailing list