[PATCH] D46326: ThinLTO+CFI: short-circuit direct calls to jump table entries

Vlad Tsyrklevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 2 12:39:48 PDT 2018


vlad.tsyrklevich added a comment.

In https://reviews.llvm.org/D46326#1084858, @dmikulin wrote:

> Yeah, need a test case.
>
> In https://reviews.llvm.org/D46326#1084792, @vlad.tsyrklevich wrote:
>
> > Also, definitions in the merged module are set to have internal linkage which will not work if we plan to call them directly in other modules. We'll need to change their linkage.
>
>
> Can you give an example? I'm not sure I completely follow...


Sorry, that was a pretty terse response--I'd tried a build of Chrome with a variant of this change and was reporting the way the build failed without providing much insight as to how or why. buildBitSetsFromFunctionsNative() will set function definitions in the merged module to have internal linkage; function definitions end up in the merged module when compiled with ThinLTO if they're compiled in a translation unit with no externally visible symbols (like in ex2.cpp below.) If that's the case, the definition of a symbol (X<double>.cfi in this example) will be set to have internal linkage so a direct call to it from another translation unit will fail.

ex1.cpp:

  #include <stdio.h>
  
  template<class C> void X();
  
  int main() {
    printf("addr %p\n", &X<double>);
    X<double>();
    ((void(*)())40000)();
    return 0;
  }

ex2.cpp:

  #include <stdio.h>
  
  template<class C> void X() { printf("X\n"); }
  
  namespace { 
    __attribute__((section(".preinit_array"), used)) void (*__preinit)(void) = X<double>;
  }



  $ clang++ -fuse-ld=lld -flto=thin -fsanitize=cfi-icall -fvisibility=hidden -o ex ex1.cpp ex2.cpp
  lld: error: undefined symbol: void X<double>() (.cfi)
  >>> referenced by ex1.cpp
  >>>               lto.tmp:(main)


https://reviews.llvm.org/D46326





More information about the llvm-commits mailing list