Index: src/IceELFObjectWriter.h |
diff --git a/src/IceELFObjectWriter.h b/src/IceELFObjectWriter.h |
index 9f468cb05ed5efaec6defbccced13d84cd35e67e..cb49539643f58ea3b19dc5359d38c481f02bab4d 100644 |
--- a/src/IceELFObjectWriter.h |
+++ b/src/IceELFObjectWriter.h |
@@ -30,7 +30,7 @@ namespace Ice { |
// sections and write them out. Expected usage: |
// |
// (1) writeInitialELFHeader |
-// (2) writeDataInitializer* |
+// (2) writeDataSection |
// (3) writeFunctionCode* |
// (4) writeNonUserSections |
class ELFObjectWriter { |
@@ -51,13 +51,11 @@ public: |
void writeFunctionCode(const IceString &FuncName, bool IsInternal, |
const Assembler *Asm); |
- // Copy initializer data for a global to file and note the offset and |
- // size of the global's definition in the symbol table. |
- // TODO(jvoung): This needs to know which section. This also needs the |
- // relocations to hook them up to the symbol table references. Also |
- // TODO is handling BSS (which just needs to note the size). |
- void writeDataInitializer(const IceString &VarName, |
- const llvm::StringRef Data); |
+ // Copy initializer data for globals to file and note the offset and size |
+ // of each global's definition in the symbol table. |
+ // Use the given target's RelocationKind for relocations. |
+ void writeDataSection(const VariableDeclarationList &Vars, |
+ FixupKind RelocationKind); |
template <typename ConstType> void writeConstantPool(Type Ty); |
@@ -65,6 +63,15 @@ public: |
// patch up the initial ELF header with the final info. |
void writeNonUserSections(); |
+ // Which type of ELF section a global variable initializer belongs to. |
+ enum SectionType { |
+ BaseSectionType = 0, |
+ ROData = BaseSectionType, |
+ Data, |
+ BSS, |
+ NumSectionTypes |
+ }; |
+ |
private: |
GlobalContext &Ctx; |
ELFStreamer &Str; |
@@ -79,8 +86,9 @@ private: |
RelSectionList RelTextSections; |
DataSectionList DataSections; |
RelSectionList RelDataSections; |
- DataSectionList RoDataSections; |
- RelSectionList RelRoDataSections; |
+ DataSectionList RODataSections; |
+ RelSectionList RelRODataSections; |
+ DataSectionList BSSSections; |
// Handles to special sections that need incremental bookkeeping. |
ELFSection *NullSection; |
@@ -93,6 +101,11 @@ private: |
Elf64_Xword ShFlags, Elf64_Xword ShAddralign, |
Elf64_Xword ShEntsize); |
+ // Create a relocation section, given the related section |
+ // (e.g., .text, .data., .rodata). |
+ ELFRelocationSection * |
+ createRelocationSection(bool IsELF64, const ELFSection *RelatedSection); |
+ |
// Align the file position before writing out a section's data, |
// and return the position of the file. |
Elf64_Off alignFileOffset(Elf64_Xword Align); |
@@ -116,6 +129,12 @@ private: |
// Link the relocation sections to the symbol table. |
void assignRelLinkNum(SizeT SymTabNumber, RelSectionList &RelSections); |
+ // Helper function for writeDataSection. Writes a data section of type |
+ // SectionType, given the global variables Vars belonging to that SectionType. |
+ void writeDataOfType(SectionType SectionType, |
+ const VariableDeclarationList &Vars, |
+ FixupKind RelocationKind, bool IsELF64); |
+ |
// Write the final relocation sections given the final symbol table. |
// May also be able to seek around the file and resolve function calls |
// that are for functions within the same section. |