[PATCH] D81605: IR: Add missing GlobalAlias copying of ThreadLocalMode attribute

Itay Bookstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 11:41:28 PDT 2020


nextsilicon-itay-bookstein created this revision.
nextsilicon-itay-bookstein added reviewers: tejohnson, pcc.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

When trying to compile the following code under LTO with a low optimization level (--lto-O0, for instance), a link error is encountered (relative relocation against absolute symbol).
As far as my research into the matter suggests, this is a bug in the IR linking process whereby the ThreadLocalMode attribute of GlobalAliases is not copied properly.
The bug is masked in higher optimization levels (uncomment --lto-O2) due to GlobalAlias resolution (uses of the alias are replaced with uses of the aliasee).

The submitted patch fixes the issue as far as I can tell, but I'd like to add a test after consulting with someone more knowledgeable in these areas of the code than I.
If the patch makes sense, could you point me to the correct place to add this test?

  //
  // main.c
  //
  #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
  
  extern __thread int tlsvar attribute_tls_model_ie;
  extern __thread int tlsvar2 attribute_tls_model_ie;
  
  void foo()
  {
  	tlsvar2 = 5;
  }
  
  //
  // tlsvar.c
  //
  #define attribute_hidden __attribute__ ((visibility ("hidden")))
  #define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
  
  __thread int tlsvar attribute_tls_model_ie;
  extern __thread int tlsvar2 __attribute__ ((alias ("tlsvar")))
    attribute_hidden attribute_tls_model_ie;
  
  //
  // build.sh
  //
  #!/bin/bash -eu
  
  _CC="clang-10"
  _LTO_OPT="-Xlinker --lto-O0"
  #_LTO_OPT="-Xlinker --lto-O2"
  
  ${_CC} -fPIC -flto -c main.c -o main.c.o
  ${_CC} -fPIC -flto -c tlsvar.c -o tlsvar.c.o
  ${_CC} -fPIC -flto -shared ${_LTO_OPT} -fuse-ld=lld main.c.o tlsvar.c.o -o main

Regards,
Itay


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81605

Files:
  llvm/include/llvm/IR/GlobalAlias.h


Index: llvm/include/llvm/IR/GlobalAlias.h
===================================================================
--- llvm/include/llvm/IR/GlobalAlias.h
+++ llvm/include/llvm/IR/GlobalAlias.h
@@ -60,6 +60,7 @@
 
   void copyAttributesFrom(const GlobalValue *Src) {
     GlobalValue::copyAttributesFrom(Src);
+    setThreadLocalMode(Src->getThreadLocalMode());
   }
 
   /// removeFromParent - This method unlinks 'this' from the containing module,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81605.269916.patch
Type: text/x-patch
Size: 444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200610/2ee5ca97/attachment-0001.bin>


More information about the llvm-commits mailing list