[PATCH] D28525: [compiler-rt] Use macros to simplify weak alias for Windows and add some documentation.
Marcos Pividori via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 10 14:46:07 PST 2017
mpividori added a comment.
Hi, also I think we could create a general macro, like:
#if SANITIZER_WINDOWS
#define WEAK_ALIAS(Name, Default) \
__pragma(comment(linker, "/alternatename:" #Name "=" #Default))
#else
#define STRINGIFY(A) #A
#define WEAK_ALIAS(Name, Default) \
_Pragma( STRINGIFY(weak Name = Default) )
#endif
And always use that macro when need to support Windows. For example:
int some_fun_def() {
.. // Default impl.
}
WEAK_ALIAS(some_fun, some_fun_def)
This definitely simplifies the code, but has the disadvantage that we always need to define a default function, which is not strictly necessary for weak functions in non-windows systems, and as they have the same visibility, we would also be exporting the default functions (unless we find some way to avoid this).
Another option is to define another macro:
#if SANITIZER_WINDOWS
#define WEAK(ReturnType, Function) \
WEAK_ALIAS(Function, Function##_def)
ReturnType Function##_def
#else
#define WEAK(function) \
ReturnType __attribute__((weak)) Function
#endif
Then we can use:
WEAK(int, some_fun) {
.. // Default impl.
}
What do you think?
Thanks.
Repository:
rL LLVM
https://reviews.llvm.org/D28525
More information about the llvm-commits
mailing list