[llvm-branch-commits] [llvm] 2047c10 - [TargetMachine] Drop implied dso_local for definitions in ELF static relocation model/PIE

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Dec 30 17:02:33 PST 2020


Author: Fangrui Song
Date: 2020-12-30T16:57:50-08:00
New Revision: 2047c10c22b071cccc57a7e2779d6603512e9113

URL: https://github.com/llvm/llvm-project/commit/2047c10c22b071cccc57a7e2779d6603512e9113
DIFF: https://github.com/llvm/llvm-project/commit/2047c10c22b071cccc57a7e2779d6603512e9113.diff

LOG: [TargetMachine] Drop implied dso_local for definitions in ELF static relocation model/PIE

TargetMachine::shouldAssumeDSOLocal currently implies dso_local for such definitions.

Since clang -fno-pic add the dso_local specifier, we don't need to special case.

Added: 
    

Modified: 
    llvm/lib/Target/TargetMachine.cpp
    llvm/test/CodeGen/ARM/fast-isel-intrinsic.ll
    llvm/test/CodeGen/PowerPC/dsolocal-static.ll
    llvm/test/CodeGen/X86/linux-preemption.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp
index b45b8e354b3a..da295a8a3de9 100644
--- a/llvm/lib/Target/TargetMachine.cpp
+++ b/llvm/lib/Target/TargetMachine.cpp
@@ -156,16 +156,6 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
 
   assert(TT.isOSBinFormatELF() || TT.isOSBinFormatWasm());
   assert(RM != Reloc::DynamicNoPIC);
-
-  bool IsExecutable =
-      RM == Reloc::Static || M.getPIELevel() != PIELevel::Default;
-  if (IsExecutable) {
-    // If the symbol is defined, it cannot be preempted.
-    if (!GV->isDeclarationForLinker())
-      return true;
-  }
-
-  // ELF & wasm support preemption of other symbols.
   return false;
 }
 

