testsuite: ada-valprint-error relocation issue

Message ID 20260401103340.4011522-1-bfilipov@amd.com
State New
Headers
Series testsuite: ada-valprint-error relocation issue |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Test failed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Test failed

Commit Message

Bratislav Filipovic April 1, 2026, 10:33 a.m. UTC
  The ada-valprint-error.exp test links a nodebug .o file with a separate
DWARF .o file generated by lib/dwarf.exp. This requires the linker to
apply relocations for initialized pointers in the .data section.

Some clang + linker combinations fail to apply these relocations,
leaving fd__global as NULL instead of pointing to buffer. This causes
the test to print null instead of the expected error message.

Binary evidence from .comment section confirms which compiler and
linker were used. Testing shows:
- GCC 13 + GNU ld 2.42: PASS
- clang 20 + GNU ld 2.42: FAIL
- clang 22 + ld.lld 22: FAIL
- clang 17/19 + GNU ld 2.45.0: PASS

The failure is a linker limitation when handling this specific
relocation pattern, not a GDB bug. Document this in the test file
to help users understand why the test may fail with certain toolchains.
---
Thanks for review Tom. I changed it per your suggestions. It seems to 
fail only for some combinations of clang + linker.

 gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
  

Comments

Tom de Vries April 1, 2026, 11:12 a.m. UTC | #1
On 4/1/26 12:33 PM, Bratislav Filipovic wrote:
> The ada-valprint-error.exp test links a nodebug .o file with a separate
> DWARF .o file generated by lib/dwarf.exp. This requires the linker to
> apply relocations for initialized pointers in the .data section.
> 
> Some clang + linker combinations fail to apply these relocations,
> leaving fd__global as NULL instead of pointing to buffer. This causes
> the test to print null instead of the expected error message.
> 
> Binary evidence from .comment section confirms which compiler and
> linker were used. Testing shows:
> - GCC 13 + GNU ld 2.42: PASS
> - clang 20 + GNU ld 2.42: FAIL
> - clang 22 + ld.lld 22: FAIL
> - clang 17/19 + GNU ld 2.45.0: PASS
> 
> The failure is a linker limitation when handling this specific
> relocation pattern, not a GDB bug. Document this in the test file
> to help users understand why the test may fail with certain toolchains.
> ---
> Thanks for review Tom. I changed it per your suggestions. It seems to
> fail only for some combinations of clang + linker.
> 

Hi,

thanks for the update, I have a few comments.

First of all, the commit needs whitespace fixes, as mentioned by the 
pre-commit check:
...
$ pre-commit run --all-files check-whitespace
check-whitespace.........................................................Failed
- hook id: check-whitespace
- exit code: 2

gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp:119: indent with spaces.
+        unsupported "linker failed to apply relocation for fd__global"
gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp:120: indent with spaces.
+        return
gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp:123: indent with spaces.
+        pass $gdb_test_name

$
...

[ Consider installing pre-commit on your system (to be able to run it 
manually), and also installing pre-commit hooks in your git repo (to let 
git run it automatically). ]

>   gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
> 
> diff --git a/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp b/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
> index f3d61e91..b72682f7 100644
> --- a/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
> +++ b/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
> @@ -107,6 +107,23 @@ if { [prepare_for_testing ${testfile}.exp ${testfile} \
>       return -1
>   }
>   
> +# Note: This test may fail with certain clang + linker combinations
> +# Specifically, clang + ld.lld can fail to apply relocations when linking
> +# nodebug .o with separate DWARF .o, leaving fd__global as NULL instead
> +# of pointing to buffer. The failure is a linker limitation, not a GDB bug.
> +#
> +# Known to fail: clang 20/22 + GNU ld 2.42, clang 22 + ld.lld 22
> +# Known to pass: GCC + GNU ld, clang 17/19 + GNU ld 2.45.0
> +gdb_test_multiple "print /x fd__global" "check fd__global value" {
> +    -re -wrap "@0x0: 0x0" {
> +        unsupported "linker failed to apply relocation for fd__global"
> +        return
> +    }

FWIW, I usually try to keep non-local Tcl control flow (like return or 
break/continue not contained in a local loop) out of the regexp clauses. 
  I think this may have been necessary at some point, so I got in the 
habit of doing so.  I'm not sure if that's still necessary, but I still 
think it's a somewhat cleaner style.

The pattern I use instead is:
...
set unsupported 0
gdb_test_multiple ... {
     -re -wrap ... {
	set unsupported 1
     }
     ...
}
if {$unsupported} {
     unsupported "linker failed to apply relocation for fd__global"
     return
}
...

Anyway, it's not necessary to change this.

> +    -re -wrap "= $hex" {
> +        pass $gdb_test_name
> +    }
> +}
> +

I applied the patch, ran the test-case, and ran into:
...
(gdb) print /x fd__global^M
$1 = (fd__ints_doubled &) @0x404020: 0x404020 <buffer>^M
(gdb) FAIL: gdb.dwarf2/ada-valprint-error.exp: check fd__global value
...

The regexp doesn't match.

This can easily be fixed by simply using:
...
     -re -wrap "" {
         pass $gdb_test_name
     }
...

Thanks,
- Tom

>   gdb_test_no_output "set language ada"
>   
>   gdb_test "print fd.global" \
  

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp b/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
index f3d61e91..b72682f7 100644
--- a/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
+++ b/gdb/testsuite/gdb.dwarf2/ada-valprint-error.exp
@@ -107,6 +107,23 @@  if { [prepare_for_testing ${testfile}.exp ${testfile} \
     return -1
 }
 
+# Note: This test may fail with certain clang + linker combinations
+# Specifically, clang + ld.lld can fail to apply relocations when linking
+# nodebug .o with separate DWARF .o, leaving fd__global as NULL instead
+# of pointing to buffer. The failure is a linker limitation, not a GDB bug.
+#
+# Known to fail: clang 20/22 + GNU ld 2.42, clang 22 + ld.lld 22
+# Known to pass: GCC + GNU ld, clang 17/19 + GNU ld 2.45.0
+gdb_test_multiple "print /x fd__global" "check fd__global value" {
+    -re -wrap "@0x0: 0x0" {
+        unsupported "linker failed to apply relocation for fd__global"
+        return
+    }
+    -re -wrap "= $hex" {
+        pass $gdb_test_name
+    }
+}
+
 gdb_test_no_output "set language ada"
 
 gdb_test "print fd.global" \