forked from OSchip/llvm-project
				
			convert arm/darwin stubs to use the mangler to synthesize all the names instead of
doing it with printSuffixedName. llvm-svn: 75741
This commit is contained in:
		
							parent
							
								
									12b1d137c2
								
							
						
					
					
						commit
						a2268c0b19
					
				| 
						 | 
					@ -75,9 +75,34 @@ namespace {
 | 
				
			||||||
    /// visibility that require non-lazy-pointers for indirect access.
 | 
					    /// visibility that require non-lazy-pointers for indirect access.
 | 
				
			||||||
    StringMap<std::string> HiddenGVNonLazyPtrs;
 | 
					    StringMap<std::string> HiddenGVNonLazyPtrs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct FnStubInfo {
 | 
				
			||||||
 | 
					      std::string Stub, LazyPtr, SLP, SCV;
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      FnStubInfo() {}
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      void Init(const GlobalValue *GV, Mangler *Mang) {
 | 
				
			||||||
 | 
					        // Already initialized.
 | 
				
			||||||
 | 
					        if (!Stub.empty()) return;
 | 
				
			||||||
 | 
					        Stub = Mang->getMangledName(GV, "$stub", true);
 | 
				
			||||||
 | 
					        LazyPtr = Mang->getMangledName(GV, "$lazy_ptr", true);
 | 
				
			||||||
 | 
					        SLP = Mang->getMangledName(GV, "$slp", true);
 | 
				
			||||||
 | 
					        SCV = Mang->getMangledName(GV, "$scv", true);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      void Init(const std::string &GV, Mangler *Mang) {
 | 
				
			||||||
 | 
					        // Already initialized.
 | 
				
			||||||
 | 
					        if (!Stub.empty()) return;
 | 
				
			||||||
 | 
					        Stub = Mang->makeNameProper(GV+"$stub", true);
 | 
				
			||||||
 | 
					        LazyPtr = Mang->makeNameProper(GV+"$lazy_ptr", true);
 | 
				
			||||||
 | 
					        SLP = Mang->makeNameProper(GV+"$slp", true);
 | 
				
			||||||
 | 
					        SCV = Mang->makeNameProper(GV+"$scv", true);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    /// FnStubs - Keeps the set of external function GlobalAddresses that the
 | 
					    /// FnStubs - Keeps the set of external function GlobalAddresses that the
 | 
				
			||||||
    /// asm printer should generate stubs for.
 | 
					    /// asm printer should generate stubs for.
 | 
				
			||||||
    StringSet<> FnStubs;
 | 
					    StringMap<FnStubInfo> FnStubs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// True if asm printer is printing a series of CONSTPOOL_ENTRY.
 | 
					    /// True if asm printer is printing a series of CONSTPOOL_ENTRY.
 | 
				
			||||||
    bool InCPMode;
 | 
					    bool InCPMode;
 | 
				
			||||||
| 
						 | 
					@ -166,27 +191,23 @@ namespace {
 | 
				
			||||||
          HiddenGVNonLazyPtrs[SymName] = Name;
 | 
					          HiddenGVNonLazyPtrs[SymName] = Name;
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          GVNonLazyPtrs[SymName] = Name;
 | 
					          GVNonLazyPtrs[SymName] = Name;
 | 
				
			||||||
        O << Name;
 | 
					 | 
				
			||||||
      } else if (ACPV->isStub()) {
 | 
					      } else if (ACPV->isStub()) {
 | 
				
			||||||
        //if (GV)
 | 
					        if (GV) {
 | 
				
			||||||
        //Name = Mang->getMangledName(GV, "$stub", true);
 | 
					          FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
 | 
				
			||||||
        //else
 | 
					          FnInfo.Init(GV, Mang);
 | 
				
			||||||
        //Name = Mang->makeNameProper(ACPV->getSymbol()+"$stub", true);
 | 
					          Name = FnInfo.Stub;
 | 
				
			||||||
        
 | 
					        } else {
 | 
				
			||||||
        if (GV)
 | 
					          FnStubInfo &FnInfo = FnStubs[Mang->makeNameProper(ACPV->getSymbol())];
 | 
				
			||||||
          Name = Mang->getMangledName(GV);
 | 
					          FnInfo.Init(ACPV->getSymbol(), Mang);
 | 
				
			||||||
        else
 | 
					          Name = FnInfo.Stub;
 | 
				
			||||||
          Name = Mang->makeNameProper(ACPV->getSymbol());
 | 
					        }
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        FnStubs.insert(Name);
 | 
					 | 
				
			||||||
        printSuffixedName(Name, "$stub");
 | 
					 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        if (GV)
 | 
					        if (GV)
 | 
				
			||||||
          Name = Mang->getMangledName(GV);
 | 
					          Name = Mang->getMangledName(GV);
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          Name = Mang->makeNameProper(ACPV->getSymbol());
 | 
					          Name = Mang->makeNameProper(ACPV->getSymbol());
 | 
				
			||||||
        O << Name;
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      O << Name;
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
| 
						 | 
					@ -345,13 +366,17 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
 | 
				
			||||||
  case MachineOperand::MO_GlobalAddress: {
 | 
					  case MachineOperand::MO_GlobalAddress: {
 | 
				
			||||||
    bool isCallOp = Modifier && !strcmp(Modifier, "call");
 | 
					    bool isCallOp = Modifier && !strcmp(Modifier, "call");
 | 
				
			||||||
    GlobalValue *GV = MO.getGlobal();
 | 
					    GlobalValue *GV = MO.getGlobal();
 | 
				
			||||||
    std::string Name = Mang->getMangledName(GV);
 | 
					    std::string Name;
 | 
				
			||||||
    bool isExt = GV->isDeclaration() || GV->isWeakForLinker();
 | 
					    bool isExt = GV->isDeclaration() || GV->isWeakForLinker();
 | 
				
			||||||
    if (isExt && isCallOp && Subtarget->isTargetDarwin() &&
 | 
					    if (isExt && isCallOp && Subtarget->isTargetDarwin() &&
 | 
				
			||||||
        TM.getRelocationModel() != Reloc::Static) {
 | 
					        TM.getRelocationModel() != Reloc::Static) {
 | 
				
			||||||
      printSuffixedName(Name, "$stub");
 | 
					      FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
 | 
				
			||||||
      FnStubs.insert(Name);
 | 
					      FnInfo.Init(GV, Mang);
 | 
				
			||||||
    } else
 | 
					      Name = FnInfo.Stub;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      Name = Mang->getMangledName(GV);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    O << Name;
 | 
					    O << Name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    printOffset(MO.getOffset());
 | 
					    printOffset(MO.getOffset());
 | 
				
			||||||
| 
						 | 
					@ -363,12 +388,15 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  case MachineOperand::MO_ExternalSymbol: {
 | 
					  case MachineOperand::MO_ExternalSymbol: {
 | 
				
			||||||
    bool isCallOp = Modifier && !strcmp(Modifier, "call");
 | 
					    bool isCallOp = Modifier && !strcmp(Modifier, "call");
 | 
				
			||||||
    std::string Name = Mang->makeNameProper(MO.getSymbolName());
 | 
					    std::string Name;
 | 
				
			||||||
    if (isCallOp && Subtarget->isTargetDarwin() &&
 | 
					    if (isCallOp && Subtarget->isTargetDarwin() &&
 | 
				
			||||||
        TM.getRelocationModel() != Reloc::Static) {
 | 
					        TM.getRelocationModel() != Reloc::Static) {
 | 
				
			||||||
      printSuffixedName(Name, "$stub");
 | 
					      FnStubInfo &FnInfo = FnStubs[Mang->makeNameProper(MO.getSymbolName())];
 | 
				
			||||||
      FnStubs.insert(Name);
 | 
					      FnInfo.Init(MO.getSymbolName(), Mang);
 | 
				
			||||||
 | 
					      Name = FnInfo.Stub;
 | 
				
			||||||
    } else
 | 
					    } else
 | 
				
			||||||
 | 
					      Name = Mang->makeNameProper(MO.getSymbolName());
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    O << Name;
 | 
					    O << Name;
 | 
				
			||||||
    if (isCallOp && Subtarget->isTargetELF() &&
 | 
					    if (isCallOp && Subtarget->isTargetELF() &&
 | 
				
			||||||
        TM.getRelocationModel() == Reloc::PIC_)
 | 
					        TM.getRelocationModel() == Reloc::PIC_)
 | 
				
			||||||
| 
						 | 
					@ -1186,8 +1214,9 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    O << '\n';
 | 
					    O << '\n';
 | 
				
			||||||
    // Output stubs for dynamically-linked functions
 | 
					    // Output stubs for dynamically-linked functions
 | 
				
			||||||
    for (StringSet<>::iterator I = FnStubs.begin(), E = FnStubs.end();
 | 
					    for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
 | 
				
			||||||
         I != E; ++I) {
 | 
					         I != E; ++I) {
 | 
				
			||||||
 | 
					      const FnStubInfo &Info = I->second;
 | 
				
			||||||
      if (TM.getRelocationModel() == Reloc::PIC_)
 | 
					      if (TM.getRelocationModel() == Reloc::PIC_)
 | 
				
			||||||
        SwitchToTextSection(".section __TEXT,__picsymbolstub4,symbol_stubs,"
 | 
					        SwitchToTextSection(".section __TEXT,__picsymbolstub4,symbol_stubs,"
 | 
				
			||||||
                            "none,16", 0);
 | 
					                            "none,16", 0);
 | 
				
			||||||
| 
						 | 
					@ -1198,33 +1227,23 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
 | 
				
			||||||
      EmitAlignment(2);
 | 
					      EmitAlignment(2);
 | 
				
			||||||
      O << "\t.code\t32\n";
 | 
					      O << "\t.code\t32\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const char *p = I->getKeyData();
 | 
					      O << Info.Stub << ":\n";
 | 
				
			||||||
      printSuffixedName(p, "$stub");
 | 
					      O << "\t.indirect_symbol " << I->getKeyData() << '\n';
 | 
				
			||||||
      O << ":\n";
 | 
					      O << "\tldr ip, " << Info.SLP << '\n';
 | 
				
			||||||
      O << "\t.indirect_symbol " << p << "\n";
 | 
					 | 
				
			||||||
      O << "\tldr ip, ";
 | 
					 | 
				
			||||||
      printSuffixedName(p, "$slp");
 | 
					 | 
				
			||||||
      O << "\n";
 | 
					 | 
				
			||||||
      if (TM.getRelocationModel() == Reloc::PIC_) {
 | 
					      if (TM.getRelocationModel() == Reloc::PIC_) {
 | 
				
			||||||
        printSuffixedName(p, "$scv");
 | 
					        O << Info.SCV << ":\n";
 | 
				
			||||||
        O << ":\n";
 | 
					 | 
				
			||||||
        O << "\tadd ip, pc, ip\n";
 | 
					        O << "\tadd ip, pc, ip\n";
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      O << "\tldr pc, [ip, #0]\n";
 | 
					      O << "\tldr pc, [ip, #0]\n";
 | 
				
			||||||
      printSuffixedName(p, "$slp");
 | 
					      O << Info.SLP << ":\n";
 | 
				
			||||||
      O << ":\n";
 | 
					      O << "\t.long\t" << Info.LazyPtr;
 | 
				
			||||||
      O << "\t.long\t";
 | 
					      if (TM.getRelocationModel() == Reloc::PIC_)
 | 
				
			||||||
      printSuffixedName(p, "$lazy_ptr");
 | 
					        O << "-(" << Info.SCV << "+8)";
 | 
				
			||||||
      if (TM.getRelocationModel() == Reloc::PIC_) {
 | 
					      O << '\n';
 | 
				
			||||||
        O << "-(";
 | 
					      
 | 
				
			||||||
        printSuffixedName(p, "$scv");
 | 
					 | 
				
			||||||
        O << "+8)\n";
 | 
					 | 
				
			||||||
      } else
 | 
					 | 
				
			||||||
        O << "\n";
 | 
					 | 
				
			||||||
      SwitchToDataSection(".lazy_symbol_pointer", 0);
 | 
					      SwitchToDataSection(".lazy_symbol_pointer", 0);
 | 
				
			||||||
      printSuffixedName(p, "$lazy_ptr");
 | 
					      O << Info.LazyPtr << ":\n";
 | 
				
			||||||
      O << ":\n";
 | 
					      O << "\t.indirect_symbol " << I->getKeyData() << "\n";
 | 
				
			||||||
      O << "\t.indirect_symbol " << p << "\n";
 | 
					 | 
				
			||||||
      O << "\t.long\tdyld_stub_binding_helper\n";
 | 
					      O << "\t.long\tdyld_stub_binding_helper\n";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    O << '\n';
 | 
					    O << '\n';
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue