llvm-project/llvm/lib/MC
Ben Langmuir a2639dcbe6 [ORC] Add a utility for adding missing "self" relocations to a Symbol
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

Differential revision: https://reviews.llvm.org/D113038
2021-11-04 15:01:05 -07:00
..
MCDisassembler Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
MCParser [llvm] Use StringRef::contains (NFC) 2021-10-23 08:45:27 -07:00
CMakeLists.txt Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
ConstantPools.cpp [MC] Add MCSubtargetInfo to MCAlignFragment 2021-09-07 15:46:19 +01:00
ELFObjectWriter.cpp [MC] Set SHF_INFO_LINK on SHT_REL/SHT_RELA sections 2021-09-02 01:00:51 -07:00
MCAsmBackend.cpp RISCV: adjust handling of relocation emission for RISCV 2021-06-17 08:20:02 -07:00
MCAsmInfo.cpp [AIX] Use AsmParser to do inline asm parsing 2021-07-02 16:12:21 +00:00
MCAsmInfoCOFF.cpp
MCAsmInfoDarwin.cpp
MCAsmInfoELF.cpp
MCAsmInfoGOFF.cpp [SystemZ][z/OS] Introduce the GOFFMCAsmInfo Interface for z/OS 2021-09-24 16:25:41 -04:00
MCAsmInfoWasm.cpp
MCAsmInfoXCOFF.cpp [AIX] Emit version string in .file directive 2021-07-12 17:03:52 +00:00
MCAsmMacro.cpp
MCAsmStreamer.cpp Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
MCAssembler.cpp [MC] Use local MCSubtargetInfo in writeNops 2021-09-07 15:46:19 +01:00
MCCodeEmitter.cpp
MCCodeView.cpp
MCContext.cpp [SystemZ][z/OS] Initial code to generate assembly files on z/OS 2021-07-27 11:29:15 -04:00
MCDwarf.cpp [MC] Make MCDwarfLineStr class public 2021-09-30 12:31:59 -07:00
MCELFObjectTargetWriter.cpp
MCELFStreamer.cpp Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
MCExpr.cpp [WebAssembly] Allow import and export of TLS symbols between DSOs 2021-09-14 06:47:37 -07:00
MCFragment.cpp [MC] Recursively calculate symbol offset 2021-10-20 14:29:43 -04:00
MCInst.cpp [MC] Add the ability to pass MCRegisterInfo to dump_pretty. 2021-05-14 18:21:57 -07:00
MCInstPrinter.cpp
MCInstrAnalysis.cpp [ORC] Add a utility for adding missing "self" relocations to a Symbol 2021-11-04 15:01:05 -07:00
MCInstrDesc.cpp
MCInstrInfo.cpp
MCLabel.cpp
MCLinkerOptimizationHint.cpp
MCMachOStreamer.cpp Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
MCMachObjectTargetWriter.cpp
MCNullStreamer.cpp
MCObjectFileInfo.cpp [MC][RISCV] Add RISCV MCObjectFileInfo 2021-08-27 18:23:29 +01:00
MCObjectStreamer.cpp [MC] Use local MCSubtargetInfo in writeNops 2021-09-07 15:46:19 +01:00
MCObjectWriter.cpp
MCPseudoProbe.cpp [MCPseudoProbe] Clean up includes (NFC) 2021-10-09 10:31:15 +02:00
MCRegisterInfo.cpp
MCSchedule.cpp
MCSection.cpp
MCSectionCOFF.cpp
MCSectionELF.cpp
MCSectionMachO.cpp
MCSectionWasm.cpp [WebAssembly] Add TLS data segment flag: WASM_SEG_FLAG_TLS 2021-05-12 13:31:02 -07:00
MCSectionXCOFF.cpp [XCOFF] support DWARF for 32-bit XCOFF for object output 2021-10-08 02:35:11 +00:00
MCStreamer.cpp [MC] Use local MCSubtargetInfo in writeNops 2021-09-07 15:46:19 +01:00
MCSubtargetInfo.cpp AMDGPU: Add target id and code object v4 support 2021-03-24 11:54:05 -04:00
MCSymbol.cpp
MCSymbolELF.cpp
MCSymbolXCOFF.cpp
MCTargetOptions.cpp [WebAssembly] Added initial type checker to MC Assembler 2021-07-09 14:07:25 -07:00
MCTargetOptionsCommandFlags.cpp [WebAssembly] Added initial type checker to MC Assembler 2021-07-09 14:07:25 -07:00
MCValue.cpp
MCWasmObjectTargetWriter.cpp
MCWasmStreamer.cpp Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
MCWin64EH.cpp [Win64EH] Write .pdata symbol relocations relative to the temporary begin symbol 2021-09-14 11:05:37 +03:00
MCWinCOFFStreamer.cpp [MC] Add MCSubtargetInfo to MCAlignFragment 2021-09-07 15:46:19 +01:00
MCWinEH.cpp
MCXCOFFObjectTargetWriter.cpp
MCXCOFFStreamer.cpp Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
MachObjectWriter.cpp
StringTableBuilder.cpp [ADT] Move DenseMapInfo for ArrayRef/StringRef into respective headers (NFC) 2021-06-03 18:34:36 +02:00
SubtargetFeature.cpp
TargetRegistry.cpp Move TargetRegistry.(h|cpp) from Support to MC 2021-10-08 14:51:48 -07:00
WasmObjectWriter.cpp [WebAssembly] Emit clangast in custom section aligned by 4 bytes 2021-10-19 15:50:08 -07:00
WinCOFFObjectWriter.cpp [COFF] Fix ARM and ARM64 REL32 relocations to be relative to the end of the relocation 2021-05-12 09:53:43 +03:00
XCOFFObjectWriter.cpp [XCOFF] support DWARF for 32-bit XCOFF for object output 2021-10-08 02:35:11 +00:00