• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- SectionMap.h -------------------------------------------------------===//
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 #ifndef MCLD_SECTION_MAP_H
10 #define MCLD_SECTION_MAP_H
11 #ifdef ENABLE_UNITTEST
12 #include <gtest.h>
13 #endif
14 
15 #include <llvm/Support/DataTypes.h>
16 #include <vector>
17 #include <string>
18 
19 namespace mcld
20 {
21 
22 /** \class SectionMap
23  *  \brief descirbe the mappings of input section's name (or prefix) to
24  *         its associated output section's name and offset
25  */
26 class SectionMap
27 {
28 public:
29   // a mapping in SectionMap is the triple of
30   // {input substr, output section's name, output section's offset}
31   struct Mapping {
32     std::string inputSubStr;
33     std::string outputStr;
34     uint64_t offset;
35   };
36 
37   typedef std::vector<struct Mapping> SectionMappingTy;
38 
39   typedef SectionMappingTy::iterator iterator;
40   typedef SectionMappingTy::const_iterator const_iterator;
41 
42 public:
43   SectionMap();
44   ~SectionMap();
45 
46   // get the possible output section name based on the mapping table
47   // return NULL if not found
48   const std::string& getOutputSectName(const std::string& pInput);
49 
50   // add a mapping from input substr to output name and offset.
51   bool push_back(const std::string& pInput,
52                  const std::string& pOutput,
53                  const uint64_t pOffset = 0);
54 
55   // find - return the iterator to the mapping
56   iterator find(const std::string& pInput);
57 
58   // at - return the pointer to the mapping
59   Mapping* at(const std::string& pInput);
60 
61   // -----  observers  ----- //
empty()62   bool empty() const
63   { return m_SectMap.empty(); }
64 
size()65   size_t size() const
66   { return m_SectMap.size(); }
67 
capacity()68   size_t capacity () const
69   { return m_SectMap.capacity(); }
70 
71   // -----  iterators  ----- //
begin()72   iterator begin()
73   { return m_SectMap.begin(); }
74 
end()75   iterator end()
76   { return m_SectMap.end(); }
77 
begin()78   const_iterator begin() const
79   { return m_SectMap.begin(); }
80 
end()81   const_iterator end() const
82   { return m_SectMap.end(); }
83 
84   // initStdSectionMap - add common mappings of ELF and other formats
85   // to SectionMap
86   bool initStdSectionMap();
87 
88 private:
89   struct SectionNameMapping {
90     const char* from;
91     const char* to;
92   };
93 
94   // used to store common mappings of ELF and other formants
95   static const SectionNameMapping m_StdSectionMap[];
96 
97   static const int m_StdSectionMapSize;
98 
99   SectionMappingTy m_SectMap;
100 };
101 
102 } // namespace of mcld
103 
104 #endif
105