Skip to content

Commit 68df812

Browse files
committedSep 4, 2018
[MinGW] Move code for indicating "potentially not DSO local" into shouldAssumeDSOLocal. NFC.
On Windows, if shouldAssumeDSOLocal returns false, it's either a dllimport reference, or a reference that we should treat as non-local and create a stub for. Clean up AArch64Subtarget::ClassifyGlobalReference a little while touching the flag handling relating to dllimport. Differential Revision: https://reviews.llvm.org/D51590 llvm-svn: 341402
1 parent fed420d commit 68df812

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed
 

‎llvm/lib/Target/AArch64/AArch64Subtarget.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,22 @@ AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV,
196196
if (TM.getCodeModel() == CodeModel::Large && isTargetMachO())
197197
return AArch64II::MO_GOT;
198198

199-
unsigned Flags = AArch64II::MO_NO_FLAG;
200-
if (GV->hasDLLImportStorageClass())
201-
Flags = AArch64II::MO_DLLIMPORT;
202-
else if (getTargetTriple().isWindowsGNUEnvironment() &&
203-
!GV->isDSOLocal() && GV->isDeclarationForLinker() &&
204-
isa<GlobalVariable>(GV))
205-
Flags = AArch64II::MO_COFFSTUB | AArch64II::MO_GOT;
206-
207-
if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
208-
return AArch64II::MO_GOT | Flags;
199+
if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) {
200+
if (GV->hasDLLImportStorageClass())
201+
return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT;
202+
if (getTargetTriple().isOSWindows())
203+
return AArch64II::MO_GOT | AArch64II::MO_COFFSTUB;
204+
return AArch64II::MO_GOT;
205+
}
209206

210207
// The small code model's direct accesses use ADRP, which cannot
211208
// necessarily produce the value 0 (if the code is above 4GB).
212209
// Same for the tiny code model, where we have a pc relative LDR.
213210
if ((useSmallAddressing() || TM.getCodeModel() == CodeModel::Tiny) &&
214211
GV->hasExternalWeakLinkage())
215-
return AArch64II::MO_GOT | Flags;
212+
return AArch64II::MO_GOT;
216213

217-
return Flags;
214+
return AArch64II::MO_NO_FLAG;
218215
}
219216

220217
unsigned char AArch64Subtarget::classifyGlobalFunctionReference(

‎llvm/lib/Target/ARM/ARMISelLowering.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3317,13 +3317,12 @@ SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op,
33173317
assert(!Subtarget->isROPI() && !Subtarget->isRWPI() &&
33183318
"ROPI/RWPI not currently supported for Windows");
33193319

3320+
const TargetMachine &TM = getTargetMachine();
33203321
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
33213322
ARMII::TOF TargetFlags = ARMII::MO_NO_FLAG;
33223323
if (GV->hasDLLImportStorageClass())
33233324
TargetFlags = ARMII::MO_DLLIMPORT;
3324-
else if (Subtarget->getTargetTriple().isWindowsGNUEnvironment() &&
3325-
!GV->isDSOLocal() && GV->isDeclarationForLinker() &&
3326-
isa<GlobalVariable>(GV))
3325+
else if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
33273326
TargetFlags = ARMII::MO_COFFSTUB;
33283327
EVT PtrVT = getPointerTy(DAG.getDataLayout());
33293328
SDValue Result;

‎llvm/lib/Target/TargetMachine.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
141141
if (GV && GV->hasDLLImportStorageClass())
142142
return false;
143143

144+
// On MinGW, variables that haven't been declared with DLLImport may still
145+
// end up automatically imported by the linker. To make this feasible,
146+
// don't assume the variables to be DSO local unless we actually know
147+
// that for sure. This only has to be done for variables; for functions
148+
// the linker can insert thunks for calling functions from another DLL.
149+
if (TT.isWindowsGNUEnvironment() && GV && GV->isDeclarationForLinker() &&
150+
isa<GlobalVariable>(GV))
151+
return false;
152+
144153
// Every other GV is local on COFF.
145154
// Make an exception for windows OS in the triple: Some firmware builds use
146155
// *-win32-macho triples. This (accidentally?) produced windows relocations

‎llvm/lib/Target/X86/X86Subtarget.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,14 @@ unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV,
138138
}
139139
}
140140

141-
// For MinGW, if a data reference isn't marked as DSO local or DLLImport,
142-
// and it's a pure declaration without a definition, it might potentially
143-
// be automatically imported from another DLL, thus route accesses via a stub.
144-
if (isTargetWindowsGNU() && GV && !GV->isDSOLocal() &&
145-
!GV->hasDLLImportStorageClass() && GV->isDeclarationForLinker() &&
146-
isa<GlobalVariable>(GV))
147-
return X86II::MO_COFFSTUB;
148-
149141
if (TM.shouldAssumeDSOLocal(M, GV))
150142
return classifyLocalReference(GV);
151143

152-
if (isTargetCOFF())
153-
return X86II::MO_DLLIMPORT;
144+
if (isTargetCOFF()) {
145+
if (GV->hasDLLImportStorageClass())
146+
return X86II::MO_DLLIMPORT;
147+
return X86II::MO_COFFSTUB;
148+
}
154149

155150
if (is64Bit()) {
156151
// ELF supports a large, truly PIC code model with non-PC relative GOT

0 commit comments

Comments
 (0)