1 //===- ELFEmulation.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 <mcld/Target/ELFEmulation.h> 10 #include <mcld/LinkerConfig.h> 11 12 #include <llvm/Support/Host.h> 13 14 using namespace mcld; 15 16 struct NameMap { 17 const char* from; ///< the prefix of the input string. (match FROM*) 18 const char* to; ///< the output string. 19 }; 20 21 static const NameMap map[] = 22 { 23 {".text", ".text"}, 24 {".rodata", ".rodata"}, 25 {".data.rel.ro.local", ".data.rel.ro.local"}, 26 {".data.rel.ro", ".data.rel.ro"}, 27 {".data", ".data"}, 28 {".bss", ".bss"}, 29 {".tdata", ".tdata"}, 30 {".tbss", ".tbss"}, 31 {".init_array", ".init_array"}, 32 {".fini_array", ".fini_array"}, 33 // TODO: Support DT_INIT_ARRAY for all constructors? 34 {".ctors", ".ctors"}, 35 {".dtors", ".dtors"}, 36 // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2 37 // sections would be handled differently. 38 {".sdata2", ".sdata"}, 39 {".sbss2", ".sbss"}, 40 {".sdata", ".sdata"}, 41 {".sbss", ".sbss"}, 42 {".lrodata", ".lrodata"}, 43 {".ldata", ".ldata"}, 44 {".lbss", ".lbss"}, 45 {".gcc_except_table", ".gcc_except_table"}, 46 {".gnu.linkonce.d.rel.ro.local", ".data.rel.ro.local"}, 47 {".gnu.linkonce.d.rel.ro", ".data.rel.ro"}, 48 {".gnu.linkonce.r", ".rodata"}, 49 {".gnu.linkonce.d", ".data"}, 50 {".gnu.linkonce.b", ".bss"}, 51 {".gnu.linkonce.sb2", ".sbss"}, 52 {".gnu.linkonce.sb", ".sbss"}, 53 {".gnu.linkonce.s2", ".sdata"}, 54 {".gnu.linkonce.s", ".sdata"}, 55 {".gnu.linkonce.wi", ".debug_info"}, 56 {".gnu.linkonce.td", ".tdata"}, 57 {".gnu.linkonce.tb", ".tbss"}, 58 {".gnu.linkonce.t", ".text"}, 59 {".gnu.linkonce.lr", ".lrodata"}, 60 {".gnu.linkonce.lb", ".lbss"}, 61 {".gnu.linkonce.l", ".ldata"}, 62 }; 63 64 bool mcld::MCLDEmulateELF(LinkerConfig& pConfig) 65 { 66 // set up section map 67 if (pConfig.codeGenType() != LinkerConfig::Object) { 68 const unsigned int map_size = (sizeof(map) / sizeof(map[0]) ); 69 for (unsigned int i = 0; i < map_size; ++i) { 70 bool exist = false; 71 pConfig.scripts().sectionMap().append(map[i].from, map[i].to, exist); 72 if (exist) 73 return false; 74 } 75 } 76 77 if (!pConfig.options().nostdlib()) { 78 // TODO: check if user sets the default search path instead via -Y option 79 // set up default search path 80 if (llvm::Triple::NetBSD == pConfig.targets().triple().getOS()) { 81 pConfig.options().directories().insert("=/usr/lib"); 82 } 83 else { 84 pConfig.options().directories().insert("=/lib"); 85 pConfig.options().directories().insert("=/usr/lib"); 86 } 87 } 88 return true; 89 } 90 91