[PATCH] D29148: [compiler-rt] Provide a list of functions from sanitizers's interfaces.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 29 00:14:06 PST 2017


mpividori added a comment.

@kubamracek @kcc

For Windows, we consider 2 different cases depending on MD / MT.

+ When considering MD:
We include all the sanitizers in a dll: "asan_dynamic.dll" 
Also, we create an auxiliary static library "asan_dynamic_runtime_thunk.lib"  that clang driver includes and links with both, dlls and executables.
Both, the executable and the dll redirect the calls to the external dll.

+ When considering MT:
We include all the sanitizers in a static library: "asan.lib" which is linked to the main executable.
Also, we create an auxiliary static library "asan_dll_thunk.lib"  that clang driver includes and links with dlls, so they can access to the implementation in the main executable.

-----------------

1. When asan is implemented as a dll (MD), we need the list of weak functions for:
  - `asan_dynamic.dll` : because we use interception to check if a strong definition was included in the main executable (https://reviews.llvm.org/D29168).
  - `asan_dynamic_runtime_thunk.lib` : because we add weak aliases to the imported default implementation (https://reviews.llvm.org/D29158).

2. When asan is implemented as a static library linked to the main executable (MT), we need the list of all the sanitizer interface for:
  - `asan_win_dll_thunk.lib` : because we use interception to refer to the implementation in the main executable from other dlls.

--------------------

So, before this diff, all the functions exported were listed in `asan_win_dll_thunk.cc`. I am moving them into a general file.

I would like to generate these header files automatically. I have been working on this, but it is a bit complicated because we have some limitations. This is the general idea:

- For the list of weak functions:  search for the macro `SANITIZER_INTERFACE_WEAK_DEF(...)` in all the .cc files (for example using grep).

- For the list of sanitizer interface:  execute "dumpbin /exports asan_dynamic.dll" and save the output in the header file.

In both cases, we could generate the headers at build time, with "add_custom_command(...)" and add apropriate dependencies with `OBJECT_DEPENDS`.
I have implemented this, just using grep and sed, and works fine. When building, the headers files: `sanitizer_interface.h` are generated in the build directory, and are included by the source files.

The problem is that on Windows (http://llvm.org/docs/GettingStartedVS.html) , we don't require gnu tools for building. We only require them for running the tests. So, I don't think I can use grep or sed when building asan.

Also, I can't do this at configure time, because I need to execute `dumpbin` after building `asan_dynamic.dll`.

I could try to do the same using windows tools like `findstr` (for grep), but I find it particularly difficult to find an equivalent to `sed`.

Before continue working on this, I would like to know your opinion.

Thanks,


https://reviews.llvm.org/D29148





More information about the llvm-commits mailing list