OLD | NEW |
1 //===- subzero/src/IceELFSection.h - Model of ELF sections ------*- C++ -*-===// | 1 //===- subzero/src/IceELFSection.h - Model of ELF sections ------*- C++ -*-===// |
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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 template <bool IsELF64> | 350 template <bool IsELF64> |
351 void ELFRelocationSection::writeData(const GlobalContext &Ctx, ELFStreamer &Str, | 351 void ELFRelocationSection::writeData(const GlobalContext &Ctx, ELFStreamer &Str, |
352 const ELFSymbolTableSection *SymTab) { | 352 const ELFSymbolTableSection *SymTab) { |
353 for (const AssemblerFixup &Fixup : Fixups) { | 353 for (const AssemblerFixup &Fixup : Fixups) { |
354 const ELFSym *Symbol; | 354 const ELFSym *Symbol; |
355 if (Fixup.isNullSymbol()) { | 355 if (Fixup.isNullSymbol()) { |
356 Symbol = SymTab->getNullSymbol(); | 356 Symbol = SymTab->getNullSymbol(); |
357 } else { | 357 } else { |
358 constexpr Assembler *Asm = nullptr; | 358 constexpr Assembler *Asm = nullptr; |
| 359 IceString Name = Fixup.symbol(&Ctx, Asm); |
359 Symbol = SymTab->findSymbol(Fixup.symbol(&Ctx, Asm)); | 360 Symbol = SymTab->findSymbol(Fixup.symbol(&Ctx, Asm)); |
| 361 if (!Symbol) |
| 362 llvm::report_fatal_error(Name + ": Missing symbol mentioned in reloc"); |
360 } | 363 } |
361 if (!Symbol) | |
362 llvm::report_fatal_error("Missing symbol mentioned in reloc"); | |
363 | 364 |
364 if (IsELF64) { | 365 if (IsELF64) { |
365 // TODO(jpp): check that Fixup.offset() is correct even for pc-rel. | |
366 Elf64_Rela Rela; | 366 Elf64_Rela Rela; |
367 Rela.r_offset = Fixup.position(); | 367 Rela.r_offset = Fixup.position(); |
368 Rela.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); | 368 Rela.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); |
369 Rela.r_addend = Fixup.offset(); | 369 Rela.r_addend = Fixup.offset(); |
| 370 if (Fixup.kind() == llvm::ELF::R_X86_64_PC32) { |
| 371 // In ELF64, PC-relative relocations' addends need to account for the |
| 372 // immediate size. For now, this is always 4 (because x86-64 sandboxed |
| 373 // is the only ELF64 target currently implemented.) |
| 374 constexpr int32_t RelocImmediateSize = 4; |
| 375 Rela.r_addend -= RelocImmediateSize; |
| 376 } |
370 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); | 377 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); |
371 Str.writeELFXword<IsELF64>(Rela.r_info); | 378 Str.writeELFXword<IsELF64>(Rela.r_info); |
372 Str.writeELFXword<IsELF64>(Rela.r_addend); | 379 Str.writeELFXword<IsELF64>(Rela.r_addend); |
373 } else { | 380 } else { |
374 Elf32_Rel Rel; | 381 Elf32_Rel Rel; |
375 Rel.r_offset = Fixup.position(); | 382 Rel.r_offset = Fixup.position(); |
376 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); | 383 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); |
377 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); | 384 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); |
378 Str.writeELFWord<IsELF64>(Rel.r_info); | 385 Str.writeELFWord<IsELF64>(Rel.r_info); |
379 } | 386 } |
380 } | 387 } |
381 } | 388 } |
382 | 389 |
383 } // end of namespace Ice | 390 } // end of namespace Ice |
384 | 391 |
385 #endif // SUBZERO_SRC_ICEELFSECTION_H | 392 #endif // SUBZERO_SRC_ICEELFSECTION_H |
OLD | NEW |