Lang Hames 906b48616c
[ORC] Add utilities for limited symbolication of JIT backtraces (#175099)
This patch adds tools for capturing symbol information from JIT'd code
and using it to symbolicate backtraces. This is useful for debugging
crashes in JIT-compiled code where traditional symbolication tools may
not have access to the JIT symbol table. These tools are not a general
solution to the JIT symbolication problem (that will require further
integration with system components like libunwind, the dynamic linker,
and/or crash tracing tools), but will aid in JIT debugging and
development until a general solution is available.

APIs Added:

1. SymbolTableDumpPlugin - A LinkGraphLinkingLayer::Plugin that captures
symbol information as code is JIT'd and writes it to a file.

- Create(StringRef Path) ->
Expected<std::shared_ptr<SymbolTableDumpPlugin>> Creates a plugin that
appends symbol information to the specified file.

- Symbol table format: "<link graph name>" <address> <symbol name>
<address> <symbol name> ...

The plugin uses a PostAllocationPass to write symbols after addresses
have
   been assigned but before the code is finalized.

2. DumpedSymbolTable - A class for symbolicating backtraces using a
previously dumped symbol table.

- Create(StringRef Path) -> Expected<DumpedSymbolTable> Loads and parses
a symbol table from a file.

- symbolicate(StringRef Backtrace) -> std::string Given text of a
backtrace, for rows ending with a hex address, adds the symbol name,
offset, and defining graph name.

New `llvm-jitlink` Command Line Options:

1. -write-symtab=<path> Enables the SymbolTableDumpPlugin to write
symbol information to the specified file as objects are JIT'd. The
symbol table can then be used to symbolicate backtraces from crashes or
signal handlers.

2. -symbolicate-with=<path> Runs llvm-jitlink in symbolication mode.
Reads the symbol table from <path> and symbolicates backtraces read from
stdin or input files.

Usage Examples:

$ llvm-jitlink -write-symtab=symbols.txt mycode.o

$ llvm-jitlink -symbolicate-with=symbols.txt - < backtrace.txt
2026-01-09 15:42:00 +11:00
..