[llvm] 952ee0d - ThinLTOBitcodeWriter: drop dso_local when a GlobalVariable is converted to a declaration

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 18:12:26 PST 2020


Author: Fangrui Song
Date: 2020-03-05T18:09:33-08:00
New Revision: 952ee0df9ef9a690cd9daec0f93f5f16363d3529

URL: https://github.com/llvm/llvm-project/commit/952ee0df9ef9a690cd9daec0f93f5f16363d3529
DIFF: https://github.com/llvm/llvm-project/commit/952ee0df9ef9a690cd9daec0f93f5f16363d3529.diff

LOG: ThinLTOBitcodeWriter: drop dso_local when a GlobalVariable is converted to a declaration

If we infer the dso_local flag for -fpic, dso_local should be dropped
when we convert a GlobalVariable a declaration. dso_local causes the
generation of direct access (e.g. R_X86_64_PC32). Such relocations referencing
STB_GLOBAL STV_DEFAULT objects are not allowed in a -shared link.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D74749

Added: 
    llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll

Modified: 
    llvm/lib/Transforms/IPO/FunctionImport.cpp
    llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 55b5c0377f28..792c14d49b7c 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -992,6 +992,8 @@ bool llvm::convertToDeclaration(GlobalValue &GV) {
     GV.replaceAllUsesWith(NewGV);
     return false;
   }
+  if (!GV.isImplicitDSOLocal())
+    GV.setDSOLocal(false);
   return true;
 }
 

diff  --git a/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll b/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
index e717fcee4bb7..bc3e8eed4d42 100644
--- a/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
+++ b/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
@@ -7,12 +7,14 @@
 ; var2 is not prevailing and here we check it is not inlined.
 
 ; Check 'var2' was not inlined.
-; RUN: llvm-objdump -d %t2.o.1 | FileCheck %s
+; RUN: llvm-objdump -d -r %t2.o.1 | FileCheck %s
 ; CHECK:      <testVar1>:
 ; CHECK-NEXT:   movl $10, %eax
 ; CHECK-NEXT:   retq
 ; CHECK:      <testVar2>:
-; CHECK-NEXT:   movl  (%rip), %eax
+; CHECK-NEXT:   movq  (%rip), %rax
+; CHECK-NEXT:     R_X86_64_GOTPCREL var2-0x4
+; CHECK-NEXT:   movl  (%rax), %eax
 ; CHECK-NEXT:   retq
 
 ; Check 'var2' is undefined.

diff  --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll
new file mode 100644
index 000000000000..78dfba4d87d7
--- /dev/null
+++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/split-dsolocal.ll
@@ -0,0 +1,23 @@
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
+; RUN: llvm-modextract -b -n 0 -o %t0.bc %t
+; RUN: llvm-modextract -b -n 1 -o %t1.bc %t
+; RUN: llvm-dis -o - %t0.bc | FileCheck --check-prefix=M0 %s
+; RUN: llvm-dis -o - %t1.bc | FileCheck --check-prefix=M1 %s
+
+; M0: @default = external constant [1 x i8]
+; M0: @hidden = external hidden constant [1 x i8]
+; M0: @al = external global [1 x i8]
+
+; M1: @default = dso_local constant [1 x i8] c"0", !type !0
+; M1: @hidden = hidden constant [1 x i8] c"0", !type !0
+; M1: @al = dso_local alias [1 x i8], [1 x i8]* @default
+ at default = dso_local constant [1 x i8] c"0", !type !0
+ at hidden = dso_local hidden constant [1 x i8] c"0", !type !0
+
+ at al = dso_local alias [1 x i8], [1 x i8]* @default
+
+define [1 x i8]* @f_default() { ret [1 x i8]* @default }
+define [1 x i8]* @f_hidden() { ret [1 x i8]* @hidden }
+define [1 x i8]* @f_al() { ret [1 x i8]* @al }
+
+!0 = !{i32 0, !"typeid"}


        


More information about the llvm-commits mailing list