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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 const IceString NullSectionName(""); | 71 const IceString NullSectionName(""); |
| 72 NullSection = new (Ctx.allocate<ELFSection>()) | 72 NullSection = new (Ctx.allocate<ELFSection>()) |
| 73 ELFSection(NullSectionName, SHT_NULL, 0, 0, 0); | 73 ELFSection(NullSectionName, SHT_NULL, 0, 0, 0); |
| 74 | 74 |
| 75 const IceString ShStrTabName(".shstrtab"); | 75 const IceString ShStrTabName(".shstrtab"); |
| 76 ShStrTab = new (Ctx.allocate<ELFStringTableSection>()) | 76 ShStrTab = new (Ctx.allocate<ELFStringTableSection>()) |
| 77 ELFStringTableSection(ShStrTabName, SHT_STRTAB, 0, 1, 0); | 77 ELFStringTableSection(ShStrTabName, SHT_STRTAB, 0, 1, 0); |
| 78 ShStrTab->add(ShStrTabName); | 78 ShStrTab->add(ShStrTabName); |
| 79 | 79 |
| 80 const IceString SymTabName(".symtab"); | 80 const IceString SymTabName(".symtab"); |
| 81 const Elf64_Xword SymTabAlign = ELF64 ? 8 : 4; | 81 const Elf64_Xword SymTabAlign = ELF64 ? 8 : 4; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
No because ELF64 is not a constexpr.
| |
| 82 const Elf64_Xword SymTabEntSize = | 82 const Elf64_Xword SymTabEntSize = |
| 83 ELF64 ? sizeof(Elf64_Sym) : sizeof(Elf32_Sym); | 83 ELF64 ? sizeof(Elf64_Sym) : sizeof(Elf32_Sym); |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
No because ELF64 is not a constexpr.
| |
| 84 static_assert(sizeof(Elf64_Sym) == 24 && sizeof(Elf32_Sym) == 16, | 84 static_assert(sizeof(Elf64_Sym) == 24 && sizeof(Elf32_Sym) == 16, |
| 85 "Elf_Sym sizes cannot be derived from sizeof"); | 85 "Elf_Sym sizes cannot be derived from sizeof"); |
| 86 SymTab = createSection<ELFSymbolTableSection>(SymTabName, SHT_SYMTAB, 0, | 86 SymTab = createSection<ELFSymbolTableSection>(SymTabName, SHT_SYMTAB, 0, |
| 87 SymTabAlign, SymTabEntSize); | 87 SymTabAlign, SymTabEntSize); |
| 88 SymTab->createNullSymbol(NullSection); | 88 SymTab->createNullSymbol(NullSection); |
| 89 | 89 |
| 90 const IceString StrTabName(".strtab"); | 90 const IceString StrTabName(".strtab"); |
| 91 StrTab = | 91 StrTab = |
| 92 createSection<ELFStringTableSection>(StrTabName, SHT_STRTAB, 0, 1, 0); | 92 createSection<ELFStringTableSection>(StrTabName, SHT_STRTAB, 0, 1, 0); |
| 93 } | 93 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, | 211 void ELFObjectWriter::writeFunctionCode(const IceString &FuncName, |
| 212 bool IsInternal, const Assembler *Asm) { | 212 bool IsInternal, const Assembler *Asm) { |
| 213 assert(!SectionNumbersAssigned); | 213 assert(!SectionNumbersAssigned); |
| 214 ELFTextSection *Section = nullptr; | 214 ELFTextSection *Section = nullptr; |
| 215 ELFRelocationSection *RelSection = nullptr; | 215 ELFRelocationSection *RelSection = nullptr; |
| 216 const bool FunctionSections = Ctx.getFlags().getFunctionSections(); | 216 const bool FunctionSections = Ctx.getFlags().getFunctionSections(); |
| 217 if (TextSections.empty() || FunctionSections) { | 217 if (TextSections.empty() || FunctionSections) { |
| 218 IceString SectionName = ".text"; | 218 IceString SectionName = ".text"; |
| 219 if (FunctionSections) | 219 if (FunctionSections) |
| 220 SectionName += "." + FuncName; | 220 SectionName += "." + FuncName; |
| 221 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR; | 221 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_EXECINSTR; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 222 const Elf64_Xword ShAlign = 1 << Asm->getBundleAlignLog2Bytes(); | 222 const Elf64_Xword ShAlign = 1 << Asm->getBundleAlignLog2Bytes(); |
| 223 Section = createSection<ELFTextSection>(SectionName, SHT_PROGBITS, ShFlags, | 223 Section = createSection<ELFTextSection>(SectionName, SHT_PROGBITS, ShFlags, |
| 224 ShAlign, 0); | 224 ShAlign, 0); |
| 225 Elf64_Off OffsetInFile = alignFileOffset(Section->getSectionAlign()); | 225 Elf64_Off OffsetInFile = alignFileOffset(Section->getSectionAlign()); |
| 226 Section->setFileOffset(OffsetInFile); | 226 Section->setFileOffset(OffsetInFile); |
| 227 TextSections.push_back(Section); | 227 TextSections.push_back(Section); |
| 228 RelSection = createRelocationSection(Section); | 228 RelSection = createRelocationSection(Section); |
| 229 RelTextSections.push_back(RelSection); | 229 RelTextSections.push_back(RelSection); |
| 230 } else { | 230 } else { |
| 231 Section = TextSections[0]; | 231 Section = TextSections[0]; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 Elf64_Xword ShAddralign = 1; | 320 Elf64_Xword ShAddralign = 1; |
| 321 for (VariableDeclaration *Var : Vars) { | 321 for (VariableDeclaration *Var : Vars) { |
| 322 Elf64_Xword Align = Var->getAlignment(); | 322 Elf64_Xword Align = Var->getAlignment(); |
| 323 ShAddralign = std::max(ShAddralign, Align); | 323 ShAddralign = std::max(ShAddralign, Align); |
| 324 } | 324 } |
| 325 const Elf64_Xword ShEntsize = 0; // non-uniform data element size. | 325 const Elf64_Xword ShEntsize = 0; // non-uniform data element size. |
| 326 // Lift this out, so it can be re-used if we do fdata-sections? | 326 // Lift this out, so it can be re-used if we do fdata-sections? |
| 327 switch (ST) { | 327 switch (ST) { |
| 328 case ROData: { | 328 case ROData: { |
| 329 const IceString SectionName = MangleSectionName(".rodata", SectionSuffix); | 329 const IceString SectionName = MangleSectionName(".rodata", SectionSuffix); |
| 330 const Elf64_Xword ShFlags = SHF_ALLOC; | 330 const Elf64_Xword ShFlags = SHF_ALLOC; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 331 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, ShFlags, | 331 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, ShFlags, |
| 332 ShAddralign, ShEntsize); | 332 ShAddralign, ShEntsize); |
| 333 Section->setFileOffset(alignFileOffset(ShAddralign)); | 333 Section->setFileOffset(alignFileOffset(ShAddralign)); |
| 334 RODataSections.push_back(Section); | 334 RODataSections.push_back(Section); |
| 335 RelSection = createRelocationSection(Section); | 335 RelSection = createRelocationSection(Section); |
| 336 RelRODataSections.push_back(RelSection); | 336 RelRODataSections.push_back(RelSection); |
| 337 break; | 337 break; |
| 338 } | 338 } |
| 339 case Data: { | 339 case Data: { |
| 340 const IceString SectionName = MangleSectionName(".data", SectionSuffix); | 340 const IceString SectionName = MangleSectionName(".data", SectionSuffix); |
| 341 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_WRITE; | 341 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_WRITE; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 342 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, ShFlags, | 342 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, ShFlags, |
| 343 ShAddralign, ShEntsize); | 343 ShAddralign, ShEntsize); |
| 344 Section->setFileOffset(alignFileOffset(ShAddralign)); | 344 Section->setFileOffset(alignFileOffset(ShAddralign)); |
| 345 DataSections.push_back(Section); | 345 DataSections.push_back(Section); |
| 346 RelSection = createRelocationSection(Section); | 346 RelSection = createRelocationSection(Section); |
| 347 RelDataSections.push_back(RelSection); | 347 RelDataSections.push_back(RelSection); |
| 348 break; | 348 break; |
| 349 } | 349 } |
| 350 case BSS: { | 350 case BSS: { |
| 351 const IceString SectionName = MangleSectionName(".bss", SectionSuffix); | 351 const IceString SectionName = MangleSectionName(".bss", SectionSuffix); |
| 352 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_WRITE; | 352 const Elf64_Xword ShFlags = SHF_ALLOC | SHF_WRITE; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 353 Section = createSection<ELFDataSection>(SectionName, SHT_NOBITS, ShFlags, | 353 Section = createSection<ELFDataSection>(SectionName, SHT_NOBITS, ShFlags, |
| 354 ShAddralign, ShEntsize); | 354 ShAddralign, ShEntsize); |
| 355 Section->setFileOffset(alignFileOffset(ShAddralign)); | 355 Section->setFileOffset(alignFileOffset(ShAddralign)); |
| 356 BSSSections.push_back(Section); | 356 BSSSections.push_back(Section); |
| 357 break; | 357 break; |
| 358 } | 358 } |
| 359 case NumSectionTypes: | 359 case NumSectionTypes: |
| 360 llvm::report_fatal_error("Unknown SectionType"); | 360 llvm::report_fatal_error("Unknown SectionType"); |
| 361 break; | 361 break; |
| 362 } | 362 } |
| 363 | 363 |
| 364 const uint8_t SymbolType = STT_OBJECT; | 364 const uint8_t SymbolType = STT_OBJECT; |
| 365 for (VariableDeclaration *Var : Vars) { | 365 for (VariableDeclaration *Var : Vars) { |
| 366 // If the variable declaration does not have an initializer, its symtab | 366 // If the variable declaration does not have an initializer, its symtab |
| 367 // entry will be created separately. | 367 // entry will be created separately. |
| 368 if (!Var->hasInitializer()) | 368 if (!Var->hasInitializer()) |
| 369 continue; | 369 continue; |
| 370 Elf64_Xword Align = Var->getAlignment(); | 370 Elf64_Xword Align = Var->getAlignment(); |
| 371 const Elf64_Xword MinAlign = 1; | 371 const Elf64_Xword MinAlign = 1; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 372 Align = std::max(Align, MinAlign); | 372 Align = std::max(Align, MinAlign); |
| 373 Section->padToAlignment(Str, Align); | 373 Section->padToAlignment(Str, Align); |
| 374 SizeT SymbolSize = Var->getNumBytes(); | 374 SizeT SymbolSize = Var->getNumBytes(); |
| 375 bool IsExternal = Var->isExternal() || Ctx.getFlags().getDisableInternal(); | 375 bool IsExternal = Var->isExternal() || Ctx.getFlags().getDisableInternal(); |
| 376 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; | 376 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
no because of IsExternal.
| |
| 377 IceString MangledName = Var->mangleName(&Ctx); | 377 IceString MangledName = Var->mangleName(&Ctx); |
| 378 SymTab->createDefinedSym(MangledName, SymbolType, SymbolBinding, Section, | 378 SymTab->createDefinedSym(MangledName, SymbolType, SymbolBinding, Section, |
| 379 Section->getCurrentSize(), SymbolSize); | 379 Section->getCurrentSize(), SymbolSize); |
| 380 StrTab->add(MangledName); | 380 StrTab->add(MangledName); |
| 381 if (!Var->hasNonzeroInitializer()) { | 381 if (!Var->hasNonzeroInitializer()) { |
| 382 assert(ST == BSS || ST == ROData); | 382 assert(ST == BSS || ST == ROData); |
| 383 if (ST == ROData) | 383 if (ST == ROData) |
| 384 Section->appendZeros(Str, SymbolSize); | 384 Section->appendZeros(Str, SymbolSize); |
| 385 else | 385 else |
| 386 Section->setSize(Section->getCurrentSize() + SymbolSize); | 386 Section->setSize(Section->getCurrentSize() + SymbolSize); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 398 } | 398 } |
| 399 case VariableDeclaration::Initializer::ZeroInitializerKind: | 399 case VariableDeclaration::Initializer::ZeroInitializerKind: |
| 400 Section->appendZeros(Str, Init->getNumBytes()); | 400 Section->appendZeros(Str, Init->getNumBytes()); |
| 401 break; | 401 break; |
| 402 case VariableDeclaration::Initializer::RelocInitializerKind: { | 402 case VariableDeclaration::Initializer::RelocInitializerKind: { |
| 403 const auto Reloc = | 403 const auto Reloc = |
| 404 llvm::cast<VariableDeclaration::RelocInitializer>(Init.get()); | 404 llvm::cast<VariableDeclaration::RelocInitializer>(Init.get()); |
| 405 AssemblerFixup NewFixup; | 405 AssemblerFixup NewFixup; |
| 406 NewFixup.set_position(Section->getCurrentSize()); | 406 NewFixup.set_position(Section->getCurrentSize()); |
| 407 NewFixup.set_kind(RelocationKind); | 407 NewFixup.set_kind(RelocationKind); |
| 408 const bool SuppressMangling = true; | 408 constexpr bool SuppressMangling = true; |
| 409 NewFixup.set_value(Ctx.getConstantSym( | 409 NewFixup.set_value(Ctx.getConstantSym( |
| 410 Reloc->getOffset(), Reloc->getDeclaration()->mangleName(&Ctx), | 410 Reloc->getOffset(), Reloc->getDeclaration()->mangleName(&Ctx), |
| 411 SuppressMangling)); | 411 SuppressMangling)); |
| 412 RelSection->addRelocation(NewFixup); | 412 RelSection->addRelocation(NewFixup); |
| 413 Section->appendRelocationOffset(Str, RelSection->isRela(), | 413 Section->appendRelocationOffset(Str, RelSection->isRela(), |
| 414 Reloc->getOffset()); | 414 Reloc->getOffset()); |
| 415 break; | 415 break; |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 void ELFObjectWriter::writeInitialELFHeader() { | 423 void ELFObjectWriter::writeInitialELFHeader() { |
| 424 assert(!SectionNumbersAssigned); | 424 assert(!SectionNumbersAssigned); |
| 425 const Elf64_Off DummySHOffset = 0; | 425 const Elf64_Off DummySHOffset = 0; |
|
Karl
2015/10/27 16:13:18
More constexprs?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 426 const SizeT DummySHStrIndex = 0; | 426 const SizeT DummySHStrIndex = 0; |
| 427 const SizeT DummyNumSections = 0; | 427 const SizeT DummyNumSections = 0; |
| 428 if (ELF64) { | 428 if (ELF64) { |
| 429 writeELFHeaderInternal<true>(DummySHOffset, DummySHStrIndex, | 429 writeELFHeaderInternal<true>(DummySHOffset, DummySHStrIndex, |
| 430 DummyNumSections); | 430 DummyNumSections); |
| 431 } else { | 431 } else { |
| 432 writeELFHeaderInternal<false>(DummySHOffset, DummySHStrIndex, | 432 writeELFHeaderInternal<false>(DummySHOffset, DummySHStrIndex, |
| 433 DummyNumSections); | 433 DummyNumSections); |
| 434 } | 434 } |
| 435 } | 435 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 Operand::OperandKind K = (*Pool.begin())->getKind(); | 516 Operand::OperandKind K = (*Pool.begin())->getKind(); |
| 517 RandomNumberGenerator RNG(Ctx.getFlags().getRandomSeed(), | 517 RandomNumberGenerator RNG(Ctx.getFlags().getRandomSeed(), |
| 518 RPE_PooledConstantReordering, K); | 518 RPE_PooledConstantReordering, K); |
| 519 RandomShuffle(Pool.begin(), Pool.end(), | 519 RandomShuffle(Pool.begin(), Pool.end(), |
| 520 [&RNG](uint64_t N) { return (uint32_t)RNG.next(N); }); | 520 [&RNG](uint64_t N) { return (uint32_t)RNG.next(N); }); |
| 521 } | 521 } |
| 522 // Write the data. | 522 // Write the data. |
| 523 for (Constant *C : Pool) { | 523 for (Constant *C : Pool) { |
| 524 if (!C->getShouldBePooled()) | 524 if (!C->getShouldBePooled()) |
| 525 continue; | 525 continue; |
| 526 auto Const = llvm::cast<ConstType>(C); | 526 auto *Const = llvm::cast<ConstType>(C); |
| 527 std::string SymBuffer; | 527 std::string SymBuffer; |
| 528 llvm::raw_string_ostream SymStrBuf(SymBuffer); | 528 llvm::raw_string_ostream SymStrBuf(SymBuffer); |
| 529 Const->emitPoolLabel(SymStrBuf, &Ctx); | 529 Const->emitPoolLabel(SymStrBuf, &Ctx); |
| 530 std::string &SymName = SymStrBuf.str(); | 530 std::string &SymName = SymStrBuf.str(); |
| 531 SymTab->createDefinedSym(SymName, STT_NOTYPE, STB_LOCAL, Section, | 531 SymTab->createDefinedSym(SymName, STT_NOTYPE, STB_LOCAL, Section, |
| 532 OffsetInSection, SymbolSize); | 532 OffsetInSection, SymbolSize); |
| 533 StrTab->add(SymName); | 533 StrTab->add(SymName); |
| 534 typename ConstType::PrimType Value = Const->getValue(); | 534 typename ConstType::PrimType Value = Const->getValue(); |
| 535 memcpy(Buf, &Value, WriteAmt); | 535 memcpy(Buf, &Value, WriteAmt); |
| 536 Str.writeBytes(llvm::StringRef(Buf, WriteAmt)); | 536 Str.writeBytes(llvm::StringRef(Buf, WriteAmt)); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 565 const Elf64_Xword ShEntsize = PointerSize; | 565 const Elf64_Xword ShEntsize = PointerSize; |
| 566 const IceString SectionName = | 566 const IceString SectionName = |
| 567 MangleSectionName(".rodata", JT.getFunctionName() + "$jumptable"); | 567 MangleSectionName(".rodata", JT.getFunctionName() + "$jumptable"); |
| 568 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, SHF_ALLOC, | 568 Section = createSection<ELFDataSection>(SectionName, SHT_PROGBITS, SHF_ALLOC, |
| 569 ShAddralign, ShEntsize); | 569 ShAddralign, ShEntsize); |
| 570 Section->setFileOffset(alignFileOffset(ShAddralign)); | 570 Section->setFileOffset(alignFileOffset(ShAddralign)); |
| 571 RODataSections.push_back(Section); | 571 RODataSections.push_back(Section); |
| 572 RelSection = createRelocationSection(Section); | 572 RelSection = createRelocationSection(Section); |
| 573 RelRODataSections.push_back(RelSection); | 573 RelRODataSections.push_back(RelSection); |
| 574 | 574 |
| 575 const uint8_t SymbolType = STT_OBJECT; | 575 const uint8_t SymbolType = STT_OBJECT; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
Done.
| |
| 576 Section->padToAlignment(Str, PointerSize); | 576 Section->padToAlignment(Str, PointerSize); |
| 577 bool IsExternal = Ctx.getFlags().getDisableInternal(); | 577 bool IsExternal = Ctx.getFlags().getDisableInternal(); |
| 578 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; | 578 const uint8_t SymbolBinding = IsExternal ? STB_GLOBAL : STB_LOCAL; |
| 579 IceString JumpTableName = | 579 IceString JumpTableName = |
| 580 InstJumpTable::makeName(JT.getFunctionName(), JT.getId()); | 580 InstJumpTable::makeName(JT.getFunctionName(), JT.getId()); |
| 581 SymTab->createDefinedSym(JumpTableName, SymbolType, SymbolBinding, Section, | 581 SymTab->createDefinedSym(JumpTableName, SymbolType, SymbolBinding, Section, |
| 582 Section->getCurrentSize(), PointerSize); | 582 Section->getCurrentSize(), PointerSize); |
| 583 StrTab->add(JumpTableName); | 583 StrTab->add(JumpTableName); |
| 584 | 584 |
| 585 for (intptr_t TargetOffset : JT.getTargetOffsets()) { | 585 for (intptr_t TargetOffset : JT.getTargetOffsets()) { |
| 586 AssemblerFixup NewFixup; | 586 AssemblerFixup NewFixup; |
| 587 NewFixup.set_position(Section->getCurrentSize()); | 587 NewFixup.set_position(Section->getCurrentSize()); |
| 588 NewFixup.set_kind(RelocationKind); | 588 NewFixup.set_kind(RelocationKind); |
| 589 constexpr bool SuppressMangling = true; | 589 constexpr bool SuppressMangling = true; |
| 590 NewFixup.set_value(Ctx.getConstantSym(TargetOffset, JT.getFunctionName(), | 590 NewFixup.set_value(Ctx.getConstantSym(TargetOffset, JT.getFunctionName(), |
| 591 SuppressMangling)); | 591 SuppressMangling)); |
| 592 RelSection->addRelocation(NewFixup); | 592 RelSection->addRelocation(NewFixup); |
| 593 Section->appendRelocationOffset(Str, RelSection->isRela(), TargetOffset); | 593 Section->appendRelocationOffset(Str, RelSection->isRela(), TargetOffset); |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 | 596 |
| 597 void ELFObjectWriter::setUndefinedSyms(const ConstantList &UndefSyms) { | 597 void ELFObjectWriter::setUndefinedSyms(const ConstantList &UndefSyms) { |
| 598 for (const Constant *S : UndefSyms) { | 598 for (const Constant *S : UndefSyms) { |
| 599 const auto Sym = llvm::cast<ConstantRelocatable>(S); | 599 const auto *Sym = llvm::cast<ConstantRelocatable>(S); |
| 600 const IceString &Name = Sym->getName(); | 600 const IceString &Name = Sym->getName(); |
| 601 bool BadIntrinsic; | 601 bool BadIntrinsic; |
| 602 const Intrinsics::FullIntrinsicInfo *Info = | 602 const Intrinsics::FullIntrinsicInfo *Info = |
| 603 Ctx.getIntrinsicsInfo().find(Name, BadIntrinsic); | 603 Ctx.getIntrinsicsInfo().find(Name, BadIntrinsic); |
| 604 if (Info) | 604 if (Info) |
| 605 continue; | 605 continue; |
| 606 // Ignore BadIntrinsic, which is set if the name begins with "llvm." but | 606 // Ignore BadIntrinsic, which is set if the name begins with "llvm." but |
| 607 // doesn't match a known intrinsic. If we want this to turn into an error, | 607 // doesn't match a known intrinsic. If we want this to turn into an error, |
| 608 // we should catch it early on. | 608 // we should catch it early on. |
| 609 assert(Sym->getOffset() == 0); | 609 assert(Sym->getOffset() == 0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 SymTab->setSize(SymTab->getSectionDataSize()); | 648 SymTab->setSize(SymTab->getSectionDataSize()); |
| 649 SymTab->writeData(Str, ELF64); | 649 SymTab->writeData(Str, ELF64); |
| 650 | 650 |
| 651 Elf64_Off StrTabOffset = alignFileOffset(StrTab->getSectionAlign()); | 651 Elf64_Off StrTabOffset = alignFileOffset(StrTab->getSectionAlign()); |
| 652 StrTab->setFileOffset(StrTabOffset); | 652 StrTab->setFileOffset(StrTabOffset); |
| 653 Str.writeBytes(StrTab->getSectionData()); | 653 Str.writeBytes(StrTab->getSectionData()); |
| 654 | 654 |
| 655 writeAllRelocationSections(); | 655 writeAllRelocationSections(); |
| 656 | 656 |
| 657 // Write out the section headers. | 657 // Write out the section headers. |
| 658 const size_t ShdrAlign = ELF64 ? 8 : 4; | 658 const size_t ShdrAlign = ELF64 ? 8 : 4; |
|
Karl
2015/10/27 16:13:18
constexpr?
Jim Stichnoth
2015/10/27 19:14:09
no because of ELF64.
| |
| 659 Elf64_Off ShOffset = alignFileOffset(ShdrAlign); | 659 Elf64_Off ShOffset = alignFileOffset(ShdrAlign); |
| 660 for (const auto S : AllSections) { | 660 for (const auto S : AllSections) { |
| 661 if (ELF64) | 661 if (ELF64) |
| 662 S->writeHeader<true>(Str); | 662 S->writeHeader<true>(Str); |
| 663 else | 663 else |
| 664 S->writeHeader<false>(Str); | 664 S->writeHeader<false>(Str); |
| 665 } | 665 } |
| 666 | 666 |
| 667 // Finally write the updated ELF header w/ the correct number of sections. | 667 // Finally write the updated ELF header w/ the correct number of sections. |
| 668 Str.seek(0); | 668 Str.seek(0); |
| 669 if (ELF64) { | 669 if (ELF64) { |
| 670 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), | 670 writeELFHeaderInternal<true>(ShOffset, ShStrTab->getNumber(), |
| 671 AllSections.size()); | 671 AllSections.size()); |
| 672 } else { | 672 } else { |
| 673 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), | 673 writeELFHeaderInternal<false>(ShOffset, ShStrTab->getNumber(), |
| 674 AllSections.size()); | 674 AllSections.size()); |
| 675 } | 675 } |
| 676 } | 676 } |
| 677 | 677 |
| 678 } // end of namespace Ice | 678 } // end of namespace Ice |
| OLD | NEW |