[llvm-branch-commits] [lldb] Support Re-export Symbol for FunctionCall (PR #208998)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jul 12 01:57:10 PDT 2026
https://github.com/aokblast created https://github.com/llvm/llvm-project/pull/208998
A symbol can be a stub that is re-exported to another library. For example, ELF can specify an auxiliary library and emit a zero-sized symbol in the symbol table. This can cause expression evaluation to resolve the stub instead of the actual function. Fix this by resolving re-exported symbols to their actual addressed.
>From 0b85e1e9f569820064e6cbf999a9853e7bdb3f8b Mon Sep 17 00:00:00 2001
From: ShengYi Hung <aokblast at FreeBSD.org>
Date: Sat, 11 Jul 2026 19:11:57 +0800
Subject: [PATCH] Support Re-export Symbol for FunctionCall
A symbol can be a stub that is re-exported to another library. For
example, ELF can specify an auxiliary library and emit a zero-sized
symbol in the symbol table. This can cause expression evaluation to
resolve the stub instead of the actual function. Fix this by resolving
re-exported symbols to their actual addressed.
---
.../Process/Utility/InferiorCallPOSIX.cpp | 34 +++++++++++++++----
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
index 5226b9bbe7c78..f190b589ad704 100644
--- a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -33,6 +33,30 @@
using namespace lldb;
using namespace lldb_private;
+/// Pick a call target from \p sc_list. Re-exported symbols have no code of
+/// their own and are resolved through the library that actually defines
+/// them, mirroring what the dynamic linker does.
+static Address GetCallableAddress(Target &target,
+ const SymbolContextList &sc_list) {
+ const uint32_t count = sc_list.GetSize();
+ for (uint32_t i = 0; i < count; ++i) {
+ SymbolContext sc;
+ if (!sc_list.GetContextAtIndex(i, sc))
+ continue;
+ if (sc.symbol && sc.symbol->GetType() == eSymbolTypeReExported) {
+ // Pass the containing module so all of its re-exported libraries
+ // (e.g. an ELF filter library's filtees) are searched in order.
+ if (Symbol *actual =
+ sc.symbol->ResolveReExportedSymbol(target, sc.module_sp))
+ return actual->GetAddress();
+ // Unresolvable re-export: not callable.
+ continue;
+ }
+ return sc.GetFunctionOrSymbolAddress();
+ }
+ return Address();
+}
+
bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
addr_t addr, addr_t length, unsigned prot,
unsigned flags, addr_t fd, addr_t offset) {
@@ -50,8 +74,7 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
ConstString("mmap"), eFunctionNameTypeFull, function_options, sc_list);
const uint32_t count = sc_list.GetSize();
if (count > 0) {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(0, sc)) {
+ {
EvaluateExpressionOptions options;
options.SetStopOthers(true);
options.SetUnwindOnError(true);
@@ -74,7 +97,7 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
prot_arg |= PROT_WRITE;
}
- Address mmap_addr = sc.GetFunctionOrSymbolAddress();
+ Address mmap_addr = GetCallableAddress(process->GetTarget(), sc_list);
if (mmap_addr.IsValid()) {
auto type_system_or_err =
process->GetTarget().GetScratchTypeSystemForLanguage(
@@ -142,8 +165,7 @@ bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
ConstString("munmap"), eFunctionNameTypeFull, function_options, sc_list);
const uint32_t count = sc_list.GetSize();
if (count > 0) {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(0, sc)) {
+ {
EvaluateExpressionOptions options;
options.SetStopOthers(true);
options.SetUnwindOnError(true);
@@ -153,7 +175,7 @@ bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
options.SetTimeout(process->GetUtilityExpressionTimeout());
options.SetTrapExceptions(false);
- Address munmap_addr = sc.GetFunctionOrSymbolAddress();
+ Address munmap_addr = GetCallableAddress(process->GetTarget(), sc_list);
if (munmap_addr.IsValid()) {
lldb::addr_t args[] = {addr, length};
lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallFunction(
More information about the llvm-branch-commits
mailing list