mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 01:29:52 +00:00
e7a00e326a
The others we have in sight are * common symbols. * entries in SHF_MERGE sections. They will have a substantially different treatment. It is not clear if it is worth it putting them all in a single list just to dispatch based on the kind on the other side. I hope to implement common symbols soon, and then we will be in a position to have a concrete discussion. For now this is simpler for the the implemented features. llvm-svn: 244042
75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
//===- Writer.h -----------------------------------------------------------===//
|
|
//
|
|
// The LLVM Linker
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_ELF_WRITER_H
|
|
#define LLD_ELF_WRITER_H
|
|
|
|
#include "Chunks.h"
|
|
#include "SymbolTable.h"
|
|
#include "llvm/Support/FileOutputBuffer.h"
|
|
|
|
namespace lld {
|
|
namespace elf2 {
|
|
// OutputSection represents a section in an output file. It's a
|
|
// container of chunks. OutputSection and Chunk are 1:N relationship.
|
|
// Chunks cannot belong to more than one OutputSections. The writer
|
|
// creates multiple OutputSections and assign them unique,
|
|
// non-overlapping file offsets and VAs.
|
|
class OutputSection {
|
|
public:
|
|
OutputSection(StringRef Name) : Name(Name), Header({}) {}
|
|
void setVA(uint64_t);
|
|
void setFileOffset(uint64_t);
|
|
template <class ELFT> void addSectionChunk(SectionChunk<ELFT> *C);
|
|
std::vector<Chunk *> &getChunks() { return Chunks; }
|
|
template <class ELFT>
|
|
void writeHeaderTo(llvm::object::Elf_Shdr_Impl<ELFT> *SHdr);
|
|
|
|
// Returns the size of the section in the output file.
|
|
uint64_t getSize() { return Header.sh_size; }
|
|
|
|
private:
|
|
StringRef Name;
|
|
llvm::ELF::Elf64_Shdr Header;
|
|
std::vector<Chunk *> Chunks;
|
|
};
|
|
|
|
// The writer writes a SymbolTable result to a file.
|
|
template <class ELFT> class Writer {
|
|
public:
|
|
typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
|
|
|
|
explicit Writer(SymbolTable *Symtab);
|
|
~Writer();
|
|
void write(StringRef Path);
|
|
|
|
private:
|
|
void createSections();
|
|
void assignAddresses();
|
|
void openFile(StringRef OutputPath);
|
|
void writeHeader();
|
|
void writeSections();
|
|
|
|
SymbolTable *Symtab;
|
|
std::unique_ptr<llvm::FileOutputBuffer> Buffer;
|
|
llvm::SpecificBumpPtrAllocator<OutputSection> CAlloc;
|
|
std::vector<OutputSection *> OutputSections;
|
|
|
|
uint64_t FileSize;
|
|
uint64_t SizeOfHeaders;
|
|
uintX_t SectionHeaderOff;
|
|
|
|
std::vector<std::unique_ptr<Chunk>> Chunks;
|
|
};
|
|
|
|
} // namespace elf2
|
|
} // namespace lld
|
|
|
|
#endif
|