mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	Move dllimport name mangling to IR mangler.
This ensures that LTO clients see the correct external symbol name. Differential Revision: http://reviews.llvm.org/D10318 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239437 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -112,6 +112,10 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // dllimported symbols have a __imp_ prefix.
 | 
				
			||||||
 | 
					  if (GV->hasDLLImportStorageClass())
 | 
				
			||||||
 | 
					    OS << "__imp_";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  StringRef Name = GV->getName();
 | 
					  StringRef Name = GV->getName();
 | 
				
			||||||
  char Prefix = DL->getGlobalPrefix();
 | 
					  char Prefix = DL->getGlobalPrefix();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -851,16 +851,7 @@ MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
 | 
				
			|||||||
  } else if (Subtarget->isTargetCOFF()) {
 | 
					  } else if (Subtarget->isTargetCOFF()) {
 | 
				
			||||||
    assert(Subtarget->isTargetWindows() &&
 | 
					    assert(Subtarget->isTargetWindows() &&
 | 
				
			||||||
           "Windows is the only supported COFF target");
 | 
					           "Windows is the only supported COFF target");
 | 
				
			||||||
 | 
					    return getSymbol(GV);
 | 
				
			||||||
    bool IsIndirect = (TargetFlags & ARMII::MO_DLLIMPORT);
 | 
					 | 
				
			||||||
    if (!IsIndirect)
 | 
					 | 
				
			||||||
      return getSymbol(GV);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    SmallString<128> Name;
 | 
					 | 
				
			||||||
    Name = "__imp_";
 | 
					 | 
				
			||||||
    getNameWithPrefix(Name, GV);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return OutContext.getOrCreateSymbol(Name);
 | 
					 | 
				
			||||||
  } else if (Subtarget->isTargetELF()) {
 | 
					  } else if (Subtarget->isTargetELF()) {
 | 
				
			||||||
    return getSymbol(GV);
 | 
					    return getSymbol(GV);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1751,11 +1751,8 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
 | 
				
			|||||||
    } else if (Subtarget->isTargetCOFF()) {
 | 
					    } else if (Subtarget->isTargetCOFF()) {
 | 
				
			||||||
      assert(Subtarget->isTargetWindows() &&
 | 
					      assert(Subtarget->isTargetWindows() &&
 | 
				
			||||||
             "Windows is the only supported COFF target");
 | 
					             "Windows is the only supported COFF target");
 | 
				
			||||||
      unsigned TargetFlags = GV->hasDLLImportStorageClass()
 | 
					 | 
				
			||||||
                                 ? ARMII::MO_DLLIMPORT
 | 
					 | 
				
			||||||
                                 : ARMII::MO_NO_FLAG;
 | 
					 | 
				
			||||||
      Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), /*Offset=*/0,
 | 
					      Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), /*Offset=*/0,
 | 
				
			||||||
                                          TargetFlags);
 | 
					                                          ARMII::MO_NO_FLAG);
 | 
				
			||||||
      if (GV->hasDLLImportStorageClass())
 | 
					      if (GV->hasDLLImportStorageClass())
 | 
				
			||||||
        Callee = DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
 | 
					        Callee = DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
 | 
				
			||||||
                             DAG.getNode(ARMISD::Wrapper, dl, getPointerTy(),
 | 
					                             DAG.getNode(ARMISD::Wrapper, dl, getPointerTy(),
 | 
				
			||||||
@@ -2646,8 +2643,6 @@ SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op,
 | 
				
			|||||||
         "Windows on ARM expects to use movw/movt");
 | 
					         "Windows on ARM expects to use movw/movt");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
 | 
					  const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
 | 
				
			||||||
  const ARMII::TOF TargetFlags =
 | 
					 | 
				
			||||||
    (GV->hasDLLImportStorageClass() ? ARMII::MO_DLLIMPORT : ARMII::MO_NO_FLAG);
 | 
					 | 
				
			||||||
  EVT PtrVT = getPointerTy();
 | 
					  EVT PtrVT = getPointerTy();
 | 
				
			||||||
  SDValue Result;
 | 
					  SDValue Result;
 | 
				
			||||||
  SDLoc DL(Op);
 | 
					  SDLoc DL(Op);
 | 
				
			||||||
