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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 Symbol = SymTab->findSymbol(Name); | 360 Symbol = SymTab->findSymbol(Name); |
361 if (!Symbol) | 361 if (!Symbol) |
362 llvm::report_fatal_error(Name + ": Missing symbol mentioned in reloc"); | 362 llvm::report_fatal_error(Name + ": Missing symbol mentioned in reloc"); |
363 } | 363 } |
364 | 364 |
365 if (IsELF64) { | 365 if (IsELF64) { |
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 } | |
377 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); | 370 Str.writeAddrOrOffset<IsELF64>(Rela.r_offset); |
378 Str.writeELFXword<IsELF64>(Rela.r_info); | 371 Str.writeELFXword<IsELF64>(Rela.r_info); |
379 Str.writeELFXword<IsELF64>(Rela.r_addend); | 372 Str.writeELFXword<IsELF64>(Rela.r_addend); |
380 } else { | 373 } else { |
381 Elf32_Rel Rel; | 374 Elf32_Rel Rel; |
382 Rel.r_offset = Fixup.position(); | 375 Rel.r_offset = Fixup.position(); |
383 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); | 376 Rel.setSymbolAndType(Symbol->getNumber(), Fixup.kind()); |
384 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); | 377 Str.writeAddrOrOffset<IsELF64>(Rel.r_offset); |
385 Str.writeELFWord<IsELF64>(Rel.r_info); | 378 Str.writeELFWord<IsELF64>(Rel.r_info); |
386 } | 379 } |
387 } | 380 } |
388 } | 381 } |
389 | 382 |
390 } // end of namespace Ice | 383 } // end of namespace Ice |
391 | 384 |
392 #endif // SUBZERO_SRC_ICEELFSECTION_H | 385 #endif // SUBZERO_SRC_ICEELFSECTION_H |
OLD | NEW |