[PATCH] D58379: [compiler-rt] Intercept the bcmp() function.

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 25 02:00:01 PST 2019


courbet added inline comments.


================
Comment at: lib/sanitizer_common/sanitizer_common_interceptors.inc:874
+  void *ctx;
+  COMMON_INTERCEPTOR_ENTER(ctx, bcmp, a1, a2, size);
+  if (common_flags()->intercept_memcmp) {
----------------
vitalybuka wrote:
> courbet wrote:
> > vitalybuka wrote:
> > > courbet wrote:
> > > > krytarowski wrote:
> > > > > Can we reuse code with memcmp(3)? bcmp(3) is a subset of memcmp(3).
> > > > Looking at `COMMON_INTERCEPTOR_ENTER` implementation for, e.g.  tsan:
> > > > 
> > > > ```
> > > > 
> > > > #define SCOPED_TSAN_INTERCEPTOR(func, ...) \
> > > >     SCOPED_INTERCEPTOR_RAW(func, __VA_ARGS__); \
> > > >     if (REAL(func) == 0) { \
> > > >       Printf("FATAL: ThreadSanitizer: failed to intercept %s\n", #func); \
> > > >       Die(); \
> > > >     } \
> > > >     if (thr->in_rtl > 1) \
> > > >       return REAL(func)(__VA_ARGS__); 
> > > > 
> > > > 
> > > > #define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)      \
> > > >   SCOPED_TSAN_INTERCEPTOR(func, __VA_ARGS__);         \
> > > >   TsanInterceptorContext _ctx = {thr, caller_pc, pc}; \
> > > >   ctx = (void *)&_ctx;                                \
> > > >   (void) ctx;
> > > > 
> > > > ```
> > > > 
> > > > Given that the implementation calls `REAL(func)`, it feels preferable to call the real `bcmp` instead of real `memcmp`, even though calling memcmp does work. But again, I'm not familiar with how you guys typically approach this, so you tell me :)
> > > > 
> > > Sometimes we do macro
> > > But I'd prefer inline function, e.g.
> > > 
> > > int memcpy_interceptor_impl(ctx, a1, a2, size, real_fn_ptr) {
> > > ....
> > > }
> > I'm not sure I understand your suggestion correctly, but if you're suggesting we refactor using a function, then the issue is that REAL(x) only works with x a macro parameter, not if `x` is a function pointer:
> > 
> > ```
> > # define PTR_TO_REAL(x) real_##x
> > ...
> > # define REAL(x) __interception::PTR_TO_REAL(x)
> > ```
> > 
> > Refactoring using a macro would be possible, but it would look quite ugly.
> Looks like you can easily extract into a function code before REAL call
Right, done.
Note that this has the side-effect of adding one more function in the call stack (see `test/asan/TestCases/memcmp_test.cc`)


Repository:
  rCRT Compiler Runtime

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

https://reviews.llvm.org/D58379





More information about the llvm-commits mailing list