Chromium Code Reviews| Index: src/IceELFObjectWriter.cpp |
| diff --git a/src/IceELFObjectWriter.cpp b/src/IceELFObjectWriter.cpp |
| index edb46fae0af2f2406b5e5e3bcbeca0cd993a9a29..94e86a58dd434db7b65d5d203530cc42e315345b 100644 |
| --- a/src/IceELFObjectWriter.cpp |
| +++ b/src/IceELFObjectWriter.cpp |
| @@ -12,6 +12,7 @@ |
| //===----------------------------------------------------------------------===// |
| #include "llvm/Support/MathExtras.h" |
| +#include "llvm/Support/raw_ostream.h" |
| #include "IceAssembler.h" |
| #include "IceDefs.h" |
| @@ -285,7 +286,8 @@ void partitionGlobalsBySection(const VariableDeclarationList &Vars, |
| } // end of anonymous namespace |
| void ELFObjectWriter::writeDataSection(const VariableDeclarationList &Vars, |
| - FixupKind RelocationKind) { |
| + FixupKind RelocationKind, |
| + const IceString &SectionSuffix) { |
| assert(!SectionNumbersAssigned); |
| VariableDeclarationList VarsBySection[ELFObjectWriter::NumSectionTypes]; |
| for (auto &SectionList : VarsBySection) |
| @@ -294,18 +296,31 @@ void ELFObjectWriter::writeDataSection(const VariableDeclarationList &Vars, |
| Ctx.getFlags().getTranslateOnly()); |
| size_t I = 0; |
| for (auto &SectionList : VarsBySection) { |
| - writeDataOfType(static_cast<SectionType>(I++), SectionList, RelocationKind); |
| + writeDataOfType(static_cast<SectionType>(I++), SectionList, RelocationKind, |
| + SectionSuffix); |
| } |
| } |
| +namespace { |
| +IceString MangleSectionName(const char Base[], const IceString &Suffix) { |
| + if (Suffix.empty()) |
| + return Base; |
| + IceString MangledName; |
|
Jim Stichnoth
2015/06/17 16:04:56
Can you just
return Base + "." + Suffix;
?
and t
John
2015/06/17 18:18:35
Not that it matters, but I have a hunch using the
|
| + llvm::raw_string_ostream Ostream(MangledName); |
| + Ostream << Base << "." << Suffix; |
| + return MangledName; |
| +} |
| +} // end of anonymous namespace |
| + |
| +// TODO(jvoung): Handle fdata-sections. |
| void ELFObjectWriter::writeDataOfType(SectionType ST, |
| const VariableDeclarationList &Vars, |
| - FixupKind RelocationKind) { |
| + FixupKind RelocationKind, |
| + const IceString &SectionSuffix) { |
| if (Vars.empty()) |
| return; |
| ELFDataSection *Section; |
| ELFRelocationSection *RelSection; |
| - // TODO(jvoung): Handle fdata-sections. |
| IceString SectionName; |
| Elf64_Xword ShAddralign = 1; |
| for (VariableDeclaration *Var : Vars) { |
| @@ -316,9 +331,7 @@ void ELFObjectWriter::writeDataOfType(SectionType ST, |
| // Lift this out, so it can be re-used if we do fdata-sections? |
| switch (ST) { |
| case ROData: { |
| - SectionName = ".rodata"; |
| - // Only expecting to write the data sections all in one shot for now. |
| - assert(RODataSections.empty()); |
| + const IceString SectionName = MangleSectionName(".rodata", SectionSuffix); |
| const Elf64_Xword ShFlags = SHF_ALLOC; |
| Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, ShFlags, |
| ShAddralign, ShEntsize); |
| @@ -329,8 +342,7 @@ void ELFObjectWriter::writeDataOfType(SectionType ST, |
| break; |
| } |
| case Data: { |
| - SectionName = ".data"; |
| - assert(DataSections.empty()); |
| + const IceString SectionName = MangleSectionName(".data", SectionSuffix); |
| const Elf64_Xword ShFlags = SHF_ALLOC | SHF_WRITE; |
| Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, ShFlags, |
| ShAddralign, ShEntsize); |
| @@ -341,8 +353,7 @@ void ELFObjectWriter::writeDataOfType(SectionType ST, |
| break; |
| } |
| case BSS: { |
| - SectionName = ".bss"; |
| - assert(BSSSections.empty()); |
| + const IceString SectionName = MangleSectionName(".bss", SectionSuffix); |
| const Elf64_Xword ShFlags = SHF_ALLOC | SHF_WRITE; |
| Section = createSection<ELFDataSection>(SectionName, SHT_NOBITS, ShFlags, |
| ShAddralign, ShEntsize); |
| @@ -383,9 +394,8 @@ void ELFObjectWriter::writeDataOfType(SectionType ST, |
| for (VariableDeclaration::Initializer *Init : Var->getInitializers()) { |
| switch (Init->getKind()) { |
| case VariableDeclaration::Initializer::DataInitializerKind: { |
| - const auto Data = |
| - llvm::cast<VariableDeclaration::DataInitializer>(Init) |
| - ->getContents(); |
| + const auto Data = llvm::cast<VariableDeclaration::DataInitializer>( |
| + Init)->getContents(); |
| Section->appendData(Str, llvm::StringRef(Data.data(), Data.size())); |
| break; |
| } |