1 //===- MipsEmulation.cpp --------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include "Mips.h" 10 #include "mcld/LinkerScript.h" 11 #include "mcld/LinkerConfig.h" 12 #include "mcld/Support/TargetRegistry.h" 13 #include "mcld/Target/ELFEmulation.h" 14 15 namespace mcld { 16 MCLDEmulateMipsELF(LinkerScript & pScript,LinkerConfig & pConfig)17static bool MCLDEmulateMipsELF(LinkerScript& pScript, LinkerConfig& pConfig) { 18 if (!MCLDEmulateELF(pScript, pConfig)) 19 return false; 20 21 // set up bitclass and endian 22 pConfig.targets().setEndian(TargetOptions::Little); 23 24 llvm::Triple::ArchType arch = pConfig.targets().triple().getArch(); 25 assert(arch == llvm::Triple::mipsel || arch == llvm::Triple::mips64el); 26 unsigned bitclass = arch == llvm::Triple::mipsel ? 32 : 64; 27 pConfig.targets().setBitClass(bitclass); 28 29 // set up target-dependent constraints of attributes 30 pConfig.attribute().constraint().enableWholeArchive(); 31 pConfig.attribute().constraint().enableAsNeeded(); 32 pConfig.attribute().constraint().setSharedSystem(); 33 34 // set up the predefined attributes 35 pConfig.attribute().predefined().unsetWholeArchive(); 36 pConfig.attribute().predefined().unsetAsNeeded(); 37 pConfig.attribute().predefined().setDynamic(); 38 return true; 39 } 40 41 //===----------------------------------------------------------------------===// 42 // emulateMipsLD - the help function to emulate Mips ld 43 //===----------------------------------------------------------------------===// emulateMipsLD(LinkerScript & pScript,LinkerConfig & pConfig)44bool emulateMipsLD(LinkerScript& pScript, LinkerConfig& pConfig) { 45 if (pConfig.targets().triple().isOSDarwin()) { 46 assert(0 && "MachO linker has not supported yet"); 47 return false; 48 } 49 if (pConfig.targets().triple().isOSWindows()) { 50 assert(0 && "COFF linker has not supported yet"); 51 return false; 52 } 53 54 return MCLDEmulateMipsELF(pScript, pConfig); 55 } 56 57 } // namespace mcld 58 59 //===----------------------------------------------------------------------===// 60 // MipsEmulation 61 //===----------------------------------------------------------------------===// MCLDInitializeMipsEmulation()62extern "C" void MCLDInitializeMipsEmulation() { 63 mcld::TargetRegistry::RegisterEmulation(mcld::TheMipselTarget, 64 mcld::emulateMipsLD); 65 mcld::TargetRegistry::RegisterEmulation(mcld::TheMips64elTarget, 66 mcld::emulateMipsLD); 67 } 68