[PATCH] D105176: [InstrProfiling] Use external weak reference for bias variable

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 12 22:56:08 PDT 2021


phosek added a comment.

In D105176#2868626 <https://reviews.llvm.org/D105176#2868626>, @phosek wrote:

> @MaskRay it looks like we could use the following pattern:
>
>   extern intptr_t __llvm_profile_counter_bias;
>   
>   #if defined(_WIN32)
>   intptr_t __llvm_profile_counter_bias_default = 0;
>   #pragma comment(linker, "/alternatename:" \
>                   SYMBOL_NAME("__llvm_profile_counter_bias") "=" \
>                   SYMBOL_NAME("__llvm_profile_counter_bias_default"))
>   #endif
>   
>   bool usesRuntimeCounterRelocation() {
>     void *s1 = &__llvm_profile_counter_bias;
>     void *s2 = &__llvm_profile_counter_bias_default;
>     return s1 != s2;
>   }
>
> This does seem to work with `clang-cl` but when I tried this with `cl` I still get an error:
>
>   error LNK2019: unresolved external symbol __llvm_profile_counter_bias referenced in function usesRuntimeCounterRelocation

Never mind, I have figured it out. This should now handle COFF as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105176/new/

https://reviews.llvm.org/D105176



More information about the llvm-commits mailing list