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