Skip to content

Commit 61c44f1

Browse files
committed
[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
1 parent 057564f commit 61c44f1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

llvm/lib/Target/X86/X86FastISel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,6 +3519,10 @@ bool X86FastISel::fastLowerCall(CallLoweringInfo &CLI) {
35193519
assert(GV && "Not a direct call");
35203520
// See if we need any target-specific flags on the GV operand.
35213521
unsigned char OpFlags = Subtarget->classifyGlobalFunctionReference(GV);
3522+
if (OpFlags == X86II::MO_PLT && !Is64Bit &&
3523+
TM.getRelocationModel() == Reloc::Static && isa<Function>(GV) &&
3524+
cast<Function>(GV)->isIntrinsic())
3525+
OpFlags = X86II::MO_NO_FLAG;
35223526

35233527
// This will be a direct call, or an indirect call through memory for
35243528
// NonLazyBind calls or dllimport calls.

llvm/test/CodeGen/X86/fast-isel-call.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: llc < %s -O0 -fast-isel-abort=1 -mtriple=i686-apple-darwin8 2>/dev/null | FileCheck %s
22
; RUN: llc < %s -O0 -fast-isel-abort=1 -mtriple=i686-apple-darwin8 2>&1 >/dev/null | FileCheck -check-prefix=STDERR -allow-empty %s
3+
; RUN: llc < %s -O0 -fast-isel-abort=1 -mtriple=i686 2>/dev/null | FileCheck %s --check-prefix=ELF
34

45
%struct.s = type {i32, i32, i32}
56

@@ -41,6 +42,9 @@ define void @test3(ptr %a) {
4142
; CHECK: movl $0, 4(%esp)
4243
; CHECK: movl $100, 8(%esp)
4344
; CHECK: calll {{.*}}memset
45+
46+
; ELF-LABEL: test3:
47+
; ELF: calll memset{{$}}
4448
}
4549

4650
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) {
5357
; CHECK: movl {{.*}}, 4(%esp)
5458
; CHECK: movl $100, 8(%esp)
5559
; CHECK: calll {{.*}}memcpy
60+
61+
; ELF-LABEL: test4:
62+
; ELF: calll memcpy{{$}}
5663
}
5764

5865
; STDERR-NOT: FastISel missed call: call x86_thiscallcc void @thiscallfun

0 commit comments

Comments
 (0)