[v2] binutils: testsuite: Fix addr2line test cases on Windows.

Message ID 20260920152329.6941-1-jdx@o2.pl
State New
Headers
Series [v2] binutils: testsuite: Fix addr2line test cases on Windows. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Dubiec Sept. 20, 2026, 3:22 p.m. UTC
  The following two test cases fail on Windows:
[...]
Running /d/Works/binutils/binutils/testsuite/binutils-all/addr2line.exp ...
FAIL: addr2line
FAIL: addr2line -f option
[...]

There are two problems:

1. All targets: On Windows, nm uses DOS/Windows-style paths (i.e. paths
beginning with a drive letter and a colon), whereas the test suite uses
UNIX-style paths. This causes the test cases to fail.

2. H8/300 and probably a few other targets (e.g. CIRS?): gcc prepends
an underscore to symbol names, so this needs to be taken into account.

This patch fixes both issues.

Signed-off-by: Jan Dubiec <jdx@o2.pl>
---
 binutils/testsuite/binutils-all/addr2line.exp | 28 +++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
  

Comments

Jan Beulich Sept. 25, 2026, 6:38 a.m. UTC | #1
On 20.09.2026 17:22, Jan Dubiec wrote:
> The following two test cases fail on Windows:
> [...]
> Running /d/Works/binutils/binutils/testsuite/binutils-all/addr2line.exp ...
> FAIL: addr2line
> FAIL: addr2line -f option
> [...]
> 
> There are two problems:
> 
> 1. All targets: On Windows, nm uses DOS/Windows-style paths (i.e. paths
> beginning with a drive letter and a colon), whereas the test suite uses
> UNIX-style paths. This causes the test cases to fail.
> 
> 2. H8/300 and probably a few other targets (e.g. CIRS?): gcc prepends
> an underscore to symbol names, so this needs to be taken into account.
> 
> This patch fixes both issues.
> 
> Signed-off-by: Jan Dubiec <jdx@o2.pl>

Okay.

Jan
  
Maciej W. Rozycki Oct. 14, 2026, 7:17 p.m. UTC | #2
On Sun, 20 Sep 2026, Jan Dubiec wrote:

> 2. H8/300 and probably a few other targets (e.g. CIRS?): gcc prepends

 s/CIRS/CRIS/ please.

  Maciej
  

Patch

diff --git a/binutils/testsuite/binutils-all/addr2line.exp b/binutils/testsuite/binutils-all/addr2line.exp
index 4f3533c7703..99548754f18 100644
--- a/binutils/testsuite/binutils-all/addr2line.exp
+++ b/binutils/testsuite/binutils-all/addr2line.exp
@@ -16,9 +16,19 @@ 
 
 set testname "addr2line"
 set opts ""
-set dot ""
+set pfx ""
 set exe [exeext]
 
+# If the host is Windows/MSYS, replace the leading /x with a DOS/Windows
+# drive letter, e.g change /x/y/foo/bar to X:/y/foo/bar.
+set tmp_srcdir $srcdir
+if { [ishost *-*-mingw*] } {
+    # Step 1: Replace the leading /x/ with x:/.
+    set tmp_srcdir [regsub {^/([a-zA-Z])/} $srcdir {\1:/}]
+    # Step 2: Change the leading x to X.
+    set tmp_srcdir [string toupper [string index $tmp_srcdir 0]][string range $tmp_srcdir 1 end]
+}
+
 # Which function is reported when two of them cover exactly the same range.
 # An inlined subroutine covering exactly the range of the subprogram that
 # contains it must be the one named, and the same one on every run.
@@ -36,7 +46,13 @@  if { [is_elf_format] } {
 # MUSL uses the ELFv2 ABI for PowerPC, so the problem does not apply there.
 if { [istarget powerpc64-*-*] && ![istarget powerpc64-*-musl] } {
     set opts --synthetic
-    set dot {\.}
+    set pfx {\.}
+}
+
+# Bare metal gcc for H8/300 prepends an underscore to symbol names.
+# Note that h8300-linux-gnu-gcc does not do this.
+if { [istarget h8300-*-elf] } {
+    set pfx {_}
 }
 
 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } {
@@ -48,12 +64,12 @@  if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug
 #testcase for default option.
 #Run nm command and input the main symbol address to addr2line.
 set output [binutils_run $NM "$opts tmpdir/testprog$exe"]
-if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${dot}main" $output contents] then {
+if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${pfx}main" $output contents] then {
     fail "$testname"
 } else {
     set list [regexp -inline -all -- {\S+} $contents]
     set got [binutils_run $ADDR2LINE "-e tmpdir/testprog$exe [lindex $list 0]"]
-    set want "$srcdir/$subdir/testprog.c:\[0-9\]+"
+    set want "$tmp_srcdir/$subdir/testprog.c:\[0-9\]+"
     if ![regexp $want $got] then {
 	fail "$testname $got\n"
     } else {
@@ -63,12 +79,12 @@  if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${dot}main" $output contents] then
 
 #testcase for -f option.
 #Run nm command and input the fn function symbol address to addr2line.
-if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${dot}fn" $output contents] then {
+if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${pfx}fn" $output contents] then {
     fail "$testname -f option"
 } else {
     set list [regexp -inline -all -- {\S+} $contents]
     set got [binutils_run $ADDR2LINE "-f -e tmpdir/testprog$exe [lindex $list 0]"]
-    set want "fn\n$srcdir/$subdir/testprog.c:\[0-9\]+"
+    set want "fn\n$tmp_srcdir/$subdir/testprog.c:\[0-9\]+"
     if ![regexp $want $got] then {
 	fail "$testname -f option $got\n"
     } else {