@@ -2658,7 +2653,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op,
 | 
				
			|||||||
  // operands, expand this into two nodes.
 | 
					  // operands, expand this into two nodes.
 | 
				
			||||||
  Result = DAG.getNode(ARMISD::Wrapper, DL, PtrVT,
 | 
					  Result = DAG.getNode(ARMISD::Wrapper, DL, PtrVT,
 | 
				
			||||||
                       DAG.getTargetGlobalAddress(GV, DL, PtrVT, /*Offset=*/0,
 | 
					                       DAG.getTargetGlobalAddress(GV, DL, PtrVT, /*Offset=*/0,
 | 
				
			||||||
                                                  TargetFlags));
 | 
					                                                  ARMII::MO_NO_FLAG));
 | 
				
			||||||
  if (GV->hasDLLImportStorageClass())
 | 
					  if (GV->hasDLLImportStorageClass())
 | 
				
			||||||
    Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Result,
 | 
					    Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Result,
 | 
				
			||||||
                         MachinePointerInfo::getGOT(), false, false, false, 0);
 | 
					                         MachinePointerInfo::getGOT(), false, false, false, 0);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -297,17 +297,12 @@ namespace ARMII {
 | 
				
			|||||||
    /// just that part of the flag set.
 | 
					    /// just that part of the flag set.
 | 
				
			||||||
    MO_OPTION_MASK = 0x3f,
 | 
					    MO_OPTION_MASK = 0x3f,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// MO_DLLIMPORT - On a symbol operand, this represents that the reference
 | 
					 | 
				
			||||||
    /// to the symbol is for an import stub.  This is used for DLL import
 | 
					 | 
				
			||||||
    /// storage class indication on Windows.
 | 
					 | 
				
			||||||
    MO_DLLIMPORT = 0x40,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// MO_NONLAZY - This is an independent flag, on a symbol operand "FOO" it
 | 
					    /// MO_NONLAZY - This is an independent flag, on a symbol operand "FOO" it
 | 
				
			||||||
    /// represents a symbol which, if indirect, will get special Darwin mangling
 | 
					    /// represents a symbol which, if indirect, will get special Darwin mangling
 | 
				
			||||||
    /// as a non-lazy-ptr indirect symbol (i.e. "L_FOO$non_lazy_ptr"). Can be
 | 
					    /// as a non-lazy-ptr indirect symbol (i.e. "L_FOO$non_lazy_ptr"). Can be
 | 
				
			||||||
    /// combined with MO_LO16, MO_HI16 or MO_NO_FLAG (in a constant-pool, for
 | 
					    /// combined with MO_LO16, MO_HI16 or MO_NO_FLAG (in a constant-pool, for
 | 
				
			||||||
    /// example).
 | 
					    /// example).
 | 
				
			||||||
    MO_NONLAZY = 0x80,
 | 
					    MO_NONLAZY = 0x40,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // It's undefined behaviour if an enum overflows the range between its
 | 
					    // It's undefined behaviour if an enum overflows the range between its
 | 
				
			||||||
    // smallest and largest values, but since these are |ed together, it can
 | 
					    // smallest and largest values, but since these are |ed together, it can
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,11 +94,6 @@ static void printSymbolOperand(X86AsmPrinter &P, const MachineOperand &MO,
 | 
				
			|||||||
    else
 | 
					    else
 | 
				
			||||||
      GVSym = P.getSymbol(GV);
 | 
					      GVSym = P.getSymbol(GV);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Handle dllimport linkage.
 | 
					 | 
				
			||||||
    if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
 | 
					 | 
				
			||||||
      GVSym =
 | 
					 | 
				
			||||||
          P.OutContext.getOrCreateSymbol(Twine("__imp_") + GVSym->getName());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
 | 
					    if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
 | 
				
			||||||
        MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
 | 
					        MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
 | 
				
			||||||
      MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
 | 
					      MCSymbol *Sym = P.getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -133,10 +133,6 @@ GetSymbolFromOperand(const MachineOperand &MO) const {
 | 
				
			|||||||
  StringRef Suffix;
 | 
					  StringRef Suffix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (MO.getTargetFlags()) {
 | 
					  switch (MO.getTargetFlags()) {
 | 
				
			||||||
  case X86II::MO_DLLIMPORT:
 | 
					 | 
				
			||||||
    // Handle dllimport linkage.
 | 
					 | 
				
			||||||
    Name += "__imp_";
 | 
					 | 
				
			||||||
    break;
 | 
					 | 
				
			||||||
  case X86II::MO_DARWIN_STUB:
 | 
					  case X86II::MO_DARWIN_STUB:
 | 
				
			||||||
    Suffix = "$stub";
 | 
					    Suffix = "$stub";
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										17
									
								
								test/Object/dllimport.ll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								test/Object/dllimport.ll
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					; RUN: llvm-as %s -o - | llvm-nm - | FileCheck %s
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
 | 
				
			||||||
 | 
					target triple = "x86_64-pc-windows-msvc"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; CHECK: U __imp_f
 | 
				
			||||||
 | 
					; CHECK: U __imp_v
 | 
				
			||||||
 | 
					; CHECK: T g
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare dllimport void @f()
 | 
				
			||||||
 | 
					@v = external dllimport global i32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @g() {
 | 
				
			||||||
 | 
					  call void @f()
 | 
				
			||||||
 | 
					  store i32 42, i32* @v
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user