[llvm-branch-commits] [llvm] 109e70d - [TargetMachine] Drop implied dso_local for an edge case (extern_weak + non-pic + hidden)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Dec 5 15:56:45 PST 2020


Author: Fangrui Song
Date: 2020-12-05T15:52:33-08:00
New Revision: 109e70d357284f612fbe69d213b002366dd67927

URL: https://github.com/llvm/llvm-project/commit/109e70d357284f612fbe69d213b002366dd67927
DIFF: https://github.com/llvm/llvm-project/commit/109e70d357284f612fbe69d213b002366dd67927.diff

LOG: [TargetMachine] Drop implied dso_local for an edge case (extern_weak + non-pic + hidden)

This does not deserve special handling. The code should be added to Clang
instead if deemed useful. With this simplification, we can additionally delete
the PIC extern_weak special case.

Added: 
    

Modified: 
    llvm/lib/Target/TargetMachine.cpp
    llvm/test/CodeGen/ARM/hidden-vis-3.ll
    llvm/test/CodeGen/X86/hidden-vis-3.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index 3b48fd3622dc..ad0e90125258 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -143,16 +143,6 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
   if (TT.isOSBinFormatCOFF() || TT.isOSWindows())
     return true;
 
-  // Most PIC code sequences that assume that a symbol is local cannot
-  // produce a 0 if it turns out the symbol is undefined. While this
-  // is ABI and relocation depended, it seems worth it to handle it
-  // here.
-  if (isPositionIndependent() && GV->hasExternalWeakLinkage())
-    return false;
-
-  if (!GV->hasDefaultVisibility())
-    return true;
-
   if (TT.isOSBinFormatMachO()) {
     if (RM == Reloc::Static)
       return true;

diff  --git a/llvm/test/CodeGen/ARM/hidden-vis-3.ll b/llvm/test/CodeGen/ARM/hidden-vis-3.ll
index 0cf2f779704d..148502686a1a 100644
--- a/llvm/test/CodeGen/ARM/hidden-vis-3.ll
+++ b/llvm/test/CodeGen/ARM/hidden-vis-3.ll
@@ -7,8 +7,9 @@ define i32 @t() nounwind readonly {
 entry:
 ; CHECK: LCPI0_0:
 ; CHECK-NEXT: .long _x
+;; .long _y can be used if @y is dso_local.
 ; CHECK: LCPI0_1:
-; CHECK-NEXT: .long _y
+; CHECK-NEXT: .long L_y$non_lazy_ptr
 
 	%0 = load i32, i32* @x, align 4		; <i32> [#uses=1]
 	%1 = load i32, i32* @y, align 4		; <i32> [#uses=1]

diff  --git a/llvm/test/CodeGen/X86/hidden-vis-3.ll b/llvm/test/CodeGen/X86/hidden-vis-3.ll
index 3137b936f5be..baad2a080aa0 100644
--- a/llvm/test/CodeGen/X86/hidden-vis-3.ll
+++ b/llvm/test/CodeGen/X86/hidden-vis-3.ll
@@ -6,8 +6,10 @@
 
 define i32 @t() nounwind readonly {
 entry:
+;; movl _y, %eax can be used if @y is dso_local.
 ; X32: _t:
-; X32: movl _y, %eax
+; X32:      movl L_y$non_lazy_ptr, %eax
+; X32-NEXT: movl (%eax), %eax
 
 ; X64: _t:
 ; X64: movq _y at GOTPCREL(%rip), %rax


        


More information about the llvm-branch-commits mailing list