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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
//===- lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h ----------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_HEXAGON_TARGET_HANDLER_H
#define LLD_READER_WRITER_ELF_HEXAGON_TARGET_HANDLER_H
#include "DefaultTargetHandler.h"
#include "ExecutableAtoms.h"
#include "HexagonRelocationHandler.h"
#include "HexagonSectionChunks.h"
#include "TargetLayout.h"
namespace lld {
namespace elf {
typedef llvm::object::ELFType<llvm::support::little, 4, false> HexagonELFType;
class HexagonTargetInfo;
/// \brief Handle Hexagon specific Atoms
template <class HexagonELFType>
class HexagonTargetAtomHandler LLVM_FINAL :
public TargetAtomHandler<HexagonELFType> {
typedef llvm::object::Elf_Sym_Impl<HexagonELFType> Elf_Sym;
typedef llvm::object::Elf_Shdr_Impl<HexagonELFType> Elf_Shdr;
public:
virtual DefinedAtom::ContentType
contentType(const ELFDefinedAtom<HexagonELFType> *atom) const {
return contentType(atom->section(), atom->symbol());
}
virtual DefinedAtom::ContentType
contentType(const Elf_Shdr *section, const Elf_Sym *sym) const {
switch (sym->st_shndx) {
// Common symbols
case llvm::ELF::SHN_HEXAGON_SCOMMON:
case llvm::ELF::SHN_HEXAGON_SCOMMON_1:
case llvm::ELF::SHN_HEXAGON_SCOMMON_2:
case llvm::ELF::SHN_HEXAGON_SCOMMON_4:
case llvm::ELF::SHN_HEXAGON_SCOMMON_8:
return DefinedAtom::typeZeroFill;
default:
if (section->sh_flags & llvm::ELF::SHF_HEX_GPREL)
return DefinedAtom::typeDataFast;
else
llvm_unreachable("unknown symbol type");
}
}
virtual DefinedAtom::ContentPermissions
contentPermissions(const ELFDefinedAtom<HexagonELFType> *atom) const {
// All of the hexagon specific symbols belong in the data segment
return DefinedAtom::permRW_;
}
virtual int64_t getType(const Elf_Sym *sym) const {
switch (sym->st_shndx) {
// Common symbols
case llvm::ELF::SHN_HEXAGON_SCOMMON:
case llvm::ELF::SHN_HEXAGON_SCOMMON_1:
case llvm::ELF::SHN_HEXAGON_SCOMMON_2:
case llvm::ELF::SHN_HEXAGON_SCOMMON_4:
case llvm::ELF::SHN_HEXAGON_SCOMMON_8:
return llvm::ELF::STT_COMMON;
default:
return sym->getType();
}
}
};
/// \brief TargetLayout for Hexagon
template <class HexagonELFType>
class HexagonTargetLayout LLVM_FINAL : public TargetLayout<HexagonELFType> {
public:
enum HexagonSectionOrder {
ORDER_SDATA = 205
};
HexagonTargetLayout(const HexagonTargetInfo &hti)
: TargetLayout<HexagonELFType>(hti), _sdataSection(nullptr) {
_sdataSection = new (_alloc) SDataSection<HexagonELFType>(hti);
}
/// \brief Return the section order for a input section
virtual Layout::SectionOrder getSectionOrder(
StringRef name, int32_t contentType, int32_t contentPermissions) {
if (contentType == DefinedAtom::typeDataFast)
return ORDER_SDATA;
return DefaultLayout<HexagonELFType>::getSectionOrder(name, contentType,
contentPermissions);
}
/// \brief This maps the input sections to the output section names
virtual StringRef getSectionName(StringRef name, const int32_t contentType,
const int32_t contentPermissions) {
if (contentType == DefinedAtom::typeDataFast)
return ".sdata";
return DefaultLayout<HexagonELFType>::getSectionName(name, contentType,
contentPermissions);
}
/// \brief Gets or creates a section.
virtual AtomSection<HexagonELFType> *
createSection(StringRef name, int32_t contentType,
DefinedAtom::ContentPermissions contentPermissions,
Layout::SectionOrder sectionOrder) {
if (contentType == DefinedAtom::typeDataFast)
return _sdataSection;
return DefaultLayout<HexagonELFType>::createSection(
name, contentType, contentPermissions, sectionOrder);
}
/// \brief get the segment type for the section thats defined by the target
virtual Layout::SegmentType
getSegmentType(Section<HexagonELFType> *section) const {
if (section->order() == ORDER_SDATA)
return PT_LOAD;
return DefaultLayout<HexagonELFType>::getSegmentType(section);
}
private:
llvm::BumpPtrAllocator _alloc;
SDataSection<HexagonELFType> *_sdataSection;
};
/// \brief TargetHandler for Hexagon
class HexagonTargetHandler LLVM_FINAL :
public DefaultTargetHandler<HexagonELFType> {
public:
HexagonTargetHandler(HexagonTargetInfo &targetInfo);
virtual TargetLayout<HexagonELFType> &targetLayout() {
return _targetLayout;
}
virtual TargetAtomHandler<HexagonELFType> &targetAtomHandler() {
return _targetAtomHandler;
}
virtual const HexagonTargetRelocationHandler &getRelocationHandler() const {
return _relocationHandler;
}
private:
HexagonTargetRelocationHandler _relocationHandler;
HexagonTargetLayout<HexagonELFType> _targetLayout;
HexagonTargetAtomHandler<HexagonELFType> _targetAtomHandler;
};
} // end namespace elf
} // end namespace lld
#endif
|