1//===- ELFSectionMap.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/Support/MsgHandling.h> 10#include <mcld/LD/ELFSectionMap.h> 11 12using namespace mcld; 13 14struct NameMap { 15 const char* from; 16 const char* to; 17}; 18 19// Common mappings of ELF and other formants. Now only ELF specific mappings 20// are added 21static 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 {".sdata", ".sdata"}, 37 {".sbss", ".sbss"}, 38 // FIXME: in GNU ld, if we are creating a shared object .sdata2 and .sbss2 39 // sections would be handled differently. 40 {".sdata2", ".sdata"}, 41 {".sbss2", ".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.t", ".text"}, 49 {".gnu.linkonce.r", ".rodata"}, 50 {".gnu.linkonce.d", ".data"}, 51 {".gnu.linkonce.b", ".bss"}, 52 {".gnu.linkonce.s", ".sdata"}, 53 {".gnu.linkonce.sb", ".sbss"}, 54 {".gnu.linkonce.s2", ".sdata"}, 55 {".gnu.linkonce.sb2", ".sbss"}, 56 {".gnu.linkonce.wi", ".debug_info"}, 57 {".gnu.linkonce.td", ".tdata"}, 58 {".gnu.linkonce.tb", ".tbss"}, 59 {".gnu.linkonce.lr", ".lrodata"}, 60 {".gnu.linkonce.l", ".ldata"}, 61 {".gnu.linkonce.lb", ".lbss"}, 62}; 63 64static const int map_size = (sizeof(map) / sizeof(map[0])); 65 66ELFSectionMap::ELFSectionMap() 67{ 68} 69 70ELFSectionMap::~ELFSectionMap() 71{ 72} 73 74void ELFSectionMap::initStandardMaps() 75{ 76 for (unsigned int i = 0; i < map_size; ++i) { 77 bool exist = false; 78 NamePair& pair = append(map[i].from, map[i].to, exist); 79 if (exist) { 80 warning(diag::warn_duplicate_std_sectmap) << map[i].from 81 << map[i].to 82 << pair.from 83 << pair.to; 84 } 85 } 86} 87 88