Skip to content

Commit ea30756

Browse files
committed
Attribute nonlazybind should not affect calls to functions with hidden visibility.
Differential Revision: https://reviews.llvm.org/D39625 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317639 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d37de6a commit ea30756

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lib/Target/TargetMachine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
167167
if (GV && !GV->isDeclarationForLinker())
168168
return true;
169169

170+
// A symbol marked nonlazybind should not be accessed with a plt. If the
171+
// symbol turns out to be external, the linker will convert a direct
172+
// access to an access via the plt, so don't assume it is local.
173+
const Function *F = dyn_cast_or_null<Function>(GV);
174+
if (F && F->hasFnAttribute(Attribute::NonLazyBind))
175+
return false;
176+
170177
bool IsTLS = GV && GV->isThreadLocal();
171178
bool IsAccessViaCopyRelocs =
172179
Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV);

lib/Target/X86/X86Subtarget.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,6 @@ X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV) const {
144144
unsigned char
145145
X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV,
146146
const Module &M) const {
147-
const Function *F = dyn_cast_or_null<Function>(GV);
148-
149-
// Do not use the PLT when explicitly told to do so for ELF 64-bit
150-
// target.
151-
if (isTargetELF() && is64Bit() && F &&
152-
F->hasFnAttribute(Attribute::NonLazyBind) &&
153-
GV->isDeclarationForLinker())
154-
return X86II::MO_GOTPCREL;
155-
156147
if (TM.shouldAssumeDSOLocal(M, GV))
157148
return X86II::MO_NO_FLAG;
158149

@@ -162,12 +153,16 @@ X86Subtarget::classifyGlobalFunctionReference(const GlobalValue *GV,
162153
return X86II::MO_DLLIMPORT;
163154
}
164155

156+
const Function *F = dyn_cast_or_null<Function>(GV);
157+
165158
if (isTargetELF()) {
166159
if (is64Bit() && F && (CallingConv::X86_RegCall == F->getCallingConv()))
167160
// According to psABI, PLT stub clobbers XMM8-XMM15.
168161
// In Regcall calling convention those registers are used for passing
169162
// parameters. Thus we need to prevent lazy binding in Regcall.
170163
return X86II::MO_GOTPCREL;
164+
if (F && F->hasFnAttribute(Attribute::NonLazyBind) && is64Bit())
165+
return X86II::MO_GOTPCREL;
171166
return X86II::MO_PLT;
172167
}
173168

test/CodeGen/X86/no-plt.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
define i32 @main() #0 {
77
; X64: callq *_Z3foov@GOTPCREL(%rip)
88
; X64: callq _Z3barv
9+
; X64: callq _Z3bazv
910

1011
entry:
1112
%retval = alloca i32, align 4
1213
store i32 0, i32* %retval, align 4
1314
%call1 = call i32 @_Z3foov()
1415
%call2 = call i32 @_Z3barv()
16+
%call3 = call i32 @_Z3bazv()
1517
ret i32 0
1618
}
1719

@@ -20,4 +22,9 @@ declare i32 @_Z3foov() #1
2022

2123
declare i32 @_Z3barv() #2
2224

25+
; Function Attrs: nonlazybind
26+
declare hidden i32 @_Z3bazv() #3
27+
28+
2329
attributes #1 = { nonlazybind }
30+
attributes #3 = { nonlazybind }

0 commit comments

Comments
 (0)