[PATCH] D28596: [compiler-rt] General definition for weak functions.
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 18 16:43:29 PST 2017
zturner added a comment.
In https://reviews.llvm.org/D28596#649978, @mpividori wrote:
> > 2. Having a macro only around the function name, i.e.: `WEAK_ATTRIBUTE void WEAK_NAME(OnPrint)(const char *str) { code }`.
>
> I can't do that because not only I need to change the name, I also need to add a linker pragma `WIN_WEAK_ALIAS(OnPrint, OnPrint__def)` and declare `OnPrint`.
> I mean, for non-windows `OnPrint` definition will be:
>
> void OnPrint(const char *str) {
> // Default implementation
> }
>
>
> And for Windows, it will be:
>
> void OnPrint__def(const char *str) {
> // Default implementation
> }
> void OnPrint(const char *str);
> WIN_WEAK_ALIAS(OnPrint, OnPrint__def)
>
>
> Thanks.
What if instead of getting it all into one line, we settle for this:
void WEAK_FN_DEF(OnPrint)(const char *str) {
}
WEAK_FN_ALIAS(OnPrint)
The macro `WEAK_FN_ALIAS` could look like this:
#define WEAK_FN_ALIAS(Fn) \
decltype(Fn##__def) Fn; \
WIN_WEAK_ALIAS(Fn, Fn##__def)
On non-Windows platforms, it would just do nothing. Apparently the crazy decltype magic works and should give you a definition named `OnPrint__def` and a forward declaration named `OnPrint`.
https://reviews.llvm.org/D28596
More information about the llvm-commits
mailing list