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() && 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: 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@PLT + +@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-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 + +@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}