[PATCH] D28596: [compiler-rt] General definition for weak functions.
Marcos Pividori via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 17 21:44:49 PST 2017
mpividori added a comment.
@kubabrecka @aizatsky Ok, thanks for your comments.
So, we can't take the same approach for all platforms because: Windows supports "weak aliases" , Linux support weak functions and weak aliases, Darwin support weak functions.
So, we need to continue with this approach:
- Weak functions with default implementation for Linux and Darwin:
__attribute__ ((weak)) void fun () {
// Default implementation
}
- Use an auxiliar function for windows and define a weak alias:
void fun_def() {
// Default implementation
}
WIN_WEAK_ALIAS(fun, fun__def)
Do you agree on this point? Would you do it differently?
-----------------
So, if we include that code, we have some duplicated code:
#if ! SANITIZER_WINDOWS
__attribute__ ((weak)) void fun () {
// Default implementation
}
#else
void fun_def() {
// Default implementation
}
WIN_WEAK_ALIAS(fun, fun__def)
#endif
To avoid duplicated code, I will define a macro `WEAK_DEF()`, so we can reduce that code to:
WEAK_DEF(void, fun, ()) {
// Default implementation
}
Would you agree on this point? Would you do it differently?
-----------------
In the headers, I also need to export the default function on Windows ("fun__def").
So, we can use "#ifdef" and declare the functions as:
SANITIZER_INTERFACE_ATTRIBUTE void fun();
#ifdef SANITIZER_WINDOWS
SANITIZER_INTERFACE_ATTRIBUTE void fun__def();
#endif
To avoid that, I will define a macro `WEAK_INTERFACE_DECL()`, so we can reduce that code to:
WEAK_INTERFACE_DECL(void, fun, ());
Would you agree on this point? Would you do it differently?
-----------------
As we declare many weak functions in different sanitizers, not only in `sanitizer_common`, I thought it would be appropriate to use the macros that I mention instead of using "#ifdefs".
I would appreciate your comment on this. I really want to finish with these changes to continue focused on libFuzzer.
Thanks.
https://reviews.llvm.org/D28596
More information about the llvm-commits
mailing list