llvm-project/lld/ELF
Fangrui Song b257d3c8a8 [ELF][PPC64] Suppress toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen
The current implementation assumes that R_PPC64_TOC16_HA is always followed
by R_PPC64_TOC16_LO_DS. This can break with R_PPC64_TOC16_LO:

  // Load the address of the TOC entry, instead of the value stored at that address
  addis 3, 2, .LC0@tloc@ha  # R_PPC64_TOC16_HA
  addi  3, 3, .LC0@tloc@l   # R_PPC64_TOC16_LO
  blr

which is used by boringssl's util/fipstools/delocate/delocate.go
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/FIPS.md has some documentation.
In short, this tool converts an assembly file to avoid any potential relocations.
The distance to an input .toc is not a constant after linking, so it cannot use an `addis;ld` pair.
Instead, it jumps to a stub which loads the TOC entry address with `addis;addi`.

This patch checks the presence of R_PPC64_TOC16_LO and suppresses
toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen.
This approach is conservative and loses some relaxation opportunities but is easy to implement.

  addis 3, 2, .LC0@toc@ha  # no relaxation
  addi  3, 3, .LC0@toc@l   # no relaxation
  li    9, 0
  addis 4, 2, .LC0@toc@ha  # can relax but suppressed
  ld    4, .LC0@toc@l(4)   # can relax but suppressed

Also note that interleaved R_PPC64_TOC16_HA and R_PPC64_TOC16_LO_DS is
possible and this patch accounts for that.

  addis 3, 2, .LC1@toc@ha  # can relax
  addis 4, 2, .LC2@toc@ha  # can relax
  ld    3, .LC1@toc@l(3)   # can relax
  ld    4, .LC2@toc@l(4)   # can relax

Reviewed By: #powerpc, sfertile

Differential Revision: https://reviews.llvm.org/D78431
2020-04-30 09:16:51 -07:00
..
Arch [ELF][ARM] Increase default max-page-size from 4096 to 6536 2020-04-18 08:19:45 -07:00
AArch64ErrataFix.cpp [ELF] Rename relocateOne() to relocate() and pass `Relocation` to it 2020-01-25 12:00:18 -08:00
AArch64ErrataFix.h [ELF] Fix variable names in comments after VariableName -> variableName change 2019-07-16 05:50:45 +00:00
ARMErrataFix.cpp [ELF] Rename relocateOne() to relocate() and pass `Relocation` to it 2020-01-25 12:00:18 -08:00
ARMErrataFix.h [ELF][ARM] Implement --fix-cortex-a8 to fix erratum 657417 2019-09-16 09:38:38 +00:00
CMakeLists.txt [ThinLTO] Pass CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLP 2020-01-09 21:13:11 -08:00
CallGraphSort.cpp [lld] NFC: fix trivial typos in comments 2020-04-02 01:21:36 +09:00
CallGraphSort.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Config.h [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
DWARF.cpp [ELF] --gdb-index: support .debug_loclists 2020-04-29 15:04:13 -07:00
DWARF.h [ELF] --gdb-index: support .debug_loclists 2020-04-29 15:04:13 -07:00
Driver.cpp [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
Driver.h [Coding style change] Rename variables so that they start with a lowercase letter 2019-07-10 05:00:37 +00:00
DriverUtils.cpp Remove unused Endian.h includes, NFC 2020-03-11 15:45:34 -07:00
EhFrame.cpp [ELF] Wrap things in `namespace lld { namespace elf {`, NFC 2019-10-07 08:31:18 +00:00
EhFrame.h [Coding style change] Rename variables so that they start with a lowercase letter 2019-07-10 05:00:37 +00:00
ICF.cpp [lld][COFF][ELF][WebAssembly] Replace --[no-]threads /threads[:no] with --threads={1,2,...} /threads:{1,2,...} 2020-03-31 08:46:12 -07:00
ICF.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
InputFiles.cpp [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
InputFiles.h [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
InputSection.cpp [ELF][PPC64] Suppress toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen 2020-04-30 09:16:51 -07:00
InputSection.h [ELF][PPC64] Suppress toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen 2020-04-30 09:16:51 -07:00
LTO.cpp [lld] Support --lto-emit-asm and --plugin-opt=emit-asm 2020-04-27 11:00:46 -07:00
LTO.h [Coding style change] Rename variables so that they start with a lowercase letter 2019-07-10 05:00:37 +00:00
LinkerScript.cpp [ELF] Propagate LMA offset to sections with neither AT() nor AT> 2020-04-01 08:19:06 -07:00
LinkerScript.h [ELF] -M/-Map: fix VMA/LMA/Size columns of symbol assignments when address/size>=2**32 2020-04-07 10:15:15 -07:00
MapFile.cpp [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
MapFile.h [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
MarkLive.cpp [LLD][ELF] Add time-trace to ELF LLD 2020-02-06 12:14:13 +00:00
MarkLive.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Options.td [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
OutputSections.cpp LLD Support for Basic Block Sections 2020-04-07 06:55:57 -07:00
OutputSections.h [ELF] Refactor uses of getInputSections to improve efficiency NFC 2020-01-21 12:27:52 +00:00
README.md
Relocations.cpp [ELF][PPC64] Suppress toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen 2020-04-30 09:16:51 -07:00
Relocations.h LLD Support for Basic Block Sections 2020-04-07 06:55:57 -07:00
ScriptLexer.cpp [lld] NFC: fix trivial typos in comments 2020-04-02 01:21:36 +09:00
ScriptLexer.h [ELF] For relative paths in INPUT() and GROUP(), search the directory of the current linker script before searching other paths 2020-04-22 12:34:20 -07:00
ScriptParser.cpp [ELF] For relative paths in INPUT() and GROUP(), search the directory of the current linker script before searching other paths 2020-04-22 12:34:20 -07:00
ScriptParser.h [ELF] Fix variable names in comments after VariableName -> variableName change 2019-07-16 05:50:45 +00:00
SymbolTable.cpp [ELF] Make --version-script/--dynamic-list work for lazy symbols fetched by LTO libcalls 2020-04-06 09:47:06 -07:00
SymbolTable.h [ELF] Replace SymbolTable::forEachSymbol with iterator_range symbols() 2019-11-26 09:09:32 -08:00
Symbols.cpp [ELF] Add --warn-backrefs-exclude=<glob> 2020-04-20 07:52:15 -07:00
Symbols.h [LLD][ELF] Implement --discard-* for cases when -r or --emit-relocs are used. 2020-04-25 18:59:41 +07:00
SyntheticSections.cpp [LLD][ELF][ARM] recommit Fix ARM Exidx order for non monotonic section order 2020-04-24 13:47:28 +01:00
SyntheticSections.h [LLD][ELF][ARM] recommit Fix ARM Exidx order for non monotonic section order 2020-04-24 13:47:28 +01:00
Target.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
Target.h LLD Support for Basic Block Sections 2020-04-07 06:55:57 -07:00
Thunks.cpp [ELF][PPC64] Enable R_PPC64_REL14 trunks 2020-04-04 10:59:17 -07:00
Thunks.h [ELF][PPC32] Implement IPLT code sequence for non-preemptible IFUNC 2019-12-29 22:42:53 -08:00
Writer.cpp [ELF][PPC64] Suppress toc-indirect to toc-relative relaxation if R_PPC64_TOC16_LO is seen 2020-04-30 09:16:51 -07:00
Writer.h Revert "Revert r370635, it caused PR43241." 2019-09-06 15:57:24 +00:00

README.md

See docs/NewLLD.rst