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

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 11:25:02 PST 2017

kubabrecka added a comment.

> We can define weak functions that will work in all platforms with a unique macro, without boilerplate code. If we want to continue supporting Linux, Darwin and Windows, I think this is useful.

Oh, I absolute agree with that.

The macros you mentioned (INTERCEPTOR, DECLARE_REAL, RECOVERABLE, and TEST from gtest) and a bit of mess that doesn't have a unified syntax of the user side.  Gtest's TEST() macro sounds like a different story to me, because it doesn't have parameters nor return type -- we only have `TEST(classname, testname) { code }`, which is completely reasonable.  The syntax of INTERCEPTOR() is very close to what you're proposing here, and frankly I don't like the syntax of INTERCEPTOR either.

> I need to define a function with a different name adding the suffix "__def" and also define a weak alias, and declare the original function. So, definitely this can not be accomplished in that way.

Have you looked into e.g. changing the exported symbol names with `/export:...=...`?  Couldn't this help?  Could we use it to basically switch the two functions?

If there's really no other way, then I suggest either:

1. Changing WEAK_DEF to drop the extra set of parentheses to have parity with INTERCEPTOR macro.  I.e.: `WEAK_DEF(void, OnPrint, const char *str) { code }`.
2. Having a macro only around the function name, i.e.: `WEAK_ATTRIBUTE void WEAK_NAME(OnPrint)(const char *str) { code }`.


More information about the llvm-commits mailing list