| Index: src/IceELFObjectWriter.h
|
| diff --git a/src/IceELFObjectWriter.h b/src/IceELFObjectWriter.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3401a1660885547949a3f0a8bc554535af284ad3
|
| --- /dev/null
|
| +++ b/src/IceELFObjectWriter.h
|
| @@ -0,0 +1,115 @@
|
| +//===- subzero/src/IceELFObjectWriter.h - ELF object writer -----*- C++ -*-===//
|
| +//
|
| +// The Subzero Code Generator
|
| +//
|
| +// This file is distributed under the University of Illinois Open Source
|
| +// License. See LICENSE.TXT for details.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +//
|
| +// Interface for an ELF Object file writer.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +
|
| +#ifndef SUBZERO_SRC_ICEELFOBJECTWRITER_H
|
| +#define SUBZERO_SRC_ICEELFOBJECTWRITER_H
|
| +
|
| +#include "IceDefs.h"
|
| +#include "IceELFSection.h"
|
| +#include "IceELFStreamer.h"
|
| +
|
| +using namespace llvm::ELF;
|
| +
|
| +namespace Ice {
|
| +
|
| +// Higher level ELF object writer. Manages section information and writes
|
| +// the final ELF object. The object writer will write to file the code
|
| +// and data from as it is being defined (rather than keep a copy).
|
| +// After all definitions are written out, it will do a final sort on the
|
| +// symbol table and string tables, then write such bookkeeping sections
|
| +// out and seek backward to patch up the ELF file header. Expected usage:
|
| +//
|
| +// (1) writeInitialELFHeader
|
| +// (2) writeDataInitializer*
|
| +// (3) writeFunctionCode*
|
| +// (4) writeNonUserSections
|
| +class ELFObjectWriter {
|
| + ELFObjectWriter(const ELFObjectWriter &) = delete;
|
| + ELFObjectWriter &operator=(const ELFObjectWriter &) = delete;
|
| +
|
| +public:
|
| + ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out);
|
| +
|
| + // Write the initial ELF header, just to reserve space in the ELF
|
| + // file. This then allows the other functions of writing text
|
| + // and data to write directly to the file and get the right offset.
|
| + void writeInitialELFHeader();
|
| +
|
| + // Copy final (non-resizeable) data of functions' text section to file.
|
| + // TODO(jvoung): This needs the relocations too adjust the offsets
|
| + // and hook them up to the symbol table references.
|
| + void writeFunctionCode(const IceString &FuncName, bool IsInternal,
|
| + const llvm::StringRef Data);
|
| +
|
| + // Add way to write/copy data symbols / set initializers.
|
| + // TODO(jvoung): This needs to know which section.
|
| + // This also needs the relocations to hook them up to the symbol table
|
| + // references.
|
| + void writeDataInitializer(const IceString &VarName,
|
| + const llvm::StringRef Data);
|
| +
|
| + // Do final layout and write out the rest of the object file
|
| + // Patch up the initial ELF header.
|
| + void writeNonUserSections();
|
| +
|
| +private:
|
| + GlobalContext &Ctx;
|
| + ELFStreamer &Str;
|
| + bool SectionNumbersAssigned;
|
| +
|
| + // All created sections, separated into different pools.
|
| + typedef std::vector<ELFSection *> SectionList;
|
| + SectionList TextSections;
|
| + SectionList RelTextSections;
|
| + SectionList DataSections;
|
| + SectionList RelDataSections;
|
| + SectionList RoDataSections;
|
| + SectionList RelRoDataSections;
|
| +
|
| + // Handles to special sections that need incremental bookkeeping.
|
| + ELFSection *NullSection;
|
| + ELFStringTableSection *ShStrTab;
|
| + ELFSymbolTableSection *SymTab;
|
| + ELFStringTableSection *StrTab;
|
| +
|
| + template <typename T>
|
| + T *createSection(const IceString &Name, Elf64_Word sh_type,
|
| + Elf64_Xword sh_flags, Elf64_Xword sh_addralign,
|
| + Elf64_Xword sh_entsize);
|
| +
|
| + // Align the file position before writing out a section's data,
|
| + // and return the position of the file.
|
| + Elf64_Off alignFileOffset(Elf64_Xword Align);
|
| +
|
| + // Assign an ordering / section numbers to each section.
|
| + // Fill in other information that is only known near the end
|
| + // (such as the size, if it wasn't already incrementally updated),
|
| + // Then put them all in one vector for conveniently writing out
|
| + // all of the section headers.
|
| + void assignSectionNumbersInfo(SectionList &AllSections);
|
| +
|
| + void assignRelSectionNumInPairs(SizeT &CurSectionNumber,
|
| + SectionList &UserSections,
|
| + SectionList &RelSections,
|
| + SectionList &AllSections);
|
| +
|
| + void assignRelLinkNum(SizeT SymTabNumber, SectionList &RelSections);
|
| +
|
| + template <bool IsELF64>
|
| + void writeELFHeaderInternal(uint64_t SectionHeaderOffset,
|
| + SizeT SectHeaderStrIndex, SizeT NumSections);
|
| +};
|
| +
|
| +} // end of namespace Ice
|
| +
|
| +#endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H
|
|
|