[llvm] [llvm-jitlink] Make the -show-addrs option work without -check. (PR #175491)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 11 23:05:42 PST 2026
https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/175491
>From 492358dc52a4e078a345bbb9d00bc43e4bf2e07a Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Mon, 12 Jan 2026 17:07:51 +1100
Subject: [PATCH] [llvm-jitlink] Make the -show-addrs option work without
-check.
Ensures that the address scraping passes are added to the JIT linker pipeline
if either of the -check or -show-addrs are passed. Prior to this commit we only
considered -check, so passing -show-addrs on its own was printing an empty
(unpopulated) symbol table.
This change exposed a bug in the ELF address scraping code that is fixed in
this commit: All symbols in the table must be flagged as "content" or
"zero-fill" symbols, but the ELF scraper includes absolute symbols that are
neither zero-fill (in the normal sense) and do not have content associated with
them in the graph. This commit treats them as zero-fill (since there is no
content), which seems like the right approach for the test tooling. (We can
refine the scraping code in the future to distinguish absolute symbols as a
third category if necessary)
---
.../Generic/llvm-jitlink-option-show-addrs.test | 14 ++++++++++++++
llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp | 6 +++++-
llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 2 +-
3 files changed, 20 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/ExecutionEngine/JITLink/Generic/llvm-jitlink-option-show-addrs.test
diff --git a/llvm/test/ExecutionEngine/JITLink/Generic/llvm-jitlink-option-show-addrs.test b/llvm/test/ExecutionEngine/JITLink/Generic/llvm-jitlink-option-show-addrs.test
new file mode 100644
index 0000000000000..96635f57a09f9
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/Generic/llvm-jitlink-option-show-addrs.test
@@ -0,0 +1,14 @@
+# RUN: llc -filetype=obj -o %t.o %S/Inputs/main-ret-0.ll
+# RUN: llvm-jitlink -noexec -show-addrs %t.o | FileCheck %s
+#
+# Check that the llvm-jitlink -show-addrs option reports an address for main.
+
+# Jitlink does not support ARM64 COFF files.
+# UNSUPPORTED: target=aarch64-{{.*}}-windows-{{.*}}
+
+# On MinGW targets, when compiling the main() function, it gets
+# an implicitly generated call to __main(), which is missing in
+# this context.
+# XFAIL: target={{.*}}-windows-gnu
+
+# CHECK: main{{.*}} target addr = 0x{{[[:xdigit:]]+}}, content:
\ No newline at end of file
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp
index 8bd17ebb6317a..84a3aa1f627dd 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp
@@ -176,9 +176,13 @@ Error registerELFGraphInfo(Session &S, LinkGraph &G) {
}
// Add symbol info for absolute symbols.
- for (auto *Sym : G.absolute_symbols())
+ for (auto *Sym : G.absolute_symbols()) {
S.SymbolInfos[Sym->getName()] = {Sym->getSize(),
Sym->getAddress().getValue()};
+ // Treat absolute symbols as zero-fill, since we don't define their
+ // content.
+ SectionContainsZeroFill = false;
+ }
auto SecAddr = FirstSym->getAddress();
auto SecSize =
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 7732992f77cb3..3d3b030a0073f 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -1396,7 +1396,7 @@ void Session::modifyPassConfig(LinkGraph &G, PassConfiguration &PassConfig) {
if (ShowLinkedFiles)
outs() << "Linking " << G.getName() << "\n";
- if (!CheckFiles.empty())
+ if (!CheckFiles.empty() || ShowAddrs)
PassConfig.PostFixupPasses.push_back([this](LinkGraph &G) {
if (ES.getTargetTriple().getObjectFormat() == Triple::ELF)
return registerELFGraphInfo(*this, G);
More information about the llvm-commits
mailing list