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