[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 17:32:04 PST 2017


mpividori added a comment.

Another option (as I mentioned in https://reviews.llvm.org/D28525#641954 ), that will also simplify the code, is to ALWAYS use weak aliases instead of weak functions.
So, always define a default implementation with "__def" suffix, and then define a weak alias:  `fun = fun__def` 
I am not sure if weak aliases work on Apple. If that is the case, this would STRONGLY SIMPLIFY the code since we take EXACTLY the same approach for all the platforms.
So, this is the idea:

- we define a general macro for weak aliases:

  #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

- We define a macro to represent the name of the default implemenation:

  #define WEAK_DEFAULT_NAME(Name) Name##__def

- For each weak function "fun" we provide a default implementation and weak alias:

  void WEAK_DEFAULT_NAME(fun)(int a, int b) {
     // Default implementation .....
  }
  WEAK_ALIAS(fun, WEAK_DEFAULT_NAME(fun))

What do you think? I whink this is the best we can do, and, at the same time, keep the code similar for all platforms.


https://reviews.llvm.org/D28596





More information about the llvm-commits mailing list