https://github.com/garybeihl updated https://github.com/llvm/llvm-project/pull/173499
>From 5993787f8b3b17ea7de204bdb7df981dad00fece Mon Sep 17 00:00:00 2001 From: Gary Beihl <[email protected]> Date: Sun, 28 Dec 2025 18:03:36 -0500 Subject: [PATCH 1/4] [lldb][NativePDB] Handle UEFI binaries without predetermined load addresses UEFI executables are relocatable PE/COFF images where GetFileAddress() returns LLDB_INVALID_ADDRESS, causing symbol load failure from PDB files. Use base address 0 when load address is invalid, allowing symbols to be loaded with their RVAs. The module's actual runtime load address must be provided using `target modules load --file <module> --slide <load_address>`. Tested with Rust UEFI binaries, successfully loading 5,405 symbols with full source and line information. Fixes: #91060 --- .../SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index 3bf113a07d28c..40d45153b730f 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -422,6 +422,16 @@ void SymbolFileNativePDB::InitializeObject() { ->GetObjectFile() ->GetBaseAddress() .GetFileAddress(); + + // For UEFI/PE binaries and other relocatable images lacking a predetermined + // load address, GetFileAddress() returns LLDB_INVALID_ADDRESS. Use base + // address 0 in this case to allow symbols to be loaded with RVA + // (Relative Virtual Address). To debug at runtime, the module's actual load + // address must be provided using 'target modules load --file <module> --slide <load_address>'. + if (m_obj_load_address == LLDB_INVALID_ADDRESS) { + m_obj_load_address = 0x0; + } + m_index->SetLoadAddress(m_obj_load_address); m_index->ParseSectionContribs(); >From 863610ea4abb9fa6af31c3ee38735c3b0fed2faf Mon Sep 17 00:00:00 2001 From: Gary Beihl <[email protected]> Date: Fri, 30 Jan 2026 11:14:13 -0500 Subject: [PATCH 2/4] Fix coding style: remove braces for single-statement if body --- .../Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index 6d5645d589d0c..9f9ddff600876 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -428,9 +428,8 @@ void SymbolFileNativePDB::InitializeObject() { // address 0 in this case to allow symbols to be loaded with RVA // (Relative Virtual Address). To debug at runtime, the module's actual load // address must be provided using 'target modules load --file <module> --slide <load_address>'. - if (m_obj_load_address == LLDB_INVALID_ADDRESS) { + if (m_obj_load_address == LLDB_INVALID_ADDRESS) m_obj_load_address = 0x0; - } m_index->SetLoadAddress(m_obj_load_address); m_index->ParseSectionContribs(); >From 7411916e90526b080785692e0d103bf5f09e53b4 Mon Sep 17 00:00:00 2001 From: Gary Beihl <[email protected]> Date: Fri, 30 Jan 2026 13:26:32 -0500 Subject: [PATCH 3/4] Add test case for relocatable PE/COFF binaries with PDB symbols Test that DLLs and other relocatable binaries can load PDB symbols correctly when GetFileAddress() returns LLDB_INVALID_ADDRESS. --- .../Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp | 6 ++++++ .../SymbolFile/NativePDB/relocatable-binary.test | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test diff --git a/lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp b/lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp new file mode 100644 index 0000000000000..98790dd7ece59 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp @@ -0,0 +1,6 @@ +// Test input for relocatable PE/COFF binary with PDB symbols. +// This simulates a DLL or other position-independent code. + +extern "C" __declspec(dllexport) int relocatable_function(int x) { + return x * 2; +} \ No newline at end of file diff --git a/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test b/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test new file mode 100644 index 0000000000000..5c74c247f9e73 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test @@ -0,0 +1,11 @@ +# REQUIRES: lld, target-windows +# RUN: %build --compiler=clang-cl --nodefaultlib -fuse-ld=lld -Wl,/dll -Wl,/noentry -o %t.dll %S/Inputs/relocatable.cpp +# RUN: lldb-test symbols %t.dll | FileCheck %s + +# Test that relocatable PE/COFF binaries (like DLLs and UEFI drivers) with PDB +# symbols can be loaded. These binaries return LLDB_INVALID_ADDRESS for +# GetFileAddress() and should use 0x0 as the base to allow RVA-based symbol +# loading. + +# CHECK: Module: {{.*}}.dll +# CHECK: Function{{{.*}}}, extern "C" name = "relocatable_function" \ No newline at end of file >From 684a9afd15be4a772d67fd87425f40f9d08822ff Mon Sep 17 00:00:00 2001 From: Gary Beihl <[email protected]> Date: Sun, 15 Feb 2026 10:00:53 -0500 Subject: [PATCH 4/4] [lldb][NativePDB] Update test for relocatable PE/COFF binaries Rewrite the test to use the x86_64-unknown-uefi target with explicit clang-cl and lld-link invocations, inline the test source, and fix the CHECK pattern to match lldb-test output. Addresses reviewer feedback on PR #173499. --- .../SymbolFile/NativePDB/Inputs/relocatable.cpp | 6 ------ .../SymbolFile/NativePDB/relocatable-binary.cpp | 17 +++++++++++++++++ .../NativePDB/relocatable-binary.test | 11 ----------- 3 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp create mode 100644 lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.cpp delete mode 100644 lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test diff --git a/lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp b/lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp deleted file mode 100644 index 98790dd7ece59..0000000000000 --- a/lldb/test/Shell/SymbolFile/NativePDB/Inputs/relocatable.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// Test input for relocatable PE/COFF binary with PDB symbols. -// This simulates a DLL or other position-independent code. - -extern "C" __declspec(dllexport) int relocatable_function(int x) { - return x * 2; -} \ No newline at end of file diff --git a/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.cpp b/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.cpp new file mode 100644 index 0000000000000..922a84f8ed147 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.cpp @@ -0,0 +1,17 @@ +// clang-format off +// REQUIRES: lld, x86 + +// Test that relocatable PE/COFF binaries (like UEFI drivers) with PDB symbols +// can be loaded. These binaries return LLDB_INVALID_ADDRESS for +// GetFileAddress() and should use 0x0 as the base to allow RVA-based symbol +// loading. + +// RUN: %clang_cl --target=x86_64-unknown-uefi -Z7 -c /Fo%t.obj -- %s +// RUN: lld-link -debug:full -nodefaultlib -entry:EfiMain -subsystem:efi_application %t.obj -out:%t.efi -pdb:%t.pdb +// RUN: lldb-test symbols %t.efi | FileCheck %s + +// CHECK: Function{{{.*}}}, mangled = ?EfiMain@@YAHXZ + +int EfiMain() { + return 0; +} diff --git a/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test b/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test deleted file mode 100644 index 5c74c247f9e73..0000000000000 --- a/lldb/test/Shell/SymbolFile/NativePDB/relocatable-binary.test +++ /dev/null @@ -1,11 +0,0 @@ -# REQUIRES: lld, target-windows -# RUN: %build --compiler=clang-cl --nodefaultlib -fuse-ld=lld -Wl,/dll -Wl,/noentry -o %t.dll %S/Inputs/relocatable.cpp -# RUN: lldb-test symbols %t.dll | FileCheck %s - -# Test that relocatable PE/COFF binaries (like DLLs and UEFI drivers) with PDB -# symbols can be loaded. These binaries return LLDB_INVALID_ADDRESS for -# GetFileAddress() and should use 0x0 as the base to allow RVA-based symbol -# loading. - -# CHECK: Module: {{.*}}.dll -# CHECK: Function{{{.*}}}, extern "C" name = "relocatable_function" \ No newline at end of file _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
