[llvm] 61c44f1 - [X86] FastISel -fno-pic: emit R_386_PC32 when calling an intrinsic

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 10 15:03:41 PDT 2023


Author: Fangrui Song
Date: 2023-09-10T15:03:36-07:00
New Revision: 61c44f1822d6c3dec0938b5b5a3dd300e856f44a

URL: https://github.com/llvm/llvm-project/commit/61c44f1822d6c3dec0938b5b5a3dd300e856f44a
DIFF: https://github.com/llvm/llvm-project/commit/61c44f1822d6c3dec0938b5b5a3dd300e856f44a.diff

LOG: [X86] FastISel -fno-pic: emit R_386_PC32 when calling an intrinsic

This matches how a SelectionDAG::getExternalSymbol node is lowered. On x86-32, a
function call in -fno-pic code should emit R_386_PC32 (since ebx is not set up).
When linked as -shared (problematic!), the generated text relocation will work.

Ideally, we should mark IR intrinsics created in
CodeGenFunction::EmitBuiltinExpr as dso_local, but the code structure makes it
not very feasible.

Fix #51078

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86FastISel.cpp
    llvm/test/CodeGen/X86/fast-isel-call.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp
index ff90b402b9b995..04822fc6ecbee6 100644
--- a/llvm/lib/Target/X86/X86FastISel.cpp
+++ b/llvm/lib/Target/X86/X86FastISel.cpp
@@ -3519,6 +3519,10 @@ bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) {
     assert(GV && "Not a direct call");
     // See if we need any target-specific flags on the GV operand.
     unsigned char OpFlags = Subtarget->classifyGlobalFunctionReference(GV);
+    if (OpFlags == X86II::MO_PLT && !Is64Bit &&
+        TM.getRelocationModel() == Reloc::Static && isa<Function>(GV) &&
+        cast<Function>(GV)->isIntrinsic())
+      OpFlags = X86II::MO_NO_FLAG;
 
     // This will be a direct call, or an indirect call through memory for
     // NonLazyBind calls or dllimport calls.

diff  --git a/llvm/test/CodeGen/X86/fast-isel-call.ll b/llvm/test/CodeGen/X86/fast-isel-call.ll
index a9d2bff923a444..84632c65fcc0e0 100644
--- a/llvm/test/CodeGen/X86/fast-isel-call.ll
+++ b/llvm/test/CodeGen/X86/fast-isel-call.ll
@@ -1,5 +1,6 @@
 ; RUN: llc < %s -O0 -fast-isel-abort=1 -mtriple=i686-apple-darwin8 2>/dev/null | FileCheck %s
 ; RUN: llc < %s -O0 -fast-isel-abort=1 -mtriple=i686-apple-darwin8 2>&1 >/dev/null | FileCheck -check-prefix=STDERR -allow-empty %s
+; RUN: llc < %s -O0 -fast-isel-abort=1 -mtriple=i686 2>/dev/null | FileCheck %s --check-prefix=ELF
 
 %struct.s = type {i32, i32, i32}
 
@@ -41,6 +42,9 @@ define void @test3(ptr %a) {
 ; CHECK:   movl	$0, 4(%esp)
 ; CHECK:   movl	$100, 8(%esp)
 ; CHECK:   calll {{.*}}memset
+
+; ELF-LABEL: test3:
+; ELF:         calll memset{{$}}
 }
 
 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
@@ -53,6 +57,9 @@ define void @test4(ptr %a, ptr %b) {
 ; CHECK:   movl	{{.*}}, 4(%esp)
 ; CHECK:   movl	$100, 8(%esp)
 ; CHECK:   calll {{.*}}memcpy
+
+; ELF-LABEL: test4:
+; ELF:         calll memcpy{{$}}
 }
 
 ; STDERR-NOT: FastISel missed call:   call x86_thiscallcc void @thiscallfun


        


More information about the llvm-commits mailing list