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
|
//===- lib/ReaderWriter/ELF/Hexagon/HexagonSectionChunks.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_HEXAGON_SECTION_CHUNKS_H
#define LLD_READER_WRITER_ELF_HEXAGON_HEXAGON_SECTION_CHUNKS_H
#include "HexagonTargetHandler.h"
namespace lld {
namespace elf {
typedef llvm::object::ELFType<llvm::support::little, 2, false> HexagonELFType;
template <typename ELFT> class HexagonTargetLayout;
class HexagonLinkingContext;
/// \brief Handle Hexagon SData section
template <class HexagonELFType>
class SDataSection : public AtomSection<HexagonELFType> {
public:
SDataSection(const HexagonLinkingContext &context)
: AtomSection<HexagonELFType>(
context, ".sdata", DefinedAtom::typeDataFast, 0,
HexagonTargetLayout<HexagonELFType>::ORDER_SDATA) {
this->_type = SHT_PROGBITS;
this->_flags = SHF_ALLOC | SHF_WRITE;
this->_align2 = 4096;
}
/// \brief Finalize the section contents before writing
virtual void doPreFlight();
/// \brief Does this section have an output segment.
virtual bool hasOutputSegment() { return true; }
const lld::AtomLayout &appendAtom(const Atom *atom) {
const DefinedAtom *definedAtom = cast<DefinedAtom>(atom);
DefinedAtom::Alignment atomAlign = definedAtom->alignment();
uint64_t align2 = 1u << atomAlign.powerOf2;
this->_atoms.push_back(new (this->_alloc) lld::AtomLayout(atom, 0, 0));
// Set the section alignment to the largest alignment
// std::max doesnot support uint64_t
if (this->_align2 < align2)
this->_align2 = align2;
return *(this->_atoms.back());
}
}; // SDataSection
template <class HexagonELFType>
void SDataSection<HexagonELFType>::doPreFlight() {
// sort the atoms on the alignments they have been set
std::stable_sort(this->_atoms.begin(), this->_atoms.end(),
[](const lld::AtomLayout * A,
const lld::AtomLayout * B) {
const DefinedAtom *definedAtomA = cast<DefinedAtom>(A->_atom);
const DefinedAtom *definedAtomB = cast<DefinedAtom>(B->_atom);
int64_t align2A = 1 << definedAtomA->alignment().powerOf2;
int64_t align2B = 1 << definedAtomB->alignment().powerOf2;
if (align2A == align2B) {
if (definedAtomA->merge() == DefinedAtom::mergeAsTentative)
return false;
if (definedAtomB->merge() == DefinedAtom::mergeAsTentative)
return true;
}
return align2A < align2B;
});
// Set the fileOffset, and the appropriate size of the section
for (auto &ai : this->_atoms) {
const DefinedAtom *definedAtom = cast<DefinedAtom>(ai->_atom);
DefinedAtom::Alignment atomAlign = definedAtom->alignment();
uint64_t fOffset = this->alignOffset(this->fileSize(), atomAlign);
uint64_t mOffset = this->alignOffset(this->memSize(), atomAlign);
ai->_fileOffset = fOffset;
this->_fsize = fOffset + definedAtom->size();
this->_msize = mOffset + definedAtom->size();
}
} // finalize
} // elf
} // lld
#endif // LLD_READER_WRITER_ELF_HEXAGON_HEXAGON_SECTION_CHUNKS_H
|