[PATCH] D28596: [compiler-rt] General definition for weak functions.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 21 16:00:43 PST 2017


mpividori updated this revision to Diff 85251.
mpividori added a comment.

Hi,
I add a new diff to include suggested changes:

- I move Windows specific code to `sanitizer_win_defs.h`.
- I include a general explanation on using `WEAK_DEF()` and `WEAK_DECL()` in `sanitizer_internal_defs.h`.
- I remove redundant `extern "c"`.
- I clarify the purpose of `SANITIZER_SUPPORT_WEAK_HOOKS` and add some documentation.

So, to simplify the code, we always provide a default implementation for weak functions.

But, for some special cases, like weak hooks `__sanitizer_[malloc|free]_hook()` that will be called very often, we want to avoid the overhead of executing the default implementation when it is not necessary. (this overhead really matters? only the overhead of function call, because the default implmentation is empty... maybe...)
So, for weak hooks, I don't modify the code for platforms that can use real weak symbols that will evaluate to a null pointer when not defined. I only define the default implementation for platforms that doesn't support weak hooks, like:

  #if !SANITIZER_SUPPORT_WEAK_HOOKS
  WEAK_DEF(void, __sanitizer_malloc_hook, void *ptr, uptr size) {
     (void)ptr;
     (void)size;
  }
  #endif

Maybe this doesn't represent a relevant difference in practice and we can remove the `#if #endif` and always provide a default implementation for weak hooks too.

So, the final idea is this:

- `WEAK_DECL()` for declaring a weak function.
- `WEAK_DEF()` for defining a default weak implementation.
- If we don't want to provide a a default implementation when not necessary and avoid the overhead:

  #if !SANITIZER_SUPPORT_WEAK_HOOKS
  `WEAK_DEF( ... weak_hook ...)` { // default}
  #endif


https://reviews.llvm.org/D28596

Files:
  lib/asan/asan_allocator.cc
  lib/asan/asan_flags.cc
  lib/asan/asan_interface_internal.h
  lib/asan/asan_report.cc
  lib/asan/asan_suppressions.cc
  lib/asan/asan_win.cc
  lib/sanitizer_common/sancov_flags.cc
  lib/sanitizer_common/sancov_flags.h
  lib/sanitizer_common/sanitizer_allocator_interface.h
  lib/sanitizer_common/sanitizer_common.cc
  lib/sanitizer_common/sanitizer_coverage_libcdep.cc
  lib/sanitizer_common/sanitizer_coverage_libcdep_new.cc
  lib/sanitizer_common/sanitizer_interface_internal.h
  lib/sanitizer_common/sanitizer_internal_defs.h
  lib/sanitizer_common/sanitizer_printf.cc
  lib/sanitizer_common/sanitizer_win.cc
  lib/sanitizer_common/sanitizer_win_defs.h
  lib/ubsan/ubsan_flags.cc
  lib/ubsan/ubsan_flags.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28596.85251.patch
Type: text/x-patch
Size: 21888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170122/11e7d8bc/attachment-0001.bin>


More information about the llvm-commits mailing list