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

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 11:18:31 PST 2017


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

Hi,
I updated the diff to include requested changes. I define 2 macros:  `WEAK_DEF()`  and `WEAK_INTERFACE_DECL()`.

Tests pass on Linux.

Now, if we use `WEAK_DEF()` to define a weak function, it will work on Windows too, as long as:

- We only define it once. This means, only one definition when linking. (This is different to weak symbols in linux, where we can define it many times in different TU, and the linker will choose the first that it finds). If this generates problems in the future (this doesn't happen now, but could happen when combining many sanitizers on Windows, providing the default weak implementation twice), this could be solved modifying the macro, `WEAK_DEFAULT_NAME()` to generate different default names for different sanitizers, for example, for asan, define `fun__def__asan` and for lsan, define `fun__def__lsan`.
- We link statically.

When linking dynamically, weak functions are exported with the `__dll` prefix.
So, on the client side, we can define a weak alias:  ` WIN_WEAK_ALIAS(fun , fun__dll) `  and use the default implementation or override it, redefining "fun". This is what I do in nexts diffs to fix Sanitizer Coverage for Windows. With the difference that I include the "windows weak aliases" in a static library which is included by clang driver (`clang-rt_asan_dynamic_runtime_thunk-arch.lib`), so they don't need to do anything different to make it work on Windows.

Thanks.


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.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.85159.patch
Type: text/x-patch
Size: 18159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170120/712f357b/attachment.bin>


More information about the llvm-commits mailing list