diff  --git a/llvm/test/CodeGen/ARM/fast-isel-intrinsic.ll b/llvm/test/CodeGen/ARM/fast-isel-intrinsic.ll
index e8ac7b6bbf5e..e739d94cd9ab 100644
--- a/llvm/test/CodeGen/ARM/fast-isel-intrinsic.ll
+++ b/llvm/test/CodeGen/ARM/fast-isel-intrinsic.ll
@@ -61,8 +61,8 @@ define void @t2() nounwind ssp {
 
 ; ARM-ELF: movw [[REG1:r[0-9]+]], :lower16:temp
 ; ARM-ELF: movt [[REG1]], :upper16:temp
-; ARM-ELF:      add r0, [[REG1]], #4
-; ARM-ELF-NEXT: add r1, [[REG1]], #16
+; ARM-ELF:      add [[REG1]], r1, #4
+; ARM-ELF-NEXT: add r1, r1, #16
 
 ; ARM: movw r2, #17
 ; ARM: bl {{_?}}memcpy
@@ -106,7 +106,7 @@ define void @t3() nounwind ssp {
 
 ; ARM-ELF: movw [[REG0:r[0-9]+]], :lower16:temp
 ; ARM-ELF: movt [[REG0]], :upper16:temp
-; ARM-ELF:      add r0, [[REG0]], #4
+; ARM-ELF:      add [[REG0]], r1, #4
 ; ARM-ELF-NEXT: add r1, r1, #16
 
 ; ARM: movw r2, #10

diff  --git a/llvm/test/CodeGen/PowerPC/dsolocal-static.ll b/llvm/test/CodeGen/PowerPC/dsolocal-static.ll
index a4ef632f6877..e5002cc59b30 100644
--- a/llvm/test/CodeGen/PowerPC/dsolocal-static.ll
+++ b/llvm/test/CodeGen/PowerPC/dsolocal-static.ll
@@ -3,8 +3,8 @@
 @default = global i32 55
 define dso_local i32* @get_default_global() {
 ; CHECK-LABEL: get_default_global:
-; CHECK:         addis 3, 2, default at toc@ha
-; CHECK-NEXT:    addi 3, 3, default at toc@l
+; CHECK:         addis 3, 2, .LC{{.*}}@toc at ha
+; CHECK-NEXT:    ld 3, .LC{{.*}}@toc at l(3)
 ; CHECK-NEXT:    blr
   ret i32* @default
 }
@@ -21,8 +21,8 @@ define dso_local i32* @get_local_global() {
 @preemptable_global = dso_preemptable global i32 42
 define dso_local i32* @get_preemptable_global() {
 ; CHECK-LABEL: get_preemptable_global:
-; CHECK:         addis 3, 2, preemptable_global at toc@ha
-; CHECK-NEXT:    addi 3, 3, preemptable_global at toc@l
+; CHECK:         addis 3, 2, .LC{{.*}}@toc at ha
+; CHECK-NEXT:    ld 3, .LC{{.*}}@toc at l(3)
 ; CHECK-NEXT:    blr
   ret i32* @preemptable_global
 }
@@ -63,8 +63,7 @@ define signext i32 @default_function(i32 %i) {
 define dso_local signext i32 @default_function_caller(i32 %i) {
 ; CHECK-LABEL: default_function_caller:
 ; CHECK:         bl default_function
-; CHECK-NOT:     nop
-; CHECK:         blr
+; CHECK-NEXT:    nop
   %call = notail call signext i32 @default_function(i32 signext %i)
   ret i32 %call
 }
@@ -87,8 +86,7 @@ define dso_preemptable signext i32 @preemptable_function(i32 %i) {
 define dso_local signext i32 @preemptable_function_caller(i32 %i) {
 ; CHECK-LABEL: preemptable_function_caller:
 ; CHECK:         bl preemptable_function
-; CHECK-NOT:     nop
-; CHECK:         blr
+; CHECK-NEXT:    nop
   %call = notail call signext i32 @preemptable_function(i32 signext %i)
   ret i32 %call
 }

diff  --git a/llvm/test/CodeGen/X86/linux-preemption.ll b/llvm/test/CodeGen/X86/linux-preemption.ll
index 4739e6cec011..eae14f98cf0d 100644
--- a/llvm/test/CodeGen/X86/linux-preemption.ll
+++ b/llvm/test/CodeGen/X86/linux-preemption.ll
@@ -17,7 +17,7 @@ define i32* @get_strong_default_global() {
   ret i32* @strong_default_global
 }
 ; CHECK: movq strong_default_global at GOTPCREL(%rip), %rax
-; STATIC: movl $strong_default_global, %eax
+; STATIC: movq strong_default_global at GOTPCREL(%rip), %rax
 ; CHECK32: movl strong_default_global at GOT(%eax), %eax
 
 @strong_hidden_global = hidden global i32 42
@@ -33,7 +33,7 @@ define i32* @get_weak_default_global() {
   ret i32* @weak_default_global
 }
 ; CHECK: movq weak_default_global at GOTPCREL(%rip), %rax
-; STATIC: movl $weak_default_global, %eax
+; STATIC: movq weak_default_global at GOTPCREL(%rip), %rax
 ; CHECK32: movl weak_default_global at GOT(%eax), %eax
 
 @external_default_global = external global i32
@@ -74,7 +74,7 @@ define i32* @get_strong_preemptable_global() {
   ret i32* @strong_preemptable_global
 }
 ; CHECK: movq strong_preemptable_global at GOTPCREL(%rip), %rax
-; STATIC: movl $strong_preemptable_global, %eax
+; STATIC: movq strong_preemptable_global at GOTPCREL(%rip), %rax
 ; CHECK32: movl strong_preemptable_global at GOT(%eax), %eax
 
 @weak_preemptable_global = weak dso_preemptable global i32 42
@@ -82,7 +82,7 @@ define i32* @get_weak_preemptable_global() {
   ret i32* @weak_preemptable_global
 }
 ; CHECK: movq weak_preemptable_global at GOTPCREL(%rip), %rax
-; STATIC: movl $weak_preemptable_global, %eax
+; STATIC: movq weak_preemptable_global at GOTPCREL(%rip), %rax
 ; CHECK32: movl weak_preemptable_global at GOT(%eax), %eax
 
 @external_preemptable_global = external dso_preemptable global i32
@@ -101,7 +101,7 @@ define i32* @get_strong_default_alias() {
   ret i32* @strong_default_alias
 }
 ; CHECK: movq strong_default_alias at GOTPCREL(%rip), %rax
-; STATIC: movl $strong_default_alias, %eax
+; STATIC: movq strong_default_alias at GOTPCREL(%rip), %rax
 ; CHECK32: movl strong_default_alias at GOT(%eax), %eax
 
 @strong_hidden_alias = hidden alias i32, i32* @aliasee
@@ -117,7 +117,7 @@ define i32* @get_weak_default_alias() {
   ret i32* @weak_default_alias
 }
 ; CHECK: movq weak_default_alias at GOTPCREL(%rip), %rax
-; STATIC: movl $weak_default_alias, %eax
+; STATIC: movq weak_default_alias at GOTPCREL(%rip), %rax
 ; CHECK32: movl weak_default_alias at GOT(%eax), %eax
 
 @strong_local_alias = dso_local alias i32, i32* @aliasee
@@ -142,7 +142,7 @@ define i32* @get_strong_preemptable_alias() {
   ret i32* @strong_preemptable_alias
 }
 ; CHECK: movq strong_preemptable_alias at GOTPCREL(%rip), %rax
-; STATIC: movl $strong_preemptable_alias, %eax
+; STATIC: movq strong_preemptable_alias at GOTPCREL(%rip), %rax
 ; CHECK32: movl strong_preemptable_alias at GOT(%eax), %eax
 
 @weak_preemptable_alias = weak dso_preemptable alias i32, i32* @aliasee
@@ -150,7 +150,7 @@ define i32* @get_weak_preemptable_alias() {
   ret i32* @weak_preemptable_alias
 }
 ; CHECK: movq weak_preemptable_alias at GOTPCREL(%rip), %rax
-; STATIC: movl $weak_preemptable_alias, %eax
+; STATIC: movq weak_preemptable_alias at GOTPCREL(%rip), %rax
 ; CHECK32: movl weak_preemptable_alias at GOT(%eax), %eax
 
 ; functions
@@ -162,7 +162,7 @@ define void()* @get_strong_default_function() {
   ret void()* @strong_default_function
 }
 ; CHECK: movq strong_default_function at GOTPCREL(%rip), %rax
-; STATIC: movl $strong_default_function, %eax
+; STATIC: movq strong_default_function at GOTPCREL(%rip), %rax
 ; CHECK32: movl strong_default_function at GOT(%eax), %eax
 
 define hidden void @strong_hidden_function() {
@@ -182,7 +182,7 @@ define void()* @get_weak_default_function() {
   ret void()* @weak_default_function
 }
 ; CHECK: movq weak_default_function at GOTPCREL(%rip), %rax
-; STATIC: movl $weak_default_function, %eax
+; STATIC: movq weak_default_function at GOTPCREL(%rip), %rax
 ; CHECK32: movl weak_default_function at GOT(%eax), %eax
 
 declare void @external_default_function()
@@ -231,7 +231,7 @@ define void()* @get_strong_preemptable_function() {
   ret void()* @strong_preemptable_function
 }
 ; CHECK: movq strong_preemptable_function at GOTPCREL(%rip), %rax
-; STATIC: movl $strong_preemptable_function, %eax
+; STATIC: movq strong_preemptable_function at GOTPCREL(%rip), %rax
 ; CHECK32: movl strong_preemptable_function at GOT(%eax), %eax
 
 define weak dso_preemptable void @weak_preemptable_function() {
@@ -241,7 +241,7 @@ define void()* @get_weak_preemptable_function() {
   ret void()* @weak_preemptable_function
 }
 ; CHECK: movq weak_preemptable_function at GOTPCREL(%rip), %rax
-; STATIC: movl $weak_preemptable_function, %eax
+; STATIC: movq weak_preemptable_function at GOTPCREL(%rip), %rax
 ; CHECK32: movl weak_preemptable_function at GOT(%eax), %eax
 
 declare dso_preemptable void @external_preemptable_function()


        


More information about the llvm-branch-commits mailing list