[PATCH] D113038: [ORC] Add a utility for adding missing "self" relocations to a Symbol

Ben Langmuir via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 2 11:30:27 PDT 2021


benlangmuir created this revision.
benlangmuir added a reviewer: lhames.
Herald added subscribers: pengfei, hiraditya, mgorny.
benlangmuir requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If a tool wants to introduce new indirections via stubs at link-time in
ORC, it can cause fidelity issues around the address of the function if
some references to the function do not have relocations. This is known
to happen inside the body of the function itself on x86_64 for example,
where a PC-relative address is formed, but without a relocation.

  _foo:
    leaq -7(%rip), %rax ## form pointer to '_foo' without relocation
  
  _bar:
    leaq (%rip), %rax ##  uses X86_64_RELOC_SIGNED to '_foo'

The consequence of introducing a stub for such a function at link time
is that if it forms a pointer to itself without relocation, it will not
have the same value as a pointer from outside the function. If the
function pointer is used as a key, this can cause problems.

This utility provides best-effort support for adding such missing
relocations using MCDisassembler and MCInstrAnalysis to identify the
problematic instructions. Currently it is only implemented for x86_64.

Note: the related issue with call/jump instructions is not handled
here, only forming function pointers.

rdar://83514317


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113038

Files:
  llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
  llvm/include/llvm/MC/MCInstrAnalysis.h
  llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
  llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
  llvm/lib/MC/MCInstrAnalysis.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
  llvm/test/ExecutionEngine/JITLink/X86/Inputs/x86-64_self_relocation.s
  llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation.test
  llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_self_relocation_exec.test
  llvm/tools/llvm-jitlink/llvm-jitlink.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113038.384176.patch
Type: text/x-patch
Size: 18267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/babf87e7/attachment.bin>


More information about the llvm-commits mailing list