Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: src/IceELFObjectWriter.h

Issue 678533005: Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: cleanup Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //===- subzero/src/IceELFObjectWriter.h - ELF object writer -----*- C++ -*-===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Interface for an ELF Object file writer.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SUBZERO_SRC_ICEELFOBJECTWRITER_H
15 #define SUBZERO_SRC_ICEELFOBJECTWRITER_H
16
17 #include "IceDefs.h"
18 #include "IceELFSection.h"
19 #include "IceELFStreamer.h"
20
21 using namespace llvm::ELF;
22
23 namespace Ice {
24
25 // Higher level ELF object writer. Manages section information and writes
26 // the final ELF object. The object writer will write to file the code
27 // and data from as it is being defined (rather than keep a copy).
28 // After all definitions are written out, it will do a final sort on the
29 // symbol table and string tables, then write such bookkeeping sections
30 // out and seek backward to patch up the ELF file header. Expected usage:
31 //
32 // (1) writeInitialELFHeader
33 // (2) writeDataInitializer*
34 // (3) writeFunctionCode*
35 // (4) writeNonUserSections
36 class ELFObjectWriter {
37 ELFObjectWriter(const ELFObjectWriter &) = delete;
38 ELFObjectWriter &operator=(const ELFObjectWriter &) = delete;
39
40 public:
41 ELFObjectWriter(GlobalContext &Ctx, ELFStreamer &Out);
42
43 // Write the initial ELF header, just to reserve space in the ELF
44 // file. This then allows the other functions of writing text
45 // and data to write directly to the file and get the right offset.
46 void writeInitialELFHeader();
47
48 // Copy final (non-resizeable) data of functions' text section to file.
49 // TODO(jvoung): This needs the relocations too adjust the offsets
50 // and hook them up to the symbol table references.
51 void writeFunctionCode(const IceString &FuncName, bool IsInternal,
52 const llvm::StringRef Data);
53
54 // Add way to write/copy data symbols / set initializers.
55 // TODO(jvoung): This needs to know which section.
56 // This also needs the relocations to hook them up to the symbol table
57 // references.
58 void writeDataInitializer(const IceString &VarName,
59 const llvm::StringRef Data);
60
61 // Do final layout and write out the rest of the object file
62 // Patch up the initial ELF header.
63 void writeNonUserSections();
64
65 private:
66 GlobalContext &Ctx;
67 ELFStreamer &Str;
68 bool SectionNumbersAssigned;
69
70 // All created sections, separated into different pools.
71 typedef std::vector<ELFSection *> SectionList;
72 SectionList TextSections;
73 SectionList RelTextSections;
74 SectionList DataSections;
75 SectionList RelDataSections;
76 SectionList RoDataSections;
77 SectionList RelRoDataSections;
78
79 // Handles to special sections that need incremental bookkeeping.
80 ELFSection *NullSection;
81 ELFStringTableSection *ShStrTab;
82 ELFSymbolTableSection *SymTab;
83 ELFStringTableSection *StrTab;
84
85 template <typename T>
86 T *createSection(const IceString &Name, Elf64_Word sh_type,
87 Elf64_Xword sh_flags, Elf64_Xword sh_addralign,
88 Elf64_Xword sh_entsize);
89
90 // Align the file position before writing out a section's data,
91 // and return the position of the file.
92 Elf64_Off alignFileOffset(Elf64_Xword Align);
93
94 // Assign an ordering / section numbers to each section.
95 // Fill in other information that is only known near the end
96 // (such as the size, if it wasn't already incrementally updated),
97 // Then put them all in one vector for conveniently writing out
98 // all of the section headers.
99 void assignSectionNumbersInfo(SectionList &AllSections);
100
101 void assignRelSectionNumInPairs(SizeT &CurSectionNumber,
102 SectionList &UserSections,
103 SectionList &RelSections,
104 SectionList &AllSections);
105
106 void assignRelLinkNum(SizeT SymTabNumber, SectionList &RelSections);
107
108 template <bool IsELF64>
109 void writeELFHeaderInternal(uint64_t SectionHeaderOffset,
110 SizeT SectHeaderStrIndex, SizeT NumSections);
111 };
112
113 } // end of namespace Ice
114
115 #endif // SUBZERO_SRC_ICEELFOBJECTWRITER_H
OLDNEW
« no previous file with comments | « src/IceDefs.h ('k') | src/IceELFObjectWriter.cpp » ('j') | src/IceMemoryRegion.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698