if (_sectionMap.find(sectionKey) == _sectionMap.end()) {
SectionOrder section_order =
getSectionOrder(sectionName, contentType, permissions);
- section = new (_allocator.Allocate<Section<ELFT> >())
- Section<ELFT>(sectionName, contentType, permissions, section_order);
+ section = new (_allocator) Section<ELFT>(
+ _targetInfo, sectionName, contentType, permissions, section_order);
section->setOrder(section_order);
_sections.push_back(section);
_sectionMap.insert(std::make_pair(sectionKey, section));
if (!segmentInsert.second) {
segment = segmentInsert.first->second;
} else {
- segment = new (_allocator.Allocate<Segment<ELFT>>()) Segment<ELFT>(
- segmentName, getSegmentType(section), _targetInfo);
+ segment = new (_allocator)
+ Segment<ELFT>(_targetInfo, segmentName, getSegmentType(section));
segmentInsert.first->second = segment;
_segments.push_back(segment);
}
K_ELFSection, // Section
K_ELFSectionHeader // Section header
};
- Chunk(llvm::StringRef name, Kind kind)
- : _name(name)
- , _kind(kind)
- , _fsize(0)
- , _msize(0)
- , _align2(0)
- , _order(0)
- , _ordinal(1)
- , _start(0)
- , _fileoffset(0) {}
+ Chunk(llvm::StringRef name, Kind kind, const ELFTargetInfo &ti)
+ : _name(name), _kind(kind), _fsize(0), _msize(0), _align2(0), _order(0),
+ _ordinal(1), _start(0), _fileoffset(0), _targetInfo(ti) {
+ }
virtual ~Chunk() {}
// Does the chunk occupy disk space
virtual bool occupiesNoDiskSpace() const {
uint64_t _ordinal;
uint64_t _start;
uint64_t _fileoffset;
+ const ELFTargetInfo &_targetInfo;
};
} // elf
public:
typedef llvm::object::Elf_Ehdr_Impl<ELFT> Elf_Ehdr;
- ELFHeader();
+ ELFHeader(const ELFTargetInfo &);
void e_ident(int I, unsigned char C) { _eh.e_ident[I] = C; }
void e_type(uint16_t type) { _eh.e_type = type; }
Elf_Ehdr _eh;
};
-template<class ELFT>
-ELFHeader<ELFT>::ELFHeader()
-: Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_ELFHeader) {
+template <class ELFT>
+ELFHeader<ELFT>::ELFHeader(const ELFTargetInfo &ti)
+ : Chunk<ELFT>("elfhdr", Chunk<ELFT>::K_ELFHeader, ti) {
this->_align2 = ELFT::Is64Bits ? 8 : 4;
this->_fsize = sizeof(Elf_Ehdr);
this->_msize = sizeof(Elf_Ehdr);
uint64_t _flagsClear;
};
- ELFProgramHeader()
- : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ELFProgramHeader) {
+ ELFProgramHeader(const ELFTargetInfo &ti)
+ : Chunk<ELFT>("elfphdr", Chunk<ELFT>::K_ELFProgramHeader, ti) {
this->_align2 = ELFT::Is64Bits ? 8 : 4;
resetProgramHeaders();
}
public:
typedef llvm::object::Elf_Shdr_Impl<ELFT> Elf_Shdr;
- ELFSectionHeader(int32_t order);
+ ELFSectionHeader(const ELFTargetInfo &, int32_t order);
void appendSection(MergedSections<ELFT> *section);
llvm::BumpPtrAllocator _sectionAllocate;
};
-template<class ELFT>
-ELFSectionHeader<ELFT>::ELFSectionHeader(int32_t order)
- : Chunk<ELFT>("shdr", Chunk<ELFT>::K_ELFSectionHeader) {
+template <class ELFT>
+ELFSectionHeader<ELFT>::ELFSectionHeader(const ELFTargetInfo &ti, int32_t order)
+ : Chunk<ELFT>("shdr", Chunk<ELFT>::K_ELFSectionHeader, ti) {
this->_fsize = 0;
this->_align2 = 8;
this->setOrder(order);
};
// Create a section object, the section is set to the default type if the
// caller doesnot set it
- Section(const llvm::StringRef sectionName,
- const int32_t contentType,
- const int32_t contentPermissions,
- const int32_t order,
- const SectionKind kind = K_Default);
+ Section(const ELFTargetInfo &, const llvm::StringRef sectionName,
+ const int32_t contentType, const int32_t contentPermissions,
+ const int32_t order, const SectionKind kind = K_Default);
/// return the section kind
inline SectionKind sectionKind() const {
// Create a section object, the section is set to the default type if the
// caller doesnot set it
-template<class ELFT>
-Section<ELFT>::Section(const StringRef sectionName,
+template <class ELFT>
+Section<ELFT>::Section(const ELFTargetInfo &ti, const StringRef sectionName,
const int32_t contentType,
- const int32_t contentPermissions,
- const int32_t order,
+ const int32_t contentPermissions, const int32_t order,
const SectionKind kind)
- : Chunk<ELFT>(sectionName, Chunk<ELFT>::K_ELFSection)
- , _contentType(contentType)
- , _contentPermissions(contentPermissions)
- , _sectionKind(kind)
- , _entSize(0)
- , _shInfo(0)
- , _link(0) {
+ : Chunk<ELFT>(sectionName, Chunk<ELFT>::K_ELFSection, ti),
+ _contentType(contentType), _contentPermissions(contentPermissions),
+ _sectionKind(kind), _entSize(0), _shInfo(0), _link(0) {
this->setOrder(order);
}
template<class ELFT>
class ELFStringTable : public Section<ELFT> {
public:
- ELFStringTable(const char *str, int32_t order);
+ ELFStringTable(const ELFTargetInfo &, const char *str, int32_t order);
static inline bool classof(const Chunk<ELFT> *c) {
return c->kind() == Section<ELFT>::K_StringTable;
std::vector<llvm::StringRef> _strings;
};
-template<class ELFT>
-ELFStringTable<ELFT>::ELFStringTable(const char *str,
+template <class ELFT>
+ELFStringTable<ELFT>::ELFStringTable(const ELFTargetInfo &ti, const char *str,
int32_t order)
- : Section<ELFT>(
- str,
- llvm::ELF::SHT_STRTAB,
- DefinedAtom::perm___,
- order,
- Section<ELFT>::K_StringTable) {
+ : Section<ELFT>(ti, str, llvm::ELF::SHT_STRTAB, DefinedAtom::perm___, order,
+ Section<ELFT>::K_StringTable) {
// the string table has a NULL entry for which
// add an empty string
_strings.push_back("");
public:
typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
- ELFSymbolTable(const char *str, int32_t order);
+ ELFSymbolTable(const ELFTargetInfo &ti, const char *str, int32_t order);
void addSymbol(const Atom *atom, int32_t sectionIndex, uint64_t addr = 0);
};
/// ELF Symbol Table
-template<class ELFT>
-ELFSymbolTable<ELFT>::ELFSymbolTable(const char *str,
+template <class ELFT>
+ELFSymbolTable<ELFT>::ELFSymbolTable(const ELFTargetInfo &ti, const char *str,
int32_t order)
- : Section<ELFT>(
- str,
- llvm::ELF::SHT_SYMTAB,
- 0,
- order,
- Section<ELFT>::K_SymbolTable) {
+ : Section<ELFT>(ti, str, llvm::ELF::SHT_SYMTAB, 0, order,
+ Section<ELFT>::K_SymbolTable) {
this->setOrder(order);
Elf_Sym *symbol = new (_symbolAllocate.Allocate<Elf_Sym>()) Elf_Sym;
memset((void *)symbol, 0, sizeof(Elf_Sym));
typedef typename std::vector<SegmentSlice<ELFT> *>::iterator SliceIter;
typedef typename std::vector<Chunk<ELFT> *>::iterator SectionIter;
- Segment(const StringRef name,
- const ELFLayout::SegmentType type,
- const ELFTargetInfo &ti);
+ Segment(const ELFTargetInfo &ti, const StringRef name,
+ const ELFLayout::SegmentType type);
/// append a section to a segment
void append(Section<ELFT> *section);
inline ELFLayout::SegmentType segmentType() { return _segmentType; }
- inline int pageSize() const { return _targetInfo.getPageSize(); }
+ inline int pageSize() const { return this->_targetInfo.getPageSize(); }
inline int64_t atomflags() const { return _atomflags; }
ELFLayout::SegmentType _segmentType;
int64_t _flags;
int64_t _atomflags;
- const ELFTargetInfo &_targetInfo;
llvm::BumpPtrAllocator _segmentAllocate;
};
-template<class ELFT>
-Segment<ELFT>::Segment(const StringRef name,
- const ELFLayout::SegmentType type,
- const ELFTargetInfo &ti)
- : Chunk<ELFT>(name, Chunk<ELFT>::K_ELFSegment)
- , _segmentType(type)
- , _flags(0)
- , _atomflags(0)
- , _targetInfo(ti) {
+template <class ELFT>
+Segment<ELFT>::Segment(const ELFTargetInfo &ti, const StringRef name,
+ const ELFLayout::SegmentType type)
+ : Chunk<ELFT>(name, Chunk<ELFT>::K_ELFSegment, ti), _segmentType(type),
+ _flags(0), _atomflags(0) {
this->_align2 = 0;
this->_fsize = 0;
}
SegmentSlice<ELFT> *slice = nullptr;
// If the newOffset computed is more than a page away, lets create
// a seperate segment, so that memory is not used up while running
- if ((newOffset - curOffset) > _targetInfo.getPageSize()) {
+ if ((newOffset - curOffset) > this->_targetInfo.getPageSize()) {
// TODO: use std::find here
for (auto s : slices()) {
if (s->startSection() == startSection) {
slice->setSections(make_range(startSectionIter, endSectionIter));
slice->setSize(curSliceSize);
slice->setAlign(sliceAlign);
- uint64_t newPageOffset =
- llvm::RoundUpToAlignment(curOffset, _targetInfo.getPageSize());
+ uint64_t newPageOffset = llvm::RoundUpToAlignment(
+ curOffset, this->_targetInfo.getPageSize());
newOffset = llvm::RoundUpToAlignment(newPageOffset, (*si)->align2());
curSliceFileOffset = newOffset;
startSectionIter = endSectionIter;
Segment<ELFT>::assignVirtualAddress(uint64_t &addr) {
for (auto slice : slices()) {
// Align to a page
- addr = llvm::RoundUpToAlignment(addr, _targetInfo.getPageSize());
+ addr = llvm::RoundUpToAlignment(addr, this->_targetInfo.getPageSize());
// Align to the slice alignment
addr = llvm::RoundUpToAlignment(addr, slice->align2());
template<class ELFT>
void ELFExecutableWriter<ELFT>::createDefaultSections() {
- _elfHeader = new ELFHeader<ELFT>();
- _programHeader = new ELFProgramHeader<ELFT>();
+ _elfHeader = new ELFHeader<ELFT>(_targetInfo);
+ _programHeader = new ELFProgramHeader<ELFT>(_targetInfo);
_layout->setELFHeader(_elfHeader);
_layout->setProgramHeader(_programHeader);
- _symtab = new ELFSymbolTable<ELFT>(
- ".symtab", DefaultELFLayout<ELFT>::ORDER_SYMBOL_TABLE);
- _strtab = new ELFStringTable<ELFT>(
- ".strtab", DefaultELFLayout<ELFT>::ORDER_STRING_TABLE);
+ _symtab = new ELFSymbolTable<
+ ELFT>(_targetInfo, ".symtab", DefaultELFLayout<ELFT>::ORDER_SYMBOL_TABLE);
+ _strtab = new ELFStringTable<
+ ELFT>(_targetInfo, ".strtab", DefaultELFLayout<ELFT>::ORDER_STRING_TABLE);
_shstrtab = new ELFStringTable<ELFT>(
- ".shstrtab", DefaultELFLayout<ELFT>::ORDER_SECTION_STRINGS);
- _shdrtab = new ELFSectionHeader<ELFT>(
- DefaultELFLayout<ELFT>::ORDER_SECTION_HEADERS);
+ _targetInfo, ".shstrtab", DefaultELFLayout<ELFT>::ORDER_SECTION_STRINGS);
+ _shdrtab = new ELFSectionHeader<
+ ELFT>(_targetInfo, DefaultELFLayout<ELFT>::ORDER_SECTION_HEADERS);
_layout->addSection(_symtab);
_layout->addSection(_strtab);
_layout->addSection(_shstrtab);