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