diff mbox series

gcc: Fix gcc-libitm false positives in regression report

Message ID 20260305131622.1145822-1-Harish.Sadineni@windriver.com
State Under Review
Headers show
Series gcc: Fix gcc-libitm false positives in regression report | expand

Commit Message

Harish Sadineni March 5, 2026, 1:16 p.m. UTC
From: Harish Sadineni <Harish.Sadineni@windriver.com>

Some of the gcc-libitm test cases include build paths (e.g. [1]) in their results.
When comparing two build outputs, these embedded paths cause resulttool to incorrectly report regressions.

[1] ptestresult.gcc-libitm-user.libitm.c++/dropref.C -B /srv/pokybuild/yocto-worker/qemuarm64-tc/build/build-st-64312/
    ..../libitm/../libstdc++-v3/src/.libs (test for excess errors): PASS

This leads to a false regression such as:
PASS → No matching test result

Upstream-Status: Backport [https://gcc.gnu.org/cgit/gcc/patch/?id=b129ff0880c6d10e0379b46889d01255ee8d1f82,
                           https://gcc.gnu.org/cgit/gcc/patch/?id=66ce317036f2eb5aeb96d5e4b9e468799d7566b]

Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
---
 meta/recipes-devtools/gcc/gcc-15.2.inc        |   2 +
 ...028-fix-gcc-libitm-false-postives-01.patch | 187 +++++++++++++++
 ...028-fix-gcc-libitm-false-postives-02.patch | 220 ++++++++++++++++++
 3 files changed, 409 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-01.patch
 create mode 100644 meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-02.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/gcc/gcc-15.2.inc b/meta/recipes-devtools/gcc/gcc-15.2.inc
index b02cc4fcb9..1508031424 100644
--- a/meta/recipes-devtools/gcc/gcc-15.2.inc
+++ b/meta/recipes-devtools/gcc/gcc-15.2.inc
@@ -74,6 +74,8 @@  SRC_URI = "${BASEURI} \
            file://0025-gcc-testsuite-tweaks-for-mips-OE.patch \
            file://0026-fix-pr90579-testcases.patch \
            file://0027-gcc15-pr122394.patch \
+	   file://0028-fix-gcc-libitm-false-postives-01.patch \
+	   file://0028-fix-gcc-libitm-false-postives-02.patch \
            file://0001-mapper-localhost-might-not-be-known.patch \
 "
 
diff --git a/meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-01.patch b/meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-01.patch
new file mode 100644
index 0000000000..d8ed99adb5
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-01.patch
@@ -0,0 +1,187 @@ 
+From b129ff0880c6d10e0379b46889d01255ee8d1f82 Mon Sep 17 00:00:00 2001
+From: Pietro Monteiro <pietro@sociotechnical.xyz>
+Date: Fri, 30 Jan 2026 20:22:49 -0500
+Subject: libitm: testsuite: don't include libstdc++ paths in test names
+ [PR69018]
+
+Libitm C++ tests pass -B/full/path/to/build/libstc++/src/.libs on the
+options argument to dg-runtest and the libstdc++ include paths as
+the default-extra-options.  This causes 2 problems:
+
+1) If a test uses `dg-options' then the libstdc++ include paths are
+not passed to the compiler.
+
+2) The `-B/full/path/to/build/libstc++/src/.libs' gets added to the
+test name.  This makes comparing build done in different directories
+harder because the hardcoded full path.
+
+Stop passing options and default-extra-options to dg-runtest and move
+dealing with the path-releated flags to libitm_target_compile in
+libitm.exp, where they are added to additional_flags.
+
+Also change the FSF address to the website in the license text.
+
+libitm/ChangeLog:
+	PR libitm/69018
+	* testsuite/lib/libitm.exp (libitm_target_compile): Add
+	lang_include_flags and `-B${blddir}/${lang_library_paths}' to
+	additional_flags.
+	* testsuite/libitm.c++/c++.exp: Set lang_library_paths and lang_include_flags.
+
+Upstream-Status: Backport [https://gcc.gnu.org/cgit/gcc/patch/?id=b129ff0880c6d10e0379b46889d01255ee8d1f82]
+
+Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
+Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
+---
+ libitm/testsuite/lib/libitm.exp     | 25 ++++++++++----
+ libitm/testsuite/libitm.c++/c++.exp | 67 +++++++++++++++++--------------------
+ 2 files changed, 48 insertions(+), 44 deletions(-)
+
+diff --git a/libitm/testsuite/lib/libitm.exp b/libitm/testsuite/lib/libitm.exp
+index 0b3301537cee..69a49906d338 100644
+--- a/libitm/testsuite/lib/libitm.exp
++++ b/libitm/testsuite/lib/libitm.exp
+@@ -9,8 +9,7 @@
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+-# along with this program; if not, write to the Free Software
+-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
++# along with this program; if not, see <http://www.gnu.org/licenses/>.
+ 
+ # Damn dejagnu for not having proper library search paths for load_lib.
+ # We have to explicitly load everything that gcc-dg.exp wants to load.
+@@ -193,14 +192,24 @@ proc libitm_target_compile { source dest type options } {
+     global gluefile wrap_flags
+     global ALWAYS_CFLAGS
+     global GCC_UNDER_TEST
+-    global lang_test_file
+-    global lang_library_path
++    global lang_library_paths
+     global lang_link_flags
++    global lang_include_flags
+ 
+-    if { [info exists lang_test_file] } {
+-	if { $blddir != "" } {
++    if { [info exists lang_include_flags] } {
++	lappend options "additional_flags=${lang_include_flags}"
++    }
++
++    if { [info exists lang_library_paths] } {
++	foreach lang_library_path $lang_library_paths {
++	    # targets that use lib[...].a%s in their specs need a -B option
++	    # for uninstalled testing.
++	    lappend options "additional_flags=-B${blddir}/${lang_library_path}"
+ 	    lappend options "ldflags=-L${blddir}/${lang_library_path}"
+ 	}
++    }
++
++    if { [info exists lang_link_flags] } {
+ 	lappend options "ldflags=${lang_link_flags}"
+     }
+ 
+@@ -219,7 +228,9 @@ proc libitm_target_compile { source dest type options } {
+ 	set options [concat "$ALWAYS_CFLAGS" $options]
+     }
+ 
+-    set options [dg-additional-files-options $options $source $dest $type]
++    if { $source != "" } {
++        set options [dg-additional-files-options $options $source $dest $type]
++    }
+ 
+     set result [target_compile $source $dest $type $options]
+ 
+diff --git a/libitm/testsuite/libitm.c++/c++.exp b/libitm/testsuite/libitm.c++/c++.exp
+index a1ce7ce4062e..90f3058e7249 100644
+--- a/libitm/testsuite/libitm.c++/c++.exp
++++ b/libitm/testsuite/libitm.c++/c++.exp
+@@ -11,8 +11,7 @@
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+-# along with this program; if not, write to the Free Software
+-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
++# along with this program; if not, see <http://www.gnu.org/licenses/>.
+ 
+ load_lib libitm-dg.exp
+ load_gcc_lib gcc-dg.exp
+@@ -33,48 +32,42 @@ set blddir [lookfor_file [get_multilibs] libitm]
+ 
+ 
+ if { $blddir != "" } {
+-    # Look for a static libstdc++ first.
+-    if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] {
+-	set lang_test_file "${lang_library_path}/libstdc++.a"
+-	set lang_test_file_found 1
+-	# We may have a shared only build, so look for a shared libstdc++.
+-    } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] {
+-	set lang_test_file "${lang_library_path}/libstdc++.${shlib_ext}"
+-	set lang_test_file_found 1
+-    } else {
+-	puts "No libstdc++ library found, will not execute c++ tests"
++    if { ![file exists "${blddir}/${lang_library_path}/libstdc++.a"]
++	 && ![file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] } {
++	verbose -log "No libstdc++ library found, will not execute c++ tests"
++	unset lang_library_path
++	return
+     }
+-} elseif { [info exists GXX_UNDER_TEST] } {
+-    set lang_test_file_found 1
+-    # Needs to exist for libitm.exp.
+-    set lang_test_file ""
++    lappend lang_library_paths ${lang_library_path}
++} elseif { ![info exists GXX_UNDER_TEST] } {
++    verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
++    return
++}
++
++# Gather a list of all tests.
++set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]]
++
++if { $blddir != "" } {
++    set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
+ } else {
+-    puts "GXX_UNDER_TEST not defined, will not execute c++ tests"
++    set ld_library_path "$always_ld_library_path"
+ }
+ 
+-if { $lang_test_file_found } {
+-    # Gather a list of all tests.
+-    set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]]
++append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
++set_ld_library_path_env_vars
+ 
+-    set stdcxxadder ""
+-    if { $blddir != "" } {
+-	set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
+-	set stdcxxadder "-B ${blddir}/${lang_library_path}"
+-    } else {
+-	set ld_library_path "$always_ld_library_path"
+-    }
+-    append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
+-    set_ld_library_path_env_vars
++set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
++if { [file exists $flags_file] } {
++    set lang_include_flags [exec sh $flags_file --build-includes]
++}
+ 
+-    set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
+-    if { [file exists $flags_file] } {
+-	set libstdcxx_includes [exec sh $flags_file --build-includes]
+-    } else {
+-	set libstdcxx_includes ""
+-    }
++# Main loop.
++dg-runtest $tests "" ""
+ 
+-    # Main loop.
+-    dg-runtest $tests $stdcxxadder $libstdcxx_includes
++if { $blddir != "" } {
++    unset lang_include_flags
++    unset lang_library_path
++    unset lang_library_paths
+ }
+ 
+ # All done.
+-- 
+cgit 
diff --git a/meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-02.patch b/meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-02.patch
new file mode 100644
index 0000000000..67ed47ff51
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/0028-fix-gcc-libitm-false-postives-02.patch
@@ -0,0 +1,220 @@ 
+From 66ce317036f2eb5aeb96d5e4b9e468799d7566b6 Mon Sep 17 00:00:00 2001
+From: Pietro Monteiro <pietro@sociotechnical.xyz>
+Date: Wed, 11 Feb 2026 11:55:13 -0500
+Subject: libitm: Fix recent libitm testsuite regression [PR69018]
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The commit r16-7202-gb129ff0880c6d1 broke running libitm’s testsuite
+using combinations of options because it didn’t clean up all the
+global variables set in c++.exp.  Fix the regression by using g++ for
+the C++ tests and cleaning up the variables shared between C and C++
+tests.
+
+libitm/ChangeLog:
+	PR libitm/69018
+	* testsuite/lib/libitm.exp (libitm_init): Check
+	GXX_UNDER_TEST.  Add "${blddir}/.libs" to
+	always_ld_library_path if blddir is not empty.  Use
+	"-fdiagnostics-plain-output".  Don't set compiler to GCC_UNDER_TEST.
+	* testsuite/libitm.c++/c++.exp: If $blddir is not empty set
+	libstdc++_library_path, shlib_ext, lang_include_flags, add
+	"${blddir}/${lang_library_paths}" to ld_library_path.
+	Unset libstdc++_library_path and shlib_ext if we skip C++
+	tests and at the end of the test run.
+	* testsuite/libitm.c/c.exp: Update the FSF address to the
+	website in the license text. Unset lang_library_paths and
+	lang_include_flags.  Set the compiler to $GCC_UNDER_TEST.
+
+Upstream-Status: Backport [https://gcc.gnu.org/cgit/gcc/patch/?id=66ce317036f2eb5aeb96d5e4b9e468799d7566b6]
+
+Co-authored-by: Jakub Jelinek  <jakub@redhat.com>
+Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
+Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
+---
+ libitm/testsuite/lib/libitm.exp     | 21 +++++++++++++++----
+ libitm/testsuite/libitm.c++/c++.exp | 42 ++++++++++++++-----------------------
+ libitm/testsuite/libitm.c/c.exp     | 14 ++++++-------
+ 3 files changed, 40 insertions(+), 37 deletions(-)
+
+diff --git a/libitm/testsuite/lib/libitm.exp b/libitm/testsuite/lib/libitm.exp
+index 69a49906d338..2de0f6cbf158 100644
+--- a/libitm/testsuite/lib/libitm.exp
++++ b/libitm/testsuite/lib/libitm.exp
+@@ -79,7 +79,7 @@ proc libitm_init { args } {
+     global ALWAYS_CFLAGS
+     global CFLAGS
+     global TOOL_EXECUTABLE TOOL_OPTIONS
+-    global GCC_UNDER_TEST
++    global GCC_UNDER_TEST GXX_UNDER_TEST
+     global TESTING_IN_BUILD_TREE
+     global target_triplet
+     global always_ld_library_path
+@@ -97,6 +97,17 @@ proc libitm_init { args } {
+ 	} else {
+ 	    set GCC_UNDER_TEST "[find_gcc]"
+ 	}
++	# Only if we're guessing 'GCC_UNDER_TEST', we're also going to guess
++	# 'GXX_UNDER_TEST'
++	if ![info exists GXX_UNDER_TEST] then {
++	    if [info exists TOOL_EXECUTABLE] {
++		set GXX_UNDER_TEST $TOOL_EXECUTABLE
++	    } else {
++		set GXX_UNDER_TEST "[find_g++]"
++	    }
++	} else {
++	    error "GXX_UNDER_TEST set but not GCC_UNDER_TEST"
++	}
+     }
+ 
+     if ![info exists tmpdir] {
+@@ -119,7 +130,7 @@ proc libitm_init { args } {
+     }
+ 
+     # Compute what needs to be put into LD_LIBRARY_PATH
+-    set always_ld_library_path ".:${blddir}/.libs"
++    set always_ld_library_path "."
+ 
+     # Compute what needs to be added to the existing LD_LIBRARY_PATH.
+     if {$gccdir != ""} {
+@@ -150,6 +161,8 @@ proc libitm_init { args } {
+ 	lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
+ 	lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
+ 	lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs"
++
++	append always_ld_library_path ":${blddir}/.libs"
+     }
+     lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
+ 
+@@ -179,7 +192,8 @@ proc libitm_init { args } {
+     # Turn on transactional memory support.
+     lappend ALWAYS_CFLAGS "additional_flags=-fgnu-tm"
+ 
+-    lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-color=never"
++    # Disable caret, color, URL diagnostics
++    lappend ALWAYS_CFLAGS "additional_flags=-fdiagnostics-plain-output"
+ }
+ 
+ #
+@@ -220,7 +234,6 @@ proc libitm_target_compile { source dest type options } {
+ 
+     lappend options "additional_flags=[libio_include_flags]"
+     lappend options "timeout=[timeout_value]"
+-    lappend options "compiler=$GCC_UNDER_TEST"
+ 
+     set options [concat $libitm_compile_options $options]
+ 
+diff --git a/libitm/testsuite/libitm.c++/c++.exp b/libitm/testsuite/libitm.c++/c++.exp
+index 90f3058e7249..c24dc830bcc5 100644
+--- a/libitm/testsuite/libitm.c++/c++.exp
++++ b/libitm/testsuite/libitm.c++/c++.exp
+@@ -16,39 +16,33 @@
+ load_lib libitm-dg.exp
+ load_gcc_lib gcc-dg.exp
+ 
+-global shlib_ext
+-
+-set shlib_ext [get_shlib_extension]
+-# The C++ tests should be linked with g++, which defaults to -shared-libgcc.
+-# Doing that is currently too intrusive, so hardcode here.
+-set lang_link_flags "-shared-libgcc -lstdc++"
+-set lang_test_file_found 0
+-set lang_library_path "../libstdc++-v3/src/.libs"
+-
+-# Initialize dg.
+-dg-init
+-
+-set blddir [lookfor_file [get_multilibs] libitm]
+-
+-
+ if { $blddir != "" } {
+-    if { ![file exists "${blddir}/${lang_library_path}/libstdc++.a"]
+-	 && ![file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] } {
++    set libstdc++_library_path "../libstdc++-v3/src/.libs"
++    set shlib_ext [get_shlib_extension]
++    if { ![file exists "${blddir}/${libstdc++_library_path}/libstdc++.a"]
++	 && ![file exists "${blddir}/${libstdc++_library_path}/libstdc++.${shlib_ext}"] } {
+ 	verbose -log "No libstdc++ library found, will not execute c++ tests"
+-	unset lang_library_path
++	unset libstdc++_library_path
++	unset shlib_ext
+ 	return
+     }
+-    lappend lang_library_paths ${lang_library_path}
++    lappend lang_library_paths ${libstdc++_library_path}
+ } elseif { ![info exists GXX_UNDER_TEST] } {
+     verbose -log "GXX_UNDER_TEST not defined, will not execute c++ tests"
+     return
+ }
+ 
++lappend ALWAYS_CFLAGS "compiler=$GXX_UNDER_TEST"
++
++# Initialize dg.
++dg-init
++
+ # Gather a list of all tests.
+ set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]]
+ 
+ if { $blddir != "" } {
+-    set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}"
++    set lang_include_flags [exec sh ${blddir}/../libstdc++-v3/scripts/testsuite_flags --build-includes]
++    set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_paths}"
+ } else {
+     set ld_library_path "$always_ld_library_path"
+ }
+@@ -56,18 +50,14 @@ if { $blddir != "" } {
+ append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
+ set_ld_library_path_env_vars
+ 
+-set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags"
+-if { [file exists $flags_file] } {
+-    set lang_include_flags [exec sh $flags_file --build-includes]
+-}
+-
+ # Main loop.
+ dg-runtest $tests "" ""
+ 
+ if { $blddir != "" } {
+     unset lang_include_flags
+-    unset lang_library_path
++    unset libstdc++_library_path
+     unset lang_library_paths
++    unset shlib_ext
+ }
+ 
+ # All done.
+diff --git a/libitm/testsuite/libitm.c/c.exp b/libitm/testsuite/libitm.c/c.exp
+index daa71427d64c..7a697b870932 100644
+--- a/libitm/testsuite/libitm.c/c.exp
++++ b/libitm/testsuite/libitm.c/c.exp
+@@ -9,20 +9,20 @@
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+-# along with this program; if not, write to the Free Software
+-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
++# along with this program; if not, see <http://www.gnu.org/licenses/>.
+ 
+-if [info exists lang_library_path] then {
+-    unset lang_library_path
+-    unset lang_link_flags
++if [info exists lang_library_paths] then {
++    unset lang_library_paths
+ }
+-if [info exists lang_test_file] then {
+-    unset lang_test_file
++if [info exists lang_include_flags] then {
++    unset lang_include_flags
+ }
+ 
+ load_lib libitm-dg.exp
+ load_gcc_lib gcc-dg.exp
+ 
++lappend ALWAYS_CFLAGS "compiler=$GCC_UNDER_TEST"
++
+ # If a testcase doesn't have special options, use these.
+ if ![info exists DEFAULT_CFLAGS] then {
+     set DEFAULT_CFLAGS "-O2"
+-- 
+cgit