diff options
| author | Martin Storsjo <martin@martin.st> | 2018-09-04 20:56:28 +0000 |
|---|---|---|
| committer | Martin Storsjo <martin@martin.st> | 2018-09-04 20:56:28 +0000 |
| commit | 68df812cceaccda7cc0d83aa38db3225b3b53652 (patch) | |
| tree | 53f7cdcb7a7fbf853faa36beb7793848c3ec5515 | |
| parent | fed420d6b6769bc0b97755345f1072fcb530fb89 (diff) | |
| download | llvm-68df812cceaccda7cc0d83aa38db3225b3b53652.zip llvm-68df812cceaccda7cc0d83aa38db3225b3b53652.tar.gz llvm-68df812cceaccda7cc0d83aa38db3225b3b53652.tar.bz2 | |
[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
| -rw-r--r-- | llvm/lib/Target/AArch64/AArch64Subtarget.cpp | 21 | ||||
| -rw-r--r-- | llvm/lib/Target/ARM/ARMISelLowering.cpp | 5 | ||||
| -rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 9 | ||||
| -rw-r--r-- | llvm/lib/Target/X86/X86Subtarget.cpp | 15 |
4 files changed, 25 insertions, 25 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp index 78eb347..f4e1e39 100644 --- a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp +++ b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp @@ -196,25 +196,22 @@ AArch64Subtarget::ClassifyGlobalReference(const GlobalValue *GV, if (TM.getCodeModel() == CodeModel::Large && isTargetMachO()) return AArch64II::MO_GOT; - unsigned Flags = AArch64II::MO_NO_FLAG; - if (GV->hasDLLImportStorageClass()) - Flags = AArch64II::MO_DLLIMPORT; - else if (getTargetTriple().isWindowsGNUEnvironment() && - !GV->isDSOLocal() && GV->isDeclarationForLinker() && - isa<GlobalVariable>(GV)) - Flags = AArch64II::MO_COFFSTUB | AArch64II::MO_GOT; - - if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) - return AArch64II::MO_GOT | Flags; + if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) { + if (GV->hasDLLImportStorageClass()) + return AArch64II::MO_GOT | AArch64II::MO_DLLIMPORT; + if (getTargetTriple().isOSWindows()) + return AArch64II::MO_GOT | AArch64II::MO_COFFSTUB; + return AArch64II::MO_GOT; + } // The small code model's direct accesses use ADRP, which cannot // necessarily produce the value 0 (if the code is above 4GB). // Same for the tiny code model, where we have a pc relative LDR. if ((useSmallAddressing() || TM.getCodeModel() == CodeModel::Tiny) && GV->hasExternalWeakLinkage()) - return AArch64II::MO_GOT | Flags; + return AArch64II::MO_GOT; - return Flags; + return AArch64II::MO_NO_FLAG; } unsigned char AArch64Subtarget::classifyGlobalFunctionReference( diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 26f23c5..4fed202 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -3317,13 +3317,12 @@ SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op, assert(!Subtarget->isROPI() && !Subtarget->isRWPI() && "ROPI/RWPI not currently supported for Windows"); + const TargetMachine &TM = getTargetMachine(); const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); ARMII::TOF TargetFlags = ARMII::MO_NO_FLAG; if (GV->hasDLLImportStorageClass()) TargetFlags = ARMII::MO_DLLIMPORT; - else if (Subtarget->getTargetTriple().isWindowsGNUEnvironment() && - !GV->isDSOLocal() && GV->isDeclarationForLinker() && - isa<GlobalVariable>(GV)) + else if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV)) TargetFlags = ARMII::MO_COFFSTUB; EVT PtrVT = getPointerTy(DAG.getDataLayout()); SDValue Result; diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index 092f5ea..b3de6c1 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -141,6 +141,15 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, if (GV && GV->hasDLLImportStorageClass()) return false; + // On MinGW, variables that haven't been declared with DLLImport may still + // end up automatically imported by the linker. To make this feasible, + // don't assume the variables to be DSO local unless we actually know + // that for sure. This only has to be done for variables; for functions + // the linker can insert thunks for calling functions from another DLL. + if (TT.isWindowsGNUEnvironment() && GV && GV->isDeclarationForLinker() && + isa<GlobalVariable>(GV)) + return false; + // Every other GV is local on COFF. // Make an exception for windows OS in the triple: Some firmware builds use // *-win32-macho triples. This (accidentally?) produced windows relocations diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp index c3503a3..0c9ce88 100644 --- a/llvm/lib/Target/X86/X86Subtarget.cpp +++ b/llvm/lib/Target/X86/X86Subtarget.cpp @@ -138,19 +138,14 @@ unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV, } } - // For MinGW, if a data reference isn't marked as DSO local or DLLImport, - // and it's a pure declaration without a definition, it might potentially - // be automatically imported from another DLL, thus route accesses via a stub. - if (isTargetWindowsGNU() && GV && !GV->isDSOLocal() && - !GV->hasDLLImportStorageClass() && GV->isDeclarationForLinker() && - isa<GlobalVariable>(GV)) - return X86II::MO_COFFSTUB; - if (TM.shouldAssumeDSOLocal(M, GV)) return classifyLocalReference(GV); - if (isTargetCOFF()) - return X86II::MO_DLLIMPORT; + if (isTargetCOFF()) { + if (GV->hasDLLImportStorageClass()) + return X86II::MO_DLLIMPORT; + return X86II::MO_COFFSTUB; + } if (is64Bit()) { // ELF supports a large, truly PIC code model with non-PC relative GOT |
