1 //===- X86Emulation.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 "X86.h" 10 #include <mcld/LinkerConfig.h> 11 #include <mcld/LinkerScript.h> 12 #include <mcld/Target/ELFEmulation.h> 13 #include <mcld/Support/TargetRegistry.h> 14 15 namespace mcld { 16 17 static bool MCLDEmulateX86ELF(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 unsigned int bitclass; 25 Triple::ArchType arch = pConfig.targets().triple().getArch(); 26 assert (arch == Triple::x86 || arch == Triple::x86_64); 27 if (arch == Triple::x86 || 28 pConfig.targets().triple().getEnvironment() == Triple::GNUX32) { 29 bitclass = 32; 30 } 31 else { 32 bitclass = 64; 33 } 34 pConfig.targets().setBitClass(bitclass); 35 36 // set up target-dependent constraints of attributes 37 pConfig.attribute().constraint().enableWholeArchive(); 38 pConfig.attribute().constraint().enableAsNeeded(); 39 pConfig.attribute().constraint().setSharedSystem(); 40 41 // set up the predefined attributes 42 pConfig.attribute().predefined().unsetWholeArchive(); 43 pConfig.attribute().predefined().unsetAsNeeded(); 44 pConfig.attribute().predefined().setDynamic(); 45 return true; 46 } 47 48 //===----------------------------------------------------------------------===// 49 // emulateX86LD - the help function to emulate X86 ld 50 //===----------------------------------------------------------------------===// 51 bool emulateX86LD(LinkerScript& pScript, LinkerConfig& pConfig) 52 { 53 if (pConfig.targets().triple().isOSDarwin()) { 54 assert(0 && "MachO linker has not supported yet"); 55 return false; 56 } 57 if (pConfig.targets().triple().isOSWindows()) { 58 assert(0 && "COFF linker has not supported yet"); 59 return false; 60 } 61 62 return MCLDEmulateX86ELF(pScript, pConfig); 63 } 64 65 } // namespace of mcld 66 67 //===----------------------------------------------------------------------===// 68 // X86Emulation 69 //===----------------------------------------------------------------------===// 70 extern "C" void MCLDInitializeX86Emulation() { 71 // Register the emulation 72 mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_32Target, mcld::emulateX86LD); 73 mcld::TargetRegistry::RegisterEmulation(mcld::TheX86_64Target, mcld::emulateX86LD); 74 } 75 76