Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceELFObjectWriter.cpp - ELF object file writer --------===// | 1 //===- subzero/src/IceELFObjectWriter.cpp - ELF object file writer --------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 Elf64_Off OffsetInFile = Str.tell(); | 210 Elf64_Off OffsetInFile = Str.tell(); |
| 211 Elf64_Xword AlignDiff = Utils::OffsetToAlignment(OffsetInFile, Align); | 211 Elf64_Xword AlignDiff = Utils::OffsetToAlignment(OffsetInFile, Align); |
| 212 if (AlignDiff == 0) | 212 if (AlignDiff == 0) |
| 213 return OffsetInFile; | 213 return OffsetInFile; |
| 214 Str.writeZeroPadding(AlignDiff); | 214 Str.writeZeroPadding(AlignDiff); |
| 215 OffsetInFile += AlignDiff; | 215 OffsetInFile += AlignDiff; |
| 216 return OffsetInFile; | 216 return OffsetInFile; |
| 217 } | 217 } |
| 218 | 218 |
| 219 void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, | 219 void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, |
| 220 bool IsInternal, const Assembler *Asm) { | 220 bool IsInternal, Assembler *Asm) { |
| 221 assert(!SectionNumbersAssigned); | 221 assert(!SectionNumbersAssigned); |
| 222 ELFTextSection *Section = nullptr; | 222 ELFTextSection *Section = nullptr; |
| 223 ELFRelocationSection *RelSection = nullptr; | 223 ELFRelocationSection *RelSection = nullptr; |
| 224 const bool FunctionSections = Ctx.getFlags().getFunctionSections(); | 224 const bool FunctionSections = Ctx.getFlags().getFunctionSections(); |
| 225 if (TextSections.empty() || FunctionSections) { | 225 if (TextSections.empty() || FunctionSections) { |
| 226 IceString SectionName = ".text"; | 226 IceString SectionName = ".text"; |
| 227 if (FunctionSections) | 227 if (FunctionSections) |
| 228 SectionName += "." + FuncName; | 228 SectionName += "." + FuncName; |
| 229 constexpr Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR; | 229 constexpr Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR; |
| 230 const Elf64_Xword ShAlign = 1 << Asm->getBundleAlignLog2Bytes(); | 230 const Elf64_Xword ShAlign = 1 << Asm->getBundleAlignLog2Bytes(); |
| 231 Section = createSection<ELFTextSection>(SectionName, SHT_PROGBITS, ShFlags, | 231 Section = createSection<ELFTextSection>(SectionName, SHT_PROGBITS, ShFlags, |
| 232 ShAlign, 0); | 232 ShAlign, 0); |
| 233 Elf64_Off OffsetInFile = alignFileOffset(Section->getSectionAlign()); | 233 Elf64_Off OffsetInFile = alignFileOffset(Section->getSectionAlign()); |
| 234 Section->setFileOffset(OffsetInFile); | 234 Section->setFileOffset(OffsetInFile); |
| 235 TextSections.push_back(Section); | 235 TextSections.push_back(Section); |
| 236 RelSection = createRelocationSection(Section); | 236 RelSection = createRelocationSection(Section); |
| 237 RelTextSections.push_back(RelSection); | 237 RelTextSections.push_back(RelSection); |
| 238 } else { | 238 } else { |
| 239 Section = TextSections[0]; | 239 Section = TextSections[0]; |
| 240 RelSection = RelTextSections[0]; | 240 RelSection = RelTextSections[0]; |
| 241 } | 241 } |
| 242 const RelocOffsetT OffsetInSection = Section->getCurrentSize(); | 242 const RelocOffsetT OffsetInSection = Section->getCurrentSize(); |
| 243 // Function symbols are set to 0 size in the symbol table, in contrast to | 243 // Function symbols are set to 0 size in the symbol table, in contrast to |
| 244 // data symbols which have a proper size. | 244 // data symbols which have a proper size. |
| 245 constexpr SizeT SymbolSize = 0; | 245 constexpr SizeT SymbolSize = 0; |
| 246 Section->appendData(Str, Asm->getBufferView()); | |
| 247 uint8_t SymbolType; | 246 uint8_t SymbolType; |
| 248 uint8_t SymbolBinding; | 247 uint8_t SymbolBinding; |
| 249 if (IsInternal && !Ctx.getFlags().getDisableInternal()) { | 248 if (IsInternal && !Ctx.getFlags().getDisableInternal()) { |
| 250 SymbolType = STT_NOTYPE; | 249 SymbolType = STT_NOTYPE; |
| 251 SymbolBinding = STB_LOCAL; | 250 SymbolBinding = STB_LOCAL; |
| 252 } else { | 251 } else { |
| 253 SymbolType = STT_FUNC; | 252 SymbolType = STT_FUNC; |
| 254 SymbolBinding = STB_GLOBAL; | 253 SymbolBinding = STB_GLOBAL; |
| 255 } | 254 } |
| 256 SymTab->createDefinedSym(FuncName, SymbolType, SymbolBinding, Section, | 255 SymTab->createDefinedSym(FuncName, SymbolType, SymbolBinding, Section, |
| 257 OffsetInSection, SymbolSize); | 256 OffsetInSection, SymbolSize); |
| 258 StrTab->add(FuncName); | 257 StrTab->add(FuncName); |
| 259 | 258 |
| 260 // Copy the fixup information from per-function Assembler memory to the | 259 // Copy the fixup information from per-function Assembler memory to the |
| 261 // object writer's memory, for writing later. | 260 // object writer's memory, for writing later. |
| 262 if (!Asm->fixups().empty()) { | 261 const auto &Fixups = Asm->fixups(); |
| 262 if (!Fixups.empty()) { | |
| 263 if (!RelSection->isRela()) { | |
| 264 // This is a non-rela section, so we need to update the instruction stream | |
| 265 // with the relocation addends. | |
| 266 for (const auto *Fixup : Fixups) { | |
|
Jim Stichnoth
2016/02/03 23:18:27
const AssemblerFixup *Fixup
John
2016/02/04 18:28:50
Discussed offline. Leaving as is.
| |
| 267 Fixup->emitOffset(Asm); | |
| 268 } | |
| 269 } | |
| 263 RelSection->addRelocations(OffsetInSection, Asm->fixups()); | 270 RelSection->addRelocations(OffsetInSection, Asm->fixups()); |
| 264 } | 271 } |
| 272 Section->appendData(Str, Asm->getBufferView()); | |
| 265 } | 273 } |
| 266 | 274 |
| 267 namespace { | 275 namespace { |
| 268 | 276 |
| 269 ELFObjectWriter::SectionType | 277 ELFObjectWriter::SectionType |
| 270 classifyGlobalSection(const VariableDeclaration *Var) { | 278 classifyGlobalSection(const VariableDeclaration *Var) { |
| 271 if (Var->getIsConstant()) | 279 if (Var->getIsConstant()) |
| 272 return ELFObjectWriter::ROData; | 280 return ELFObjectWriter::ROData; |
| 273 if (Var->hasNonzeroInitializer()) | 281 if (Var->hasNonzeroInitializer()) |
| 274 return ELFObjectWriter::Data; | 282 return ELFObjectWriter::Data; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 if (ELF64) { | 688 if (ELF64) { |
| 681 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), | 689 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), |
| 682 AllSections.size()); | 690 AllSections.size()); |
| 683 } else { | 691 } else { |
| 684 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), | 692 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), |
| 685 AllSections.size()); | 693 AllSections.size()); |
| 686 } | 694 } |
| 687 } | 695 } |
| 688 | 696 |
| 689 } // end of namespace Ice | 697 } // end of namespace Ice |
| OLD | NEW |