2013-01-30 06:03:39 +08:00
|
|
|
//===- lib/ReaderWriter/ELF/Chunks.h --------------------------------------===//
|
2013-01-22 04:09:55 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-30 06:03:39 +08:00
|
|
|
#ifndef LLD_READER_WRITER_ELF_CHUNKS_H
|
|
|
|
#define LLD_READER_WRITER_ELF_CHUNKS_H
|
|
|
|
|
|
|
|
#include "lld/Core/LLVM.h"
|
2013-01-22 04:09:55 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ELF.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/FileOutputBuffer.h"
|
|
|
|
|
|
|
|
namespace lld {
|
2013-01-30 03:53:41 +08:00
|
|
|
class ELFTargetInfo;
|
2013-01-22 04:09:55 +08:00
|
|
|
|
2013-01-30 03:53:41 +08:00
|
|
|
namespace elf {
|
2013-01-22 04:09:55 +08:00
|
|
|
class ELFWriter;
|
|
|
|
|
|
|
|
/// \brief A chunk is a contiguous region of space
|
|
|
|
template<class ELFT>
|
|
|
|
class Chunk {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// \brief Describes the type of Chunk
|
|
|
|
enum Kind {
|
2013-01-30 06:03:39 +08:00
|
|
|
K_Header, // ELF Header
|
|
|
|
K_ProgramHeader, // Program Header
|
2013-01-22 04:09:55 +08:00
|
|
|
K_ELFSegment, // Segment
|
|
|
|
K_ELFSection, // Section
|
2013-02-15 04:24:38 +08:00
|
|
|
K_AtomSection, //< A section containing atoms.
|
2013-01-30 06:03:39 +08:00
|
|
|
K_SectionHeader // Section header
|
2013-01-22 04:09:55 +08:00
|
|
|
};
|
2013-01-30 06:03:39 +08:00
|
|
|
Chunk(StringRef name, Kind kind, const ELFTargetInfo &ti)
|
2013-01-29 09:07:47 +08:00
|
|
|
: _name(name), _kind(kind), _fsize(0), _msize(0), _align2(0), _order(0),
|
|
|
|
_ordinal(1), _start(0), _fileoffset(0), _targetInfo(ti) {
|
|
|
|
}
|
2013-01-30 15:11:43 +08:00
|
|
|
virtual ~Chunk() {}
|
2013-01-22 04:09:55 +08:00
|
|
|
// Does the chunk occupy disk space
|
2013-01-30 15:11:43 +08:00
|
|
|
virtual bool occupiesNoDiskSpace() const { return false; }
|
2013-01-22 04:09:55 +08:00
|
|
|
// The name of the chunk
|
2013-01-30 06:03:39 +08:00
|
|
|
StringRef name() const { return _name; }
|
2013-01-22 04:09:55 +08:00
|
|
|
// Kind of chunk
|
|
|
|
Kind kind() const { return _kind; }
|
|
|
|
uint64_t fileSize() const { return _fsize; }
|
|
|
|
uint64_t align2() const { return _align2; }
|
|
|
|
|
|
|
|
// The ordinal value of the chunk
|
|
|
|
uint64_t ordinal() const { return _ordinal;}
|
|
|
|
void setOrdinal(uint64_t newVal) { _ordinal = newVal;}
|
|
|
|
// The order in which the chunk would appear in the output file
|
|
|
|
uint64_t order() const { return _order; }
|
|
|
|
void setOrder(uint32_t order) { _order = order; }
|
|
|
|
// Output file offset of the chunk
|
|
|
|
uint64_t fileOffset() const { return _fileoffset; }
|
|
|
|
void setFileOffset(uint64_t offset) { _fileoffset = offset; }
|
|
|
|
// Output start address of the chunk
|
|
|
|
void setVAddr(uint64_t start) { _start = start; }
|
|
|
|
uint64_t virtualAddr() const { return _start; }
|
|
|
|
// Does the chunk occupy memory during execution ?
|
|
|
|
uint64_t memSize() const { return _msize; }
|
|
|
|
void setMemSize(uint64_t msize) { _msize = msize; }
|
|
|
|
// Writer the chunk
|
2013-01-29 09:00:21 +08:00
|
|
|
virtual void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) = 0;
|
2013-01-22 04:09:55 +08:00
|
|
|
// Finalize the chunk before writing
|
2013-01-30 15:11:43 +08:00
|
|
|
virtual void finalize() = 0;
|
2013-01-22 04:09:55 +08:00
|
|
|
|
|
|
|
protected:
|
2013-01-30 06:03:39 +08:00
|
|
|
StringRef _name;
|
2013-01-22 04:09:55 +08:00
|
|
|
Kind _kind;
|
|
|
|
uint64_t _fsize;
|
|
|
|
uint64_t _msize;
|
|
|
|
uint64_t _align2;
|
2013-02-15 04:24:38 +08:00
|
|
|
uint32_t _order;
|
2013-01-22 04:09:55 +08:00
|
|
|
uint64_t _ordinal;
|
|
|
|
uint64_t _start;
|
|
|
|
uint64_t _fileoffset;
|
2013-01-29 09:07:47 +08:00
|
|
|
const ELFTargetInfo &_targetInfo;
|
2013-01-22 04:09:55 +08:00
|
|
|
};
|
|
|
|
|
2013-01-30 06:03:39 +08:00
|
|
|
} // end namespace elf
|
|
|
|
} // end namespace lld
|
2013-01-22 04:09:55 +08:00
|
|
|
|
2013-01-30 06:03:39 +08:00
|
|
|
#endif
|