[PATCH] D13481: [X86] Call locally defined function directly for PIE

H.J Lu via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 13:07:37 PDT 2015


hjl.tools created this revision.
hjl.tools added a subscriber: llvm-commits.
hjl.tools set the repository for this revision to rL LLVM.

There is no need to use PLT to call locally defined function for PIE
since locally defined function in PIE can't be preempted.

Fixes PR 24970.

Repository:
  rL LLVM

http://reviews.llvm.org/D13481

Files:
  lib/Target/X86/X86FastISel.cpp
  lib/Target/X86/X86ISelLowering.cpp
  test/CodeGen/X86/pie-1.ll
  test/CodeGen/X86/pie-2.ll

Index: test/CodeGen/X86/pie-2.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/pie-2.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s -mcpu=generic -mtriple=i686-linux-gnu -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mcpu=generic -mtriple=i686-linux-gnu -fast-isel -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -fast-isel -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+
+; LINUX:	call{{l|q}}	foo
+
+ at glob = common global i32 0, align 4
+
+; Function Attrs: nounwind uwtable
+define i32 @foo() {
+entry:
+  %0 = load i32, i32* @glob, align 4
+  ret i32 %0
+}
+
+; Function Attrs: nounwind uwtable
+define void @bar() {
+entry:
+  %call = call i32 @foo()
+  store i32 %call, i32* @glob, align 4
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"PIC Level", i32 2}
Index: test/CodeGen/X86/pie-1.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/pie-1.ll
@@ -0,0 +1,27 @@
+; RUN: llc < %s -mcpu=generic -mtriple=i686-linux-gnu -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mcpu=generic -mtriple=i686-linux-gnu -fast-isel -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -fast-isel -relocation-model=pic -asm-verbose=false -enable-pie | FileCheck %s -check-prefix=LINUX
+
+; LINUX-NOT:	call{{l|q}}	foo at PLT
+
+ at glob = common global i32 0, align 4
+
+; Function Attrs: nounwind uwtable
+define i32 @foo() {
+entry:
+  %0 = load i32, i32* @glob, align 4
+  ret i32 %0
+}
+
+; Function Attrs: nounwind uwtable
+define void @bar() {
+entry:
+  %call = call i32 @foo()
+  store i32 %call, i32* @glob, align 4
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"PIC Level", i32 2}
Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -3304,6 +3304,8 @@
       // we don't need to use the PLT - we can directly call it.
       if (Subtarget->isTargetELF() &&
           DAG.getTarget().getRelocationModel() == Reloc::PIC_ &&
+          !(DAG.getTarget().Options.PositionIndependentExecutable &&
+            GV->isStrongDefinitionForLinker()) &&
           GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) {
         OpFlags = X86II::MO_PLT;
       } else if (Subtarget->isPICStyleStubAny() &&
Index: lib/Target/X86/X86FastISel.cpp
===================================================================
--- lib/Target/X86/X86FastISel.cpp
+++ lib/Target/X86/X86FastISel.cpp
@@ -3088,6 +3088,8 @@
     // we don't need to use the PLT - we can directly call it.
     if (Subtarget->isTargetELF() &&
         TM.getRelocationModel() == Reloc::PIC_ &&
+        !(TM.Options.PositionIndependentExecutable &&
+          GV->isStrongDefinitionForLinker()) &&
         GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) {
       OpFlags = X86II::MO_PLT;
     } else if (Subtarget->isPICStyleStubAny() &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13481.36648.patch
Type: text/x-patch
Size: 3600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151006/e0f078fa/attachment.bin>


More information about the llvm-commits mailing list