Skip to content

Commit

Permalink
[X86] FastISel -fno-pic: emit R_386_PC32 when calling an intrinsic
Browse files Browse the repository at this point in the history
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 llvm#51078
  • Loading branch information
MaskRay committed Sep 10, 2023
1 parent 057564f commit 61c44f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Target/X86/X86FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions llvm/test/CodeGen/X86/fast-isel-call.ll
Original file line number Diff line number Diff line change
@@ -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}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 61c44f1

Please sign in to comment.