* [PATCH 01/27] gdb/testsuite: Don't link with -lm on windows-msvc
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 02/27] gdb/testsuite: Use unprefixed runtest for a native Windows/MSVC build Pedro Alves
` (25 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
When testing with --target=x86_64-pc-windows-msvc, all C/C++ tests
fail to build without this change, because target_compile adds -lm to
the link line, resulting in:
lld-link: error: could not open 'm.lib': no such file or directory
x86_64-pc-windows-msvc targets the MSVC ABI, and uses the MSVC headers
and libraries, and there is no traditional math library in that
environment. The math functions are part of the C runtime library
instead.
DejaGnu's default_target_compile does:
if {[board_info $dest exists mathlib]} {
append extra_ldflags " [board_info $dest mathlib]"
} else {
append extra_ldflags " -lm"
}
Forcing people to use a custom board just to override mathlib would be
too heavy handed, IMNSHO. Likewise for the approach of providing a
dummy empty m.lib library. Instead, handle this by making gdb_compile
itself set the mathlib board config, when targeting windows-msvc.
Change-Id: Ib4671c9f207399f5ba437aaefb70373b6f298c41
---
gdb/testsuite/lib/gdb.exp | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 9b86d53be08..eea39d4e8cc 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6553,6 +6553,25 @@ proc gdb_compile {source dest type options} {
global objdir
global gdb_saved_set_unbuffered_mode_obj
+ if {[istarget "*-*-windows-msvc*"]} {
+ # target_compile by default links with -lm, if the target
+ # board does not have 'mathlib' set to point to an alternative
+ # math library. The windows-msvc target uses the MSVC headers
+ # and libraries, and there is no separate math lib in that
+ # case, the math functions are found in the C runtime library
+ # instead. If mathlib is not set already in the target board,
+ # set it to empty and recurse, to override target_compile's
+ # default.
+ global board
+ set board [target_info name]
+ if {![board_info $board exists mathlib]} {
+ set_board_info mathlib ""
+ set result [gdb_compile $source $dest $type $options]
+ unset_board_info mathlib
+ return $result
+ }
+ }
+
set outdir [file dirname $dest]
# Handle compiling native Windows programs when testing Cygwin.
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 02/27] gdb/testsuite: Use unprefixed runtest for a native Windows/MSVC build
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
2026-07-23 13:00 ` [PATCH 01/27] gdb/testsuite: Don't link with -lm on windows-msvc Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 03/27] gdb/testsuite: Find host binutils in a native Windows/MSVC config Pedro Alves
` (24 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
This is the first of two pieces making plain "make check" Just Work
when testing a MinGW-hosted GDB targeting the MSVC ABI:
--host=x86_64-w64-mingw32 --target=x86_64-pc-windows-msvc
When running the testsuite for a configuration where the host and
target triplets differ, the testsuite Makefile runs a target-prefixed
runtest -- e.g. x86_64-pc-windows-msvc-runtest, which fails with:
/bin/sh: line 1: x86_64-pc-windows-msvc-runtest: command not found
For a MinGW-hosted GDB targeting the MSVC ABI, the two triplets
differ, but it's still a native configuration and the plain "runtest"
should be used.
This is the same native-vs-cross distinction that gdb/configure.ac
already makes for gdb_native, so fix this by factoring that logic into
a new GDB_AC_NATIVE m4 macro and use it in both places.
gdb/gdb-native.m4 is now included by both gdb/configure.ac (via
acinclude.m4) and gdb/testsuite/configure.ac (via aclocal.m4), the
same way transform.m4 is shared.
Change-Id: Ia2d8cc0c685d8dd0a070f570798817e620857ab1
---
gdb/acinclude.m4 | 3 +++
gdb/configure | 40 +++++++++++++++++++-------------------
gdb/configure.ac | 23 +++-------------------
gdb/gdb-native.m4 | 30 ++++++++++++++++++++++++++++
gdb/testsuite/Makefile.in | 3 ++-
gdb/testsuite/aclocal.m4 | 1 +
gdb/testsuite/configure | 19 ++++++++++++++++++
gdb/testsuite/configure.ac | 5 +++++
8 files changed, 83 insertions(+), 41 deletions(-)
create mode 100644 gdb/gdb-native.m4
diff --git a/gdb/acinclude.m4 b/gdb/acinclude.m4
index 64cbab0b93a..c74e2d3dcba 100644
--- a/gdb/acinclude.m4
+++ b/gdb/acinclude.m4
@@ -15,6 +15,9 @@ m4_include(acx_configure_dir.m4)
# This gets GDB_AC_TRANSFORM.
m4_include(transform.m4)
+# This gets GDB_AC_NATIVE.
+m4_include(gdb-native.m4)
+
# This get AM_GDB_COMPILER_TYPE.
m4_include(../gdbsupport/compiler-type.m4)
diff --git a/gdb/configure b/gdb/configure
index 93b2df6f99b..f0f90b6be08 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -25218,26 +25218,26 @@ CPPFLAGS=$OLD_CPPFLAGS
# configuration.
gdb_host_obs=posix-hdep.o
-# Check whether the configuration is native -- i.e., whether GDB will
-# debug processes running on the same machine it runs on. If so, we
-# let configure.host and configure.nat pull in the native-debug
-# support.
-gdb_native=no
-if test "${target}" = "${host}"; then
- gdb_native=yes
-elif test "${host_cpu}" = "${target_cpu}"; then
- # Debugging Windows binaries on a Windows host is native even when
- # the host and target triplets differ across the mingw/cygwin/msvc
- # ABI boundary. E.g., a mingw32-hosted GDB targeting binaries
- # produced by a compiler defaulting to windows-msvc.
- case ${host_os} in
- mingw* | cygwin*)
- case ${target_os} in
- mingw* | cygwin* | windows*)
- gdb_native=yes ;;
- esac ;;
- esac
-fi
+# Check whether the configuration is native. If so, we let
+# configure.host and configure.nat pull in the native-debug support.
+
+ gdb_native=no
+ if test "${target}" = "${host}"; then
+ gdb_native=yes
+ elif test "${host_cpu}" = "${target_cpu}"; then
+ # Debugging Windows binaries on a Windows host is native even when
+ # the host and target triplets differ across the mingw/cygwin/msvc
+ # ABI boundary. E.g., a mingw32-hosted GDB targeting binaries
+ # produced by a compiler defaulting to windows-msvc.
+ case ${host_os} in
+ mingw* | cygwin*)
+ case ${target_os} in
+ mingw* | cygwin* | windows*)
+ gdb_native=yes ;;
+ esac ;;
+ esac
+ fi
+
. $srcdir/configure.host
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 50d04ff9027..30972e9a442 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -222,26 +222,9 @@ BFD_64_BIT
# configuration.
gdb_host_obs=posix-hdep.o
-# Check whether the configuration is native -- i.e., whether GDB will
-# debug processes running on the same machine it runs on. If so, we
-# let configure.host and configure.nat pull in the native-debug
-# support.
-gdb_native=no
-if test "${target}" = "${host}"; then
- gdb_native=yes
-elif test "${host_cpu}" = "${target_cpu}"; then
- # Debugging Windows binaries on a Windows host is native even when
- # the host and target triplets differ across the mingw/cygwin/msvc
- # ABI boundary. E.g., a mingw32-hosted GDB targeting binaries
- # produced by a compiler defaulting to windows-msvc.
- case ${host_os} in
- mingw* | cygwin*)
- case ${target_os} in
- mingw* | cygwin* | windows*)
- gdb_native=yes ;;
- esac ;;
- esac
-fi
+# Check whether the configuration is native. If so, we let
+# configure.host and configure.nat pull in the native-debug support.
+GDB_AC_NATIVE([gdb_native])
. $srcdir/configure.host
diff --git a/gdb/gdb-native.m4 b/gdb/gdb-native.m4
new file mode 100644
index 00000000000..0849c04d14b
--- /dev/null
+++ b/gdb/gdb-native.m4
@@ -0,0 +1,30 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# GDB_AC_NATIVE([VAR])
+#
+# Determine whether this is a native configuration -- i.e., whether
+# GDB will debug processes running on the same machine it runs on.
+# Store "yes" or "no" in the output variable.
+
+AC_DEFUN([GDB_AC_NATIVE], [
+ $1=no
+ if test "${target}" = "${host}"; then
+ $1=yes
+ elif test "${host_cpu}" = "${target_cpu}"; then
+ # Debugging Windows binaries on a Windows host is native even when
+ # the host and target triplets differ across the mingw/cygwin/msvc
+ # ABI boundary. E.g., a mingw32-hosted GDB targeting binaries
+ # produced by a compiler defaulting to windows-msvc.
+ case ${host_os} in
+ mingw* | cygwin*)
+ case ${target_os} in
+ mingw* | cygwin* | windows*)
+ $1=yes ;;
+ esac ;;
+ esac
+ fi
+])
diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in
index f103d7ddd65..b852dbceb50 100644
--- a/gdb/testsuite/Makefile.in
+++ b/gdb/testsuite/Makefile.in
@@ -28,6 +28,7 @@ program_transform_name = @program_transform_name@
build_canonical = @build@
host_canonical = @host@
target_canonical = @target@
+gdb_native = @gdb_native@
enable_libctf = @enable_libctf@
SHELL = @SHELL@
@@ -66,7 +67,7 @@ RUNTEST_FOR_TARGET = `\
if [ -f $${srcdir}/../../dejagnu/runtest ]; then \
echo $${srcdir}/../../dejagnu/runtest; \
else \
- if [ "$(host_canonical)" = "$(target_canonical)" ]; then \
+ if [ "$(gdb_native)" = yes ]; then \
echo runtest; \
else \
t='$(program_transform_name)'; echo runtest | sed -e $$t; \
diff --git a/gdb/testsuite/aclocal.m4 b/gdb/testsuite/aclocal.m4
index c5d3ba527a7..0fe30d7fc5c 100644
--- a/gdb/testsuite/aclocal.m4
+++ b/gdb/testsuite/aclocal.m4
@@ -2,6 +2,7 @@ m4_include(../../config/acx.m4)
m4_include(../../config/override.m4)
m4_include(../../config/enable.m4)
m4_include(../transform.m4)
+m4_include(../gdb-native.m4)
# AM_CONDITIONAL -*- Autoconf -*-
diff --git a/gdb/testsuite/configure b/gdb/testsuite/configure
index 6ea9686516d..f2818fd0a0c 100755
--- a/gdb/testsuite/configure
+++ b/gdb/testsuite/configure
@@ -626,6 +626,7 @@ NM_TRANSFORM_NAME
GAS_TRANSFORM_NAME
READELF_TRANSFORM_NAME
STRIP_TRANSFORM_NAME
+gdb_native
EXTRA_RULES
EGREP
GREP
@@ -3449,6 +3450,24 @@ if test "${build}" = "${host}" -a "${host}" = "${target}"; then
fi
+# Whether this is a native configuration. When it is, the testsuite
+# runs the unprefixed "runtest" rather than a target-prefixed one.
+
+ gdb_native=no
+ if test "${target}" = "${host}"; then
+ gdb_native=yes
+ elif test "${host_cpu}" = "${target_cpu}"; then
+ case ${host_os} in
+ mingw* | cygwin*)
+ case ${target_os} in
+ mingw* | cygwin* | windows*)
+ gdb_native=yes ;;
+ esac ;;
+ esac
+ fi
+
+
+
# Transform the name of some programs and generate the lib/pdtrace
# test tool.
test "$program_prefix" != NONE &&
diff --git a/gdb/testsuite/configure.ac b/gdb/testsuite/configure.ac
index 6eae19656df..8e64b216f95 100644
--- a/gdb/testsuite/configure.ac
+++ b/gdb/testsuite/configure.ac
@@ -86,6 +86,11 @@ if test "${build}" = "${host}" -a "${host}" = "${target}"; then
fi
AC_SUBST(EXTRA_RULES)
+# Whether this is a native configuration. When it is, the testsuite
+# runs the unprefixed "runtest" rather than a target-prefixed one.
+GDB_AC_NATIVE([gdb_native])
+AC_SUBST(gdb_native)
+
# Transform the name of some programs and generate the lib/pdtrace
# test tool.
AC_ARG_PROGRAM
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 03/27] gdb/testsuite: Find host binutils in a native Windows/MSVC config
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
2026-07-23 13:00 ` [PATCH 01/27] gdb/testsuite: Don't link with -lm on windows-msvc Pedro Alves
2026-07-23 13:00 ` [PATCH 02/27] gdb/testsuite: Use unprefixed runtest for a native Windows/MSVC build Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 04/27] gdb/testsuite: Compile with -Wno-deprecated-declarations on windows-msvc Pedro Alves
` (23 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
This is the second of two pieces making plain "make check" Just Work
OOTB when testing a MinGW-hosted GDB targeting the MSVC ABI:
--host=x86_64-w64-mingw32 --target=x86_64-pc-windows-msvc
The
gdb_find_objcopy
gdb_find_objdump
gdb_find_readelf
gdb_find_windres
gdb_find_eu-unstrip
procs in lib/future.exp fall back to dejagnu's "transform", which
prefixes the tool with the target triplet whenever the host and target
triplets differ.
For a MinGW-hosted GDB targeting the MSVC ABI, that fallback produces
e.g. x86_64-pc-windows-msvc-objcopy, which does not exist, so tests
that use these tools fail with, e.g.:
couldn't execute "x86_64-pc-windows-msvc-objcopy": no such file or directory
FAIL: gdb.base/step-symless.exp: strip stub symbols
Even though the two triplets differ, this is a Windows native
configuration and a host tool could be used.
Both gdb/configure.ac and gdb/testsuite/configure.ac use
GDB_AC_NATIVE, which treats this --host/--target combination as
native. gdb/testsuite/configure.ac already stores that result in the
gdb_native substitution variable, so propagate it to the testsuite via
site.exp. Doing it this way keeps a single source of truth rather
than reimplementing the same logic in Tcl.
Which host tool to run, though, depends on the environment. For
example:
- The MSYS2 binutils package has bare tools only, e.g. objdump, with
no x86_64-w64-mingw32-objdump:
https://packages.msys2.org/packages/mingw-w64-x86_64-binutils
- The xPack MinGW binutils distribution has host-triple-prefixed tools
only, e.g. x86_64-w64-mingw32-objdump, with no bare objdump:
https://github.com/xpack-dev-tools/gcc-xpack/
So rather than assume one spelling, search for whichever exists. Add
a gdb_transform_tool helper that, given a tool name, searches PATH in
the following order:
1. The target-prefixed name (via "transform"). This is the
preexisting behavior for a genuine cross.
2. For native configurations only, the host-triple-prefixed name.
3. For native configurations only, the bare name.
So for:
--host=x86_64-w64-mingw32 --target=x86_64-pc-windows-msvc
and for objdump, we try:
x86_64-pc-windows-msvc-objdump
x86_64-w64-mingw32-objdump
objdump
If none of the candidates is found, the helper returns the
target-prefixed name unchanged as before, so the "tool not found"
error is exactly as before.
Change-Id: If48c625503c7c14bf8365e35bfe58c38a3bb7ae9
---
gdb/testsuite/Makefile.in | 1 +
gdb/testsuite/lib/future.exp | 83 +++++++++++++++++++++++++++---------
gdb/testsuite/lib/gdb.exp | 13 ++++++
3 files changed, 77 insertions(+), 20 deletions(-)
diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in
index b852dbceb50..c4d7f4f284c 100644
--- a/gdb/testsuite/Makefile.in
+++ b/gdb/testsuite/Makefile.in
@@ -135,6 +135,7 @@ $(abs_builddir)/site.exp site.exp: Makefile
echo "set srcdir ${abs_srcdir}" >> ./tmp0; \
echo "set tool gdb" >> ./tmp0; \
echo "set enable_libctf ${enable_libctf}" >> ./tmp0; \
+ echo "set gdb_native $(if $(filter yes,$(gdb_native)),1,0)" >> ./tmp0; \
echo 'source $${srcdir}/lib/append_gdb_boards_dir.exp' >> ./tmp0; \
echo "## All variables above are generated by configure. Do Not Edit ##" >> ./tmp0; \
cat ./tmp0 > site.exp; \
diff --git a/gdb/testsuite/lib/future.exp b/gdb/testsuite/lib/future.exp
index 3ab160a05fc..ca37fdaaf52 100644
--- a/gdb/testsuite/lib/future.exp
+++ b/gdb/testsuite/lib/future.exp
@@ -146,55 +146,98 @@ proc gdb_find_ldd {} {
return $ldd
}
+# Return the name of a target binary utility TOOL, e.g. "objcopy".
+#
+# Normally, this is the target-prefixed TOOL, as computed by dejagnu's
+# 'transform'. On a native configuration, if that name is not on
+# PATH, fall back to a host tool instead. This makes the binary
+# utilities usable when the host and target triplets differ on what we
+# still consider a native configuration, e.g. a MinGW-hosted GDB
+# targeting the MSVC ABI.
+#
+# Only use this for a tool that behaves the same whether it is the
+# host or the target build of the tool -- the binary utilities that
+# operate on the shared object file format (objcopy, objdump, readelf,
+# etc.) qualify. Do not use this for a tool whose behavior depends on
+# the target, such as the compiler: the host compiler builds for the
+# host, not for the debuggee's ABI.
+
+proc gdb_transform_tool {tool} {
+ # Compute the target-prefixed name with transform's verbose
+ # logging suppressed -- we may end up only probing this candidate
+ # and not running it (in the native case), so we don't want
+ # transform's "Transforming ..." line in the log until we know
+ # this is the name we return.
+ set save_verbose $::verbose
+ set ::verbose -1
+ set target_tool [transform $tool]
+ set ::verbose $save_verbose
+
+ # Default to the target-prefixed name. It is the right tool for a
+ # cross, and for the not-found case it gives the same "tool not
+ # found" error as DejaGnu's transform would.
+ set result $target_tool
+
+ if {[which $target_tool] == 0 && [gdb_is_native_config]} {
+ # Try looking for a host tool: the host-triple-prefixed name
+ # first (e.g. x86_64-w64-mingw32-objcopy), then the bare name
+ # (e.g. objcopy).
+ set host_tool "[ishost {}]-$tool"
+ if {[which $host_tool] != 0} {
+ set result $host_tool
+ } elseif {[which $tool] != 0} {
+ set result $tool
+ }
+ }
+
+ # Log the transformation the way dejagnu's transform would, but
+ # for the name we actually settled on.
+ if {$result ne $tool} {
+ verbose "Transforming $tool to $result"
+ }
+
+ return $result
+}
+
proc gdb_find_objcopy {} {
global OBJCOPY_FOR_TARGET
if {[info exists OBJCOPY_FOR_TARGET]} {
- set objcopy $OBJCOPY_FOR_TARGET
- } else {
- set objcopy [transform objcopy]
+ return $OBJCOPY_FOR_TARGET
}
- return $objcopy
+ return [gdb_transform_tool objcopy]
}
# find target objdump
proc gdb_find_objdump {} {
global OBJDUMP_FOR_TARGET
if {[info exists OBJDUMP_FOR_TARGET]} {
- set objdump $OBJDUMP_FOR_TARGET
- } else {
- set objdump [transform objdump]
+ return $OBJDUMP_FOR_TARGET
}
- return $objdump
+ return [gdb_transform_tool objdump]
}
proc gdb_find_readelf {} {
global READELF_FOR_TARGET
if {[info exists READELF_FOR_TARGET]} {
- set readelf $READELF_FOR_TARGET
- } else {
- set readelf [transform readelf]
+ return $READELF_FOR_TARGET
}
- return $readelf
+ return [gdb_transform_tool readelf]
}
proc gdb_find_windres {} {
global WINDRES_FOR_TARGET
if {[info exists WINDRES_FOR_TARGET]} {
- set windres $WINDRES_FOR_TARGET
- } else {
- set windres [transform windres]
+ return $WINDRES_FOR_TARGET
}
- return $windres
+ return [gdb_transform_tool windres]
}
proc gdb_find_eu-unstrip {} {
global EU_UNSTRIP_FOR_TARGET
if {[info exists EU_UNSTRIP_FOR_TARGET]} {
- set eu_unstrip $EU_UNSTRIP_FOR_TARGET
- } else {
- set eu_unstrip [transform eu-unstrip]
+ return $EU_UNSTRIP_FOR_TARGET
}
- return $eu_unstrip
+ return [gdb_transform_tool eu-unstrip]
}
# Local version of default_target_compile, to be used for languages that
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index eea39d4e8cc..b4046c402d4 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -4223,6 +4223,19 @@ proc is_windows_based_target {} {
return [expr {[istarget *-*-cygwin*] || [istarget *-*-mingw*]}]
}
+# Return true if this is a native configuration in GDB's sense. This
+# is broader than dejagnu's isnative, which returns true iff we have
+# identical host and target triplets. On Windows the host and target
+# triplets can differ and the GDB build can still natively debug the
+# target. E.g. a mingw-hosted GDB targeting binaries produced by a
+# compiler defaulting to windows-msvc.
+
+proc gdb_is_native_config {} {
+ # configure already worked this out and the result is found in
+ # site.exp in this boolean.
+ return $::gdb_native
+}
+
# Return 1 if displaced stepping is supported on target, otherwise, return 0.
proc support_displaced_stepping {} {
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 04/27] gdb/testsuite: Compile with -Wno-deprecated-declarations on windows-msvc
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (2 preceding siblings ...)
2026-07-23 13:00 ` [PATCH 03/27] gdb/testsuite: Find host binutils in a native Windows/MSVC config Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 05/27] gdb/testsuite: Recognize windows-msvc across lib/gdb.exp procedures Pedro Alves
` (22 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
Several testcases hit compilation errors like:
output is .../testsuite/gdb.base/callfuncs.c:231:3: warning: 'strcpy' is deprecated: This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations]
231 | strcpy (buf, tstruct.a);
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\string.h:130:1: note: 'strcpy' has been explicitly marked deprecated here
130 | __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:874:5: note: expanded from macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1'
874 | __DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(_ReturnType, _ReturnPolicy, _DeclSpec, _FuncName, _FuncName##_s, _DstType, _SalAttributeDst, _DstType, _Dst, _TType1, _TArg1)
| ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt.h:1933:17: note: expanded from macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX'
1933 | _CRT_INSECURE_DEPRECATE(_SecureFuncName) _DeclSpec _ReturnType __cdecl _FuncName(_SalAttributeDst _DstType *_Dst, _TType1 _TArg1);
| ^
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:368:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
368 | #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT( \
| ^
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vcruntime.h:358:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
358 | #define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
| ^
Fix this by always compiling C/C++ tests with
-Wno-deprecated-declarations on windows-msvc targets.
Change-Id: I9058f70c69a7b9e5ebf2f38b84c7e35df92ddc0d
---
gdb/testsuite/lib/gdb.exp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index b4046c402d4..fb9f29ee03d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6671,6 +6671,21 @@ proc gdb_compile {source dest type options} {
|| [test_compiler_info {icc-20-21-[7-9]}]} {
lappend new_options "additional_flags=-diag-disable=10441"
}
+
+ if {[istarget "*-*-windows-msvc*"]
+ && ([test_compiler_info "clang-*"]
+ || [test_compiler_info "gcc-*"])} {
+ # Compiling with the MSVC headers results in:
+ #
+ # warning: 'strcpy' is deprecated: This function or variable may be unsafe.
+ # Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
+ # See online help for details. [-Wdeprecated-declarations]
+ #
+ # We get the same warning for strcpy, getenv, fopen,
+ # wcscat, and others, throughout the testsuite. Easier to
+ # just disable globally.
+ lappend new_options "additional_flags=-Wno-deprecated-declarations"
+ }
}
# If the 'build-id' option is used, then ensure that we generate a
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 05/27] gdb/testsuite: Recognize windows-msvc across lib/gdb.exp procedures
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (3 preceding siblings ...)
2026-07-23 13:00 ` [PATCH 04/27] gdb/testsuite: Compile with -Wno-deprecated-declarations on windows-msvc Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 06/27] gdb/testsuite: Don't pass -fPIC on PE/COFF targets Pedro Alves
` (21 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
The testsuite has many istarget checks like e.g.:
[istarget *-*-mingw*] || [istarget *-*-cygwin*]
and
[istarget *-*-mingw*] || [istarget *-*-cygwin*] || [istarget *-*-pe*]
to decide Windows- or PE/COFF-specific behavior. These do not match a
windows-msvc target, whose triplets are
{x86_64,aarch64,i686}-pc-windows-msvc, so on such a configuration the
testsuite would take the non-Windows paths and misbehave in many
places.
Rather than adding windows-msvc to each site by hand, introduce two
predicates and replace the existing checks in lib/gdb.exp with them:
- is_windows_native_target -- mingw* or windows* triplets, as opposed
to Cygwin.
- is_pecoff_target -- any Windows-based target or a bare PE target.
is_windows_based_target is extended to build on
is_windows_native_target so it too picks up windows-msvc.
Following patches will go over the testcases throughout using these
predicates.
Change-Id: I786285c009565ec2d3ddc06c0ba57d466d42e4d0
---
gdb/testsuite/lib/gdb.exp | 62 +++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index fb9f29ee03d..db22d2bc320 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2528,7 +2528,7 @@ proc default_gdb_exit {} {
}
if { ([is_remote host] && [board_info host exists fileid])
- || [istarget *-*-mingw*] } {
+ || [is_windows_native_target] } {
send_gdb "quit\n"
gdb_expect 10 {
-re "y or n" {
@@ -3102,9 +3102,7 @@ proc allow_shlib_tests {} {
if {([istarget *-*-linux*]
|| [istarget *-*-*bsd*]
|| [istarget *-*-solaris2*]
- || [istarget *-*-mingw*]
- || [istarget *-*-cygwin*]
- || [istarget *-*-pe*])} {
+ || [is_pecoff_target])} {
return 1
}
@@ -3210,7 +3208,7 @@ gdb_caching_proc allow_dlmopen_tests {} {
# Return 1 if we should allow TUI-related tests.
gdb_caching_proc allow_tui_tests {} {
- if { [istarget *-*-mingw*] } {
+ if { [is_windows_native_target] } {
# Avoid "Cannot enable the TUI when output is not a terminal".
return 0
}
@@ -4217,10 +4215,25 @@ proc is_aarch64_target {} {
return [expr {![is_aarch32_target]}]
}
+# Return true if the target is Windows native (as opposed to Cygwin).
+
+proc is_windows_native_target {} {
+ return [expr {[istarget *-*-mingw*]
+ || [istarget *-*-windows*]}]
+}
+
# Return true if the target is Windows-based.
proc is_windows_based_target {} {
- return [expr {[istarget *-*-cygwin*] || [istarget *-*-mingw*]}]
+ return [expr {[istarget *-*-cygwin*]
+ || [is_windows_native_target]}]
+}
+
+# Return true if the target is PE/COFF-based.
+
+proc is_pecoff_target {} {
+ return [expr {[is_windows_based_target]
+ || [istarget *-*-pe*]}]
}
# Return true if this is a native configuration in GDB's sense. This
@@ -5736,7 +5749,7 @@ proc skip_inline_var_tests {} {
# time out sequences.
proc allow_fork_tests {} {
- if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+ if {[is_windows_based_target]} {
return 0
}
@@ -5750,7 +5763,7 @@ proc allow_fork_tests {} {
# false.
proc allow_multi_inferior_tests {} {
- if {[istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"]} {
+ if {[is_windows_based_target]} {
return 0
}
@@ -6792,17 +6805,14 @@ proc gdb_compile {source dest type options} {
# IBM xlc compiler doesn't accept shared library named other
# than .so: use "-Wl," to bypass this
lappend source "-Wl,$shlib_name"
- } elseif { ([istarget "*-*-mingw*"]
- || [istarget *-*-cygwin*]
- || [istarget *-*-pe*])} {
+ } elseif { [is_pecoff_target] } {
lappend source "${shlib_name}.a"
} else {
lappend source $shlib_name
}
if { $shlib_found == 0 } {
set shlib_found 1
- if { ([istarget "*-*-mingw*"]
- || [istarget *-*-cygwin*]) } {
+ if { [is_pecoff_target] } {
lappend new_options "ldflags=-Wl,--enable-auto-import"
}
if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
@@ -6924,9 +6934,7 @@ proc gdb_compile {source dest type options} {
# (depending on the platform) to set a special rpath value, to allow
# the executable to find the libraries it depends on.
if { $shlib_load || $shlib_found } {
- if { ([istarget "*-*-mingw*"]
- || [istarget *-*-cygwin*]
- || [istarget *-*-pe*]) } {
+ if { [is_pecoff_target] } {
# Do not need anything.
} elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } {
lappend new_options "ldflags=-Wl,-rpath,${outdir}"
@@ -7022,9 +7030,7 @@ proc gdb_compile {source dest type options} {
}
if { $type == "executable" } {
- if { ([istarget "*-*-mingw*"]
- || [istarget "*-*-*djgpp"]
- || [istarget "*-*-cygwin*"])} {
+ if { [is_windows_based_target] || [istarget "*-*-*djgpp"] } {
# Force output to unbuffered mode, by linking in an object file
# with a global constructor that calls setvbuf.
#
@@ -7299,9 +7305,7 @@ proc gdb_compile_shlib_1 {sources dest options} {
} else {
lappend link_options "additional_flags=-shared"
- if { ([istarget "*-*-mingw*"]
- || [istarget *-*-cygwin*]
- || [istarget *-*-pe*]) } {
+ if { [is_pecoff_target] } {
if { [is_remote host] } {
set name [file tail ${dest}]
} else {
@@ -7325,10 +7329,7 @@ proc gdb_compile_shlib_1 {sources dest options} {
if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
return -1
}
- if { [is_remote host]
- && ([istarget "*-*-mingw*"]
- || [istarget *-*-cygwin*]
- || [istarget *-*-pe*]) } {
+ if { [is_remote host] && [is_pecoff_target] } {
set dest_tail_name [file tail ${dest}]
remote_upload host $dest_tail_name.a ${dest}.a
remote_file host delete $dest_tail_name.a
@@ -7841,7 +7842,7 @@ proc kill_wait_spawned_process { proc_spawn_id } {
proc spawn_id_get_pid { spawn_id } {
set testpid [exp_pid -i $spawn_id]
- if { [istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"] } {
+ if { [is_windows_based_target] } {
# testpid is the Cygwin PID, GDB uses the Windows PID, which
# might be different due to the way fork/exec works.
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
@@ -9102,7 +9103,7 @@ proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
if {$allow_extra} {
set extra ".*"
- } elseif {[istarget *-*-cygwin*] || [istarget *-*-mingw*]} {
+ } elseif {[is_windows_based_target]} {
# On Windows, even on supposedly single-threaded programs, we
# may see thread exit output when running to end, for threads
# spawned by the runtime. E.g.:
@@ -9479,7 +9480,7 @@ gdb_caching_proc gdb_has_argv0 {} {
|| [istarget *-*-solaris*]
|| [istarget *-*-aix*]
|| [istarget *-*-gnu*]
- || [istarget *-*-cygwin*] || [istarget *-*-mingw32*]
+ || [is_windows_based_target]
|| [istarget *-*-*djgpp*] || [istarget *-*-go32*]
|| [istarget *-wince-pe] || [istarget *-*-mingw32ce*]
|| [istarget *-*-osf*]
@@ -9512,8 +9513,7 @@ gdb_caching_proc gdb_has_argv0 {} {
# Returns "" if there is none.
proc get_build_id { filename } {
- if { ([istarget "*-*-mingw*"]
- || [istarget *-*-cygwin*]) } {
+ if { ([is_windows_based_target]) } {
set objdump_program [gdb_find_objdump]
set result [catch {set data [exec $objdump_program -p $filename | grep signature | cut "-d " -f4]} output]
verbose "result is $result"
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 06/27] gdb/testsuite: Don't pass -fPIC on PE/COFF targets
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (4 preceding siblings ...)
2026-07-23 13:00 ` [PATCH 05/27] gdb/testsuite: Recognize windows-msvc across lib/gdb.exp procedures Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 07/27] gdb/testsuite: Use /IMPLIB on windows-msvc to name import libraries Pedro Alves
` (20 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
'-fPIC' is not needed for any PE/COFF-based target. We were passing
'-fPIC' on mingw and cygwin, and it works there because GCC and Clang
simply ignore that option for those targets (to ease portability), but
Clang for x86_64-pc-windows-msvc isn't as forgiving:
error: unsupported option '-fPIC' for target 'x86_64-pc-windows-msvc'
Originally, gdb.exp wasn't passing -fPIC on cygwin/mingw, but it
started doing that with commit 2f4132646d8 ("[gdb/testsuite] Don't
pass -fPIC to gdb_compile_shlib"). Before that commit,
gdb_compile_shlib added -fpic on the platforms that need it, but added
nothing in some cases (cygwin, mingw and pe, and the unknown-compiler
fallback), and the individual testcases papered over that by passing
additional_flags=-fPIC unconditionally themselves. That commit moved
the -fPIC from the testcase calls to gdb_compile_shlib, adding it in
exactly those previously-empty cases, which is how cygwin and mingw
ended up being passed -fPIC even though they don't need it.
Change-Id: I6883bc14381883eac3ee825a65ef67ed26bcadce
---
gdb/testsuite/lib/gdb.exp | 47 ++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index db22d2bc320..25f01ed9727 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -7226,35 +7226,32 @@ proc gdb_compile_shlib_1 {sources dest options} {
set info_options "c"
}
- switch -glob [test_compiler_info "" ${info_options}] {
- "xlc-*" {
- lappend obj_options "additional_flags=-qpic"
- }
- "clang-*" {
- if { [istarget "*-*-cygwin*"]
- || [istarget "*-*-mingw*"] } {
- lappend obj_options "additional_flags=-fPIC"
- } else {
- lappend obj_options "additional_flags=-fpic"
+ if { [is_pecoff_target] } {
+ # Nothing needed, PE targets always compile all code as
+ # position-independent.
+ } else {
+ switch -glob [test_compiler_info "" ${info_options}] {
+ "xlc-*" {
+ lappend obj_options "additional_flags=-qpic"
}
- }
- "gcc-*" {
- if { [istarget "powerpc*-*-aix*"]
- || [istarget "rs6000*-*-aix*"]
- || [istarget "*-*-cygwin*"]
- || [istarget "*-*-mingw*"]
- || [istarget "*-*-pe*"] } {
- lappend obj_options "additional_flags=-fPIC"
- } else {
+ "clang-*" {
lappend obj_options "additional_flags=-fpic"
}
- }
- "icc-*" {
+ "gcc-*" {
+ if { [istarget "powerpc*-*-aix*"]
+ || [istarget "rs6000*-*-aix*"] } {
+ lappend obj_options "additional_flags=-fPIC"
+ } else {
+ lappend obj_options "additional_flags=-fpic"
+ }
+ }
+ "icc-*" {
lappend obj_options "additional_flags=-fpic"
- }
- default {
- # don't know what the compiler is...
- lappend obj_options "additional_flags=-fPIC"
+ }
+ default {
+ # don't know what the compiler is...
+ lappend obj_options "additional_flags=-fPIC"
+ }
}
}
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 07/27] gdb/testsuite: Use /IMPLIB on windows-msvc to name import libraries
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (5 preceding siblings ...)
2026-07-23 13:00 ` [PATCH 06/27] gdb/testsuite: Don't pass -fPIC on PE/COFF targets Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:00 ` [PATCH 08/27] gdb/testsuite: Export all DLL symbols on windows-msvc via generated .def Pedro Alves
` (19 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
When building a shared library for a test, gdb_compile_shlib asks the
linker to write an import library named after the DLL, so that the
test executable can later link against it. This currently always uses
GNU ld's --out-implib switch.
lld-link, the linker Clang drives on a windows-msvc target, does not
understand --out-implib. It only accepts MSVC's link.exe slash-style
flags. Use /IMPLIB instead, which names the import library the same
way.
Change-Id: I3deb3f0d16c27891b69e40f01656944ed5d52210
---
gdb/testsuite/lib/gdb.exp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 25f01ed9727..c9ee8e9753d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -7308,7 +7308,11 @@ proc gdb_compile_shlib_1 {sources dest options} {
} else {
set name ${dest}
}
- lappend link_options "ldflags=-Wl,--out-implib,${name}.a"
+ if { [istarget "*-*-windows-msvc*"] } {
+ lappend link_options "ldflags=-Wl,/IMPLIB:${name}.a"
+ } else {
+ lappend link_options "ldflags=-Wl,--out-implib,${name}.a"
+ }
} else {
# Set the soname of the library. This causes the linker on ELF
# systems to create the DT_NEEDED entry in the executable referring
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 08/27] gdb/testsuite: Export all DLL symbols on windows-msvc via generated .def
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (6 preceding siblings ...)
2026-07-23 13:00 ` [PATCH 07/27] gdb/testsuite: Use /IMPLIB on windows-msvc to name import libraries Pedro Alves
@ 2026-07-23 13:00 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 09/27] gdb/testsuite: Restrict --no-as-needed to ELF targets Pedro Alves
` (18 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:00 UTC (permalink / raw)
To: gdb-patches
When building a shared library for a test, gdb_compile_shlib arranges
for the DLL's symbols to be exported and for an import library to be
produced, so that the test executable can link against the DLL. With
GNU ld this works implicitly: linking a DLL exports all of its symbols
by default.
lld-link, which is the linker clang drives on a windows-msvc target,
does not do that. It exports nothing unless explicitly told to, via
__declspec(dllexport) in the sources, a /EXPORT switch per symbol, or
a module-definition (.def) file. The testsuite's shared-library
sources carry (almost) no dllexport annotations, so the import library
comes out empty and linking the test executable fails, e.g.:
lld-link: error: undefined symbol: pendfunc
Fix this by restoring the export-all-symbols behavior by generating a
.def file that lists every defined, external symbol in the DLL's
objects, and passing it to lld-link with /DEF. The symbol list is
collected with nm.
FWIW, this is the same approach CMake takes for its
WINDOWS_EXPORT_ALL_SYMBOLS target property.
Change-Id: I1a9638259986910d473c4f02fbf60437e3653e04
---
gdb/testsuite/lib/future.exp | 8 +++++
gdb/testsuite/lib/gdb.exp | 64 +++++++++++++++++++++++++++++++++++-
2 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/lib/future.exp b/gdb/testsuite/lib/future.exp
index ca37fdaaf52..e308bef0a60 100644
--- a/gdb/testsuite/lib/future.exp
+++ b/gdb/testsuite/lib/future.exp
@@ -224,6 +224,14 @@ proc gdb_find_readelf {} {
return [gdb_transform_tool readelf]
}
+proc gdb_find_nm {} {
+ global NM_FOR_TARGET
+ if {[info exists NM_FOR_TARGET]} {
+ return $NM_FOR_TARGET
+ }
+ return [gdb_transform_tool nm]
+}
+
proc gdb_find_windres {} {
global WINDRES_FOR_TARGET
if {[info exists WINDRES_FOR_TARGET]} {
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index c9ee8e9753d..b3588f0edec 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6812,7 +6812,11 @@ proc gdb_compile {source dest type options} {
}
if { $shlib_found == 0 } {
set shlib_found 1
- if { [is_pecoff_target] } {
+ # lld-link does not understand GNU ld's
+ # --enable-auto-import. On windows-msvc the DLL's
+ # symbols are exported via a generated .def instead.
+ # See gdb_windows_gen_def_file.
+ if { [is_pecoff_target] && ![istarget "*-*-windows-msvc*"] } {
lappend new_options "ldflags=-Wl,--enable-auto-import"
}
if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
@@ -7208,6 +7212,50 @@ proc gdb_compile_pthreads {source dest type options} {
}
}
+# Write a module-definition (.def) file to DEFFILE that exports every
+# defined, external symbol found in OBJECTS, and return DEFFILE.
+# Unlike GNU ld, which auto-exports a DLL's symbols, lld-link exports
+# nothing unless told to, so the import library it produces would be
+# empty and executables linking against the DLL would fail with
+# undefined symbols. Feeding lld-link this generated .def restores
+# the export-all-symbols behavior the testsuite relies on. Returns
+# empty string on failure.
+
+proc gdb_windows_gen_def_file {objects deffile} {
+ set nm [gdb_find_nm]
+
+ set exports {}
+ foreach obj $objects {
+ if {[catch {exec $nm $obj} output]} {
+ verbose -log "gdb_windows_gen_def_file: nm $obj failed: $output"
+ return ""
+ }
+ foreach line [split $output "\n"] {
+ # nm prints "<value> <type> <name>". A defined external
+ # symbol has an uppercase type letter, undefined (U) has a
+ # blank value, and local symbols use lowercase letters.
+ # Export text/weak as code and data/bss/rodata/common as
+ # DATA.
+ if {![regexp {^\S* +(\S) +(\S+)$} $line -> type name]} {
+ continue
+ }
+ switch -- $type {
+ "T" - "W" { lappend exports $name }
+ "D" - "B" - "R" - "C" { lappend exports "$name DATA" }
+ }
+ }
+ }
+
+ set f [open $deffile w]
+ puts $f "EXPORTS"
+ foreach e [lsort -unique $exports] {
+ puts $f " $e"
+ }
+ close $f
+
+ return $deffile
+}
+
# Build a shared library from SOURCES.
proc gdb_compile_shlib_1 {sources dest options} {
@@ -7310,6 +7358,20 @@ proc gdb_compile_shlib_1 {sources dest options} {
}
if { [istarget "*-*-windows-msvc*"] } {
lappend link_options "ldflags=-Wl,/IMPLIB:${name}.a"
+
+ # lld-link exports nothing by default, so generate a
+ # .def listing every symbol and feed it in, to get the
+ # export-all-symbols behavior GNU ld gives us
+ # implicitly.
+ set deffile [gdb_windows_gen_def_file $objects ${dest}.def]
+ if { $deffile eq "" } {
+ return -1
+ }
+ # Pass the path in Windows-native form so MSYS2's
+ # argument conversion doesn't mangle the "/DEF:/..."
+ # value.
+ set deffile [host_file_normalize $deffile]
+ lappend link_options "ldflags=-Wl,/DEF:${deffile}"
} else {
lappend link_options "ldflags=-Wl,--out-implib,${name}.a"
}
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 09/27] gdb/testsuite: Restrict --no-as-needed to ELF targets
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (7 preceding siblings ...)
2026-07-23 13:00 ` [PATCH 08/27] gdb/testsuite: Export all DLL symbols on windows-msvc via generated .def Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 10/27] gdb.base/set-cwd.exp: Use is_windows_native_target Pedro Alves
` (17 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
gdb_compile passes -Wl,--no-as-needed when linking a test executable
against a shared library, to keep the shared library's DT_NEEDED entry
even when no symbol from it is referenced at link time.
--as-needed/--no-as-needed is an ELF concept, though: it controls
whether the linker emits a DT_NEEDED tag in the .dynamic section for a
shared library that ends up unreferenced. Other object formats have
no DT_NEEDED, so the flag does nothing there. E.g., PE records a DLL
dependency in the import table, driven by which symbols are actually
imported. GNU ld accepts the option and silently ignores it for a PE
target (to easy portability), but lld-link, the linker clang drives on
windows-msvc, warns about it:
lld-link: warning: ignoring unknown argument '--no-as-needed'
Fix this by restricting the flag to ELF targets, using the existing
is_elf_target predicate.
Change-Id: Icb472ba2e9e38c25c179e14648340acaea2f463d
---
gdb/testsuite/lib/gdb.exp | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index b3588f0edec..dccafbb637a 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6819,7 +6819,18 @@ proc gdb_compile {source dest type options} {
if { [is_pecoff_target] && ![istarget "*-*-windows-msvc*"] } {
lappend new_options "ldflags=-Wl,--enable-auto-import"
}
- if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
+ # --as-needed/--no-as-needed control whether the
+ # linker emits a DT_NEEDED entry for an unreferenced
+ # shared library, which is an ELF .dynamic-section
+ # concept. It does nothing on other object formats
+ # (PE records DLL dependencies via the import table,
+ # Mach-O via LC_LOAD_DYLIB load commands, XCOFF via
+ # the loader section), and lld-link doesn't even
+ # recognize the option, warning about it. So only
+ # pass it when producing ELF.
+ if { [is_elf_target]
+ && ([test_compiler_info "gcc-*"]
+ || [test_compiler_info "clang-*"]) } {
# Undo debian's change in the default.
# Put it at the front to not override any user-provided
# value, and to make sure it appears in front of all the
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 10/27] gdb.base/set-cwd.exp: Use is_windows_native_target
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (8 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 09/27] gdb/testsuite: Restrict --no-as-needed to ELF targets Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 11/27] gdb.base/exitsignal.exp: " Pedro Alves
` (16 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
gdb.base/set-cwd.exp special-cases native Windows, where getcwd
returns a path with backslashes that has to be converted to forward
slashes before comparing against the expected directory. The check
guarding that conversion uses istarget "*-*-mingw*", which only
matches MinGW targets and misses windows-msvc targets, which are also
native Windows.
Fix it by using the is_windows_native_target helper instead.
Change-Id: I4a31cfaded2d402863e59ea742501d5cece6ec77
---
gdb/testsuite/gdb.base/set-cwd.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/set-cwd.exp b/gdb/testsuite/gdb.base/set-cwd.exp
index aae557ece27..dea87360095 100644
--- a/gdb/testsuite/gdb.base/set-cwd.exp
+++ b/gdb/testsuite/gdb.base/set-cwd.exp
@@ -84,7 +84,7 @@ proc test_dir {expected_dir message} {
}
}
- if {[istarget "*-*-mingw*"]} {
+ if {[is_windows_native_target]} {
# getcwd on native Windows uses backslashes. Convert to
# forward slashes. We look for pairs of backslashes as DIR
# comes from a C string printed by GDB, which escapes
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 11/27] gdb.base/exitsignal.exp: Use is_windows_native_target
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (9 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 10/27] gdb.base/set-cwd.exp: Use is_windows_native_target Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 12/27] gdb.base/exitsignal.exp: Relax SIGSEGV second-chance pattern Pedro Alves
` (15 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
gdb.base/exitsignal.exp special-cases the pure Win32 program path with
a hardcoded "*-*-mingw*" istarget check. Use is_windows_native_target
instead, so the special case also applies to windows-msvc targets.
Change-Id: I00611f28539aeddc23eb782e71f50d0874230cd8
---
gdb/testsuite/gdb.base/exitsignal.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp
index c77e41df78e..0ffb20258d1 100644
--- a/gdb/testsuite/gdb.base/exitsignal.exp
+++ b/gdb/testsuite/gdb.base/exitsignal.exp
@@ -120,7 +120,7 @@ proc test_signal {how exec binfile} {
gdb_test "continue" "(Thread .*|Program) received signal SIGSEGV.*" \
"trigger SIGSEGV"
- if {[istarget "*-*-mingw*"]
+ if {[is_windows_native_target]
|| ([istarget "*-*-cygwin*"] && $binfile == $::binfile3)} {
# We're debugging a pure Win32 program with no SEH handler. The
# previous continue caught the first-chance exception. Now we
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 12/27] gdb.base/exitsignal.exp: Relax SIGSEGV second-chance pattern
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (10 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 11/27] gdb.base/exitsignal.exp: " Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 13/27] gdb/testsuite: Skip -Ttext-segment on PE Pedro Alves
` (14 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The "trigger SIGSEGV, second-chance" test matches the signal stop with
Thread .* received signal SIGSEGV.*
GDB only prints the "Thread NNN received signal ..." form when the
inferior has more than one thread. For a single-threaded inferior it
prints "Program received signal ..." instead.
Whether a Windows program is multi-threaded by the time it reaches
main depends on the C runtime it links against:
- A program built against the dynamic UCRT pulls in ucrtbase.dll,
which starts additional threads during its initialization.
- A program built with a statically-linked CRT does not go through
that initialization, so it is still single-threaded at main.
Native MinGW test programs pull in ucrtbase.dll and so are
multi-threaded, but programs built with a clang x86_64-pc-windows-msvc
toolchain default to the static CRT and are single-threaded, so GDB
announces the signal with "Program received signal ..." and the test
fails:
Program received signal SIGSEGV, Segmentation fault.
0x00007ff628a9102f in main (argc=1, argv=0x50ff90) at .../gdb/testsuite/gdb.base/segv.c:41
41 *(volatile int *) 0;
(gdb) FAIL: gdb.base/exitsignal.exp: how=run: signal: trigger SIGSEGV, second-chance
Fix this by dropping the "Thread .*" prefix from the pattern so that
it matches both the "Thread NNN received signal" and "Program received
signal" forms.
Change-Id: I3ac3cd316da2126635a9e2b3338befec9c2a5195
---
gdb/testsuite/gdb.base/exitsignal.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/exitsignal.exp b/gdb/testsuite/gdb.base/exitsignal.exp
index 0ffb20258d1..dd968300fcb 100644
--- a/gdb/testsuite/gdb.base/exitsignal.exp
+++ b/gdb/testsuite/gdb.base/exitsignal.exp
@@ -125,7 +125,7 @@ proc test_signal {how exec binfile} {
# We're debugging a pure Win32 program with no SEH handler. The
# previous continue caught the first-chance exception. Now we
# catch the second-chance one.
- gdb_test "continue" "Thread .* received signal SIGSEGV.*" \
+ gdb_test "continue" " received signal SIGSEGV.*" \
"trigger SIGSEGV, second-chance"
} elseif {[istarget "*-*-cygwin*"]} {
# Cygwin calls DebugBreak before it lets the process exit.
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 13/27] gdb/testsuite: Skip -Ttext-segment on PE
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (11 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 12/27] gdb.base/exitsignal.exp: Relax SIGSEGV second-chance pattern Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 14/27] gdb/testsuite: Support text_segment on windows-msvc via /BASE Pedro Alves
` (13 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The gdb_compile text_segment option asks the linker to place the image
at a specific base address. It picks a linker flag by probing which
one the linker accepts, trying -Ttext-segment (GNU ld) first, then
--image-base (LLVM's lld).
On a PE target that order is wrong. GNU ld accepts -Ttext-segment
there, so the probe succeeds, but the PE emulation silently ignores
it. OTOH, --image-base is intercepted by the PE emulation to set the
real image base.
I.e., even though the comment in gdb.exp says that --image-base is for
LLVM lld, that is the right option for Windows GNU ld, too.
The result is that on mingw and cygwin the image base was never
actually being set.
Fix this by skipping the -Ttext-segment probe on PE targets so the
dispatch falls through to --image-base.
Change-Id: I79e4f3d8ef7e94deb42b895f3bbabb402a20d269
---
gdb/testsuite/lib/gdb.exp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index dccafbb637a..fcef2022a43 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6845,11 +6845,13 @@ proc gdb_compile {source dest type options} {
# procedure. Do not append it to new_options as this will cause
# recursion.
} elseif {[regexp "^text_segment=(.*)" $opt dummy_var addr]} {
- if { [linker_supports_Ttext_segment_flag] } {
- # For GNU ld.
+ if { ![is_pecoff_target]
+ && [linker_supports_Ttext_segment_flag] } {
+ # For GNU ld. On PE, GNU ld accepts -Ttext-segment,
+ # but silently ignores it.
lappend new_options "ldflags=-Wl,-Ttext-segment=$addr"
} elseif { [linker_supports_image_base_flag] } {
- # For LLVM's lld.
+ # For GNU ld on PE and for LLVM's lld.
lappend new_options "ldflags=-Wl,--image-base=$addr"
} elseif { [linker_supports_Ttext_flag] } {
# For old GNU gold versions.
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 14/27] gdb/testsuite: Support text_segment on windows-msvc via /BASE
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (12 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 13/27] gdb/testsuite: Skip -Ttext-segment on PE Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 15/27] gdb.base/shreloc.exp: Use gdb_compile text_segment to set image base Pedro Alves
` (12 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The gdb_compile text_segment option asks the linker to place the image
at a specific base address. It dispatches to the right linker flag by
probing which one the linker accepts:
-Ttext-segment => GNU ld
--image-base => LLVM's lld
-Ttext => gold
None of those are accepted by lld-link, the linker clang drives on a
windows-msvc target, so gdb_compile errors out with "Don't know how to
handle text_segment option."
Add a fourth probe case using lld-link's /BASE switch, gated on a new
linker_supports_base_flag probe that mirrors the existing ones. /BASE
sets the preferred image base the same way GNU ld's --image-base does.
Change-Id: I84d5a3de6d755a3794abb7358b16de5e516ddefa
---
gdb/testsuite/lib/gdb.exp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index fcef2022a43..bece5b6044d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6853,6 +6853,9 @@ proc gdb_compile {source dest type options} {
} elseif { [linker_supports_image_base_flag] } {
# For GNU ld on PE and for LLVM's lld.
lappend new_options "ldflags=-Wl,--image-base=$addr"
+ } elseif { [linker_supports_base_flag] } {
+ # For lld-link (MSVC link.exe compatible mode).
+ lappend new_options "ldflags=-Wl,/BASE:$addr"
} elseif { [linker_supports_Ttext_flag] } {
# For old GNU gold versions.
lappend new_options "ldflags=-Wl,-Ttext=$addr"
@@ -11457,6 +11460,15 @@ gdb_caching_proc linker_supports_image_base_flag {} {
return [gdb_simple_compile $me $src executable $flags]
}
+# Return 1 if linker supports /BASE (lld-link / MSVC link.exe),
+# otherwise 0.
+gdb_caching_proc linker_supports_base_flag {} {
+ set me "linker_supports_base_flag"
+ set flags ldflags=[quote_for_host -Wl,/BASE:0x7000000]
+ set src { int main() { return 0; } }
+ return [gdb_simple_compile $me $src executable $flags]
+}
+
# Return 1 if the linker is lld-link which can embed our application
# manifest by itself, otherwise 0. Probes the exact flag combination
# gdb_compile uses.
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 15/27] gdb.base/shreloc.exp: Use gdb_compile text_segment to set image base
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (13 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 14/27] gdb/testsuite: Support text_segment on windows-msvc via /BASE Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 16/27] gdb/coffread: Don't relocate absolute symbols Pedro Alves
` (11 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The gdb.base/shreloc.exp testcase wants its two shared libraries to
have the same preferred image base, so that when GDB mishandles a
relocated library its symbols collapse onto the other's and the
check_different tests catch it. On cygwin/mingw, to guarantee this,
it passes -Wl,--image-base directly.
Express the intent through gdb_compile's text_segment option instead
of open-coding the linker flag, and gate it on is_pecoff_target so it
is done on all PE targets, including windows-msvc.
This is mainly to avoid istarget special-casing, as in practice
lld-link already gives every DLL the same fixed default base, there is
no equivalent of --enable-auto-image-base there.
The second, cygwin/mingw-only block that checks the
"_minor_os_version__" absolute symbol is left as is. That symbol is
specific to GNU ld's PE output, so the check does not apply to
windows-msvc. That will change in a follow patch, though.
Change-Id: I002ed69603804c1ef6f18c0aa7b563e6bd80941b
---
gdb/testsuite/gdb.base/shreloc.exp | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.base/shreloc.exp b/gdb/testsuite/gdb.base/shreloc.exp
index e0efd61bcdf..718b1ca81ad 100644
--- a/gdb/testsuite/gdb.base/shreloc.exp
+++ b/gdb/testsuite/gdb.base/shreloc.exp
@@ -38,8 +38,15 @@ set lib2_sl [standard_output_file shreloc2.sl]
set lib_opts {debug shlib}
set exec_opts [list debug shlib=$lib1_sl shlib=$lib2_sl]
-if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
- lappend lib_opts "ldflags=-Wl,--image-base,0x04000000"
+if { [is_pecoff_target] } {
+ # Force both shared libraries to the same image base so that they
+ # overlap and one of them gets relocated at load time, which is
+ # what this test exercises. Without this, they would not
+ # necessarily overlap: some MinGW ld distributions default to
+ # --enable-auto-image-base, which derives each DLL's base from a
+ # hash of its file name, giving the two libraries different bases.
+ # Pinning the base defeats that.
+ lappend lib_opts "text_segment=0x04000000"
}
if {[test_compiler_info "xlc-*"]} {
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 16/27] gdb/coffread: Don't relocate absolute symbols
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (14 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 15/27] gdb.base/shreloc.exp: Use gdb_compile text_segment to set image base Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 17/27] gdb.base/shreloc.exp: Test absolute symbols portably Pedro Alves
` (10 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
A COFF absolute symbol (i.e., one with COFF section number N_ABS) has
a value that is a plain constant, not an offset into any section.
Such a symbol must not be adjusted when the objfile it belongs to is
relocated, e.g. when a DLL is loaded at an address other than its
preferred image base.
gdb/coffread.c records absolute symbols as mst_abs, which is correct,
but it derives the symbol's section from cs_to_section, which in turn
asks cs_to_bfd_section for the BFD section. cs_to_bfd_section matches
by section number and finds nothing for an N_ABS symbol, returning
NULL, so cs_to_section falls back to the text section. The symbol
then inherits the text section's relocation offset (the DLL's load
bias) and its value is wrongly shifted by that amount.
For a DLL loaded at its preferred base the bias is zero and the bug is
invisible, but when two DLLs are loaded overlapping so that one is
relocated, its absolute symbols come out shifted. This can be seen in
gdb.base/shreloc.exp, which loads two libraries at the same base and
checks that absolute symbols keep the same value in both:
(gdb) maint print msymbols ...
[4] A 0x5bc10000 __minor_os_version__ section .text
[4] A 0x5bbe0000 __minor_os_version__ section .text
__minor_os_version__ has value 0 in both DLLs, but GDB reports its
value as each symbols DLL's load base. Note also the contradictory "A
... section .text" -- an absolute symbol should not be tied to a
section at all.
Fix this in cs_to_bfd_section, by returning BFD's absolute section for
an N_ABS symbol rather than NULL. Its relocation offset is always
zero, so the symbol's value is left untouched, matching what
elf_symtab_read does for absolute ELF symbols. cs_to_section then
naturally returns the absolute section's index.
While at it, fold the N_ABS case in symtab_read into the general path.
Without this fix, gdb.base/shreloc.exp fails on all Windows-based
targets, and it now passes cleanly:
-FAIL: gdb.base/shreloc.exp: absolute symbols not relocated
+PASS: gdb.base/shreloc.exp: absolute symbols not relocated
Tested on:
x86_64-pc-linux-gnu
x86_64-pc-cygwin
x86_64-w64-mingw32
x86_64-pc-windows-msvc
Change-Id: I91b9882b6918cbd46dfdf1aa18f72cbbace70535
---
gdb/coffread.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 0a5da42e563..9f792edcd26 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -116,6 +116,13 @@ struct coff_reader
asection *
coff_reader::cs_to_bfd_section (struct coff_symbol *cs)
{
+ /* An absolute symbol (N_ABS) is not tied to any of the input file's
+ sections. Its value is a plain constant, so map it to BFD's
+ absolute section, so that callers treat it as absolute and, in
+ particular, do not relocate it. */
+ if (cs->c_secnum == N_ABS)
+ return bfd_abs_section_ptr;
+
for (asection *sect : gdb_bfd_sections (symfile_bfd))
if (sect->target_index == cs->c_secnum)
return sect;
@@ -469,14 +476,6 @@ coff_reader::symtab_read (minimal_symbol_reader &reader,
symbol lookup which returned no match. */
break;
}
- else if (cs->c_secnum == N_ABS)
- {
- /* Use the correct minimal symbol type (and don't
- relocate) for absolute values. */
- ms_type = mst_abs;
- sec = cs_to_section (cs);
- tmpaddr = cs->c_value;
- }
else
{
asection *bfd_section = cs_to_bfd_section (cs);
@@ -484,7 +483,13 @@ coff_reader::symtab_read (minimal_symbol_reader &reader,
sec = cs_to_section (cs);
tmpaddr = cs->c_value;
- if (bfd_section->flags & SEC_CODE)
+ if (bfd_is_abs_section (bfd_section))
+ {
+ /* Use the correct minimal symbol type (and don't
+ relocate) for absolute values. */
+ ms_type = mst_abs;
+ }
+ else if (bfd_section->flags & SEC_CODE)
{
ms_type =
cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 17/27] gdb.base/shreloc.exp: Test absolute symbols portably
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (15 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 16/27] gdb/coffread: Don't relocate absolute symbols Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 18/27] gdb: %p => host_address_to_string, target-section owner token Pedro Alves
` (9 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
gdb.base/shreloc.exp checks that an absolute symbol -- one whose value
is a plain constant, not tied to any section -- is not adjusted when
the library it lives in is relocated at load time. It does this by
looking at _minor_os_version__, an absolute symbol that GNU ld's PE
emulation injects into every image. That symbol only exists with GNU
ld, so the check is gated on cygwin/mingw and does not run anywhere
else.
Generalize the test by doing what the existing comment already
suggests: include an absolute symbol via the assembler instead.
This drops the last istarget check from the test, runs the
absolute-symbol check on every target rather than just cygwin/mingw,
and also covers windows-msvc, where _minor_os_version__ does not exist
(lld-link does not emit it).
While at it, convert the check to gdb_assert.
Change-Id: Ife2cc8f59d9e121661c125e08be21b221db860c9
---
gdb/testsuite/gdb.base/shreloc.exp | 20 ++++++------------
gdb/testsuite/gdb.base/shreloc.h | 33 ++++++++++++++++++++++++++++++
gdb/testsuite/gdb.base/shreloc1.c | 2 ++
gdb/testsuite/gdb.base/shreloc2.c | 2 ++
4 files changed, 43 insertions(+), 14 deletions(-)
create mode 100644 gdb/testsuite/gdb.base/shreloc.h
diff --git a/gdb/testsuite/gdb.base/shreloc.exp b/gdb/testsuite/gdb.base/shreloc.exp
index 718b1ca81ad..6c884f23fad 100644
--- a/gdb/testsuite/gdb.base/shreloc.exp
+++ b/gdb/testsuite/gdb.base/shreloc.exp
@@ -224,17 +224,9 @@ if {[send_gdb_discard "maint print msymbols ${msymfile}"]} {
}
}
-if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
- #
- # We know the names of some absolute symbols included in the
- # portable-executable (DLL) format. Check that they didn't get
- # relocated.
- #
- # A better approach would be include absolute symbols via the assembler.
- #
- if {[check_same "_minor_os_version__" "${msymfile}"]} {
- pass "absolute symbols not relocated"
- } else {
- fail "absolute symbols not relocated"
- }
-}
+# Both libraries define 'shreloc_abs_sym' as an absolute symbol with
+# the same value (see shreloc.h). An absolute symbol is not tied to a
+# section, so it must not be adjusted when the library is relocated.
+# Check that its value is reported the same for both libraries.
+gdb_assert {[check_same "shreloc_abs_sym" "${msymfile}"]} \
+ "absolute symbols not relocated"
diff --git a/gdb/testsuite/gdb.base/shreloc.h b/gdb/testsuite/gdb.base/shreloc.h
new file mode 100644
index 00000000000..cc283a85ce3
--- /dev/null
+++ b/gdb/testsuite/gdb.base/shreloc.h
@@ -0,0 +1,33 @@
+/* Copyright 2026 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 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, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GDB_TESTSUITE_GDB_BASE_SHRELOC_H
+#define GDB_TESTSUITE_GDB_BASE_SHRELOC_H
+
+/* An absolute symbol. Its value is a plain constant, not tied to any
+ section, so it must not be adjusted when the library is relocated
+ at load time. Included by both libraries so the test can confirm
+ that GDB reports the same value for both.
+
+ The name is emitted literally without the target's user-label
+ prefix (e.g. a leading '_' on some formats). The test greps for
+ the exact name, so it must be identical on every target. This is
+ OK because the symbol is never referenced from C. */
+asm (".globl shreloc_abs_sym\n\t"
+ "shreloc_abs_sym = 0x4000");
+
+#endif /* GDB_TESTSUITE_GDB_BASE_SHRELOC_H */
diff --git a/gdb/testsuite/gdb.base/shreloc1.c b/gdb/testsuite/gdb.base/shreloc1.c
index 6a228f85853..848ffaab4d4 100644
--- a/gdb/testsuite/gdb.base/shreloc1.c
+++ b/gdb/testsuite/gdb.base/shreloc1.c
@@ -1,3 +1,5 @@
+#include "shreloc.h"
+
#if defined(_WIN32) || defined(__CYGWIN__)
# define ATTRIBUTES __attribute((__dllexport__))
#else
diff --git a/gdb/testsuite/gdb.base/shreloc2.c b/gdb/testsuite/gdb.base/shreloc2.c
index 1a9b48bd13d..521c4094c80 100644
--- a/gdb/testsuite/gdb.base/shreloc2.c
+++ b/gdb/testsuite/gdb.base/shreloc2.c
@@ -1,3 +1,5 @@
+#include "shreloc.h"
+
#if defined(_WIN32) || defined(__CYGWIN__)
# define ATTRIBUTES __attribute((__dllexport__))
#else
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 18/27] gdb: %p => host_address_to_string, target-section owner token
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (16 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 17/27] gdb.base/shreloc.exp: Test absolute symbols portably Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 19/27] gdb: %p => host_address_to_string, dump_for_expression Pedro Alves
` (8 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
"maintenance info target-sections" prints an owner token for each
section, formatted with %p:
gdb_printf ("%*sStart: %s, End: %s, Owner token: %p\n", ...
The exact rendering of %p is implementation-defined. glibc prints it
with a leading "0x", but the MSVC C runtime prints it zero-padded and
with no "0x" prefix, e.g.:
Owner token: 000001833bd9bde0
gdb.base/maint-info-sections.exp expects a "0x"-prefixed value there,
so on windows-msvc the auxiliary-information line does not match and
the test fails:
FAIL: gdb.base/maint-info-sections.exp: with executable: maint info target-sections
Fix this by using host_address_to_string, which always renders a host
pointer with a "0x" prefix regardless of the C runtime, as GDB does
elsewhere for this reason.
Tested on x86_64-pc-linux-gnu and x86_64-pc-windows-msvc.
Change-Id: Ib9f081b65f02e2820783f87cfaffcff81e46e983
---
gdb/maint.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gdb/maint.c b/gdb/maint.c
index 1daa6ce1d2e..cbcdf59001b 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -522,11 +522,11 @@ maintenance_info_target_sections (const char *arg, int from_tty)
digits);
/* The magic '8 + digits' here ensures that the 'Start' is aligned
with the output of print_bfd_section_info. */
- gdb_printf ("%*sStart: %s, End: %s, Owner token: %p\n",
+ gdb_printf ("%*sStart: %s, End: %s, Owner token: %s\n",
(8 + digits), "",
hex_string_custom (sec.addr, addr_size),
hex_string_custom (sec.endaddr, addr_size),
- sec.owner.v ());
+ host_address_to_string (sec.owner.v ()));
}
}
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 19/27] gdb: %p => host_address_to_string, dump_for_expression
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (17 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 18/27] gdb: %p => host_address_to_string, target-section owner token Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 20/27] gdb: %p => host_address_to_string, find_symtab_matching_filename Pedro Alves
` (7 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
Use host_address_to_string in dump_for_expression, which always
renders a host pointer with a "0x" prefix regardless of the C runtime,
as GDB does elsewhere for this reason.
Tested on x86_64-pc-linux-gnu and x86_64-pc-windows-msvc.
Change-Id: Icd754e4b996c93adfd1a6cd67265ee3857762b30
---
gdb/expprint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gdb/expprint.c b/gdb/expprint.c
index e99430d2325..45bad7a516d 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -131,7 +131,8 @@ dump_for_expression (struct ui_file *stream, int depth,
void
dump_for_expression (struct ui_file *stream, int depth, const block *bl)
{
- gdb_printf (stream, _("%*sBlock: %p\n"), depth, "", bl);
+ gdb_printf (stream, _("%*sBlock: %s\n"), depth, "",
+ host_address_to_string (bl));
}
void
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 20/27] gdb: %p => host_address_to_string, find_symtab_matching_filename
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (18 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 19/27] gdb: %p => host_address_to_string, dump_for_expression Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 21/27] gdb: %p => host_address_to_string, handle_output_debug_string Pedro Alves
` (6 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
Use host_address_to_string in find_symtab_matching_filename, which
always renders a host pointer with a "0x" prefix regardless of the C
runtime, as GDB does elsewhere for this reason.
Tested on x86_64-pc-linux-gnu and x86_64-pc-windows-msvc.
Change-Id: Id9feccab986d62ebcff68afac065839b2c9bed1a
---
gdb/symfile-debug.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 2432a709ddf..25069a32f2a 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -282,8 +282,8 @@ objfile::find_symtab_matching_filename (const char *name,
break;
if (debug_symfile)
- gdb_printf (gdb_stdlog, "qf->find_symtab_matching_filename (...) = %p\n",
- result);
+ gdb_printf (gdb_stdlog, "qf->find_symtab_matching_filename (...) = %s\n",
+ host_address_to_string (result));
return result;
}
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 21/27] gdb: %p => host_address_to_string, handle_output_debug_string
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (19 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 20/27] gdb: %p => host_address_to_string, find_symtab_matching_filename Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 22/27] gdb.base/maint-info-sections.exp: Match exec file name with optional .exe Pedro Alves
` (5 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
Use host_address_to_string in
windows_per_inferior::handle_output_debug_string, which always renders
a host pointer with a "0x" prefix regardless of the C runtime, as GDB
does elsewhere for this reason.
Tested on x86_64-pc-linux-gnu and x86_64-pc-windows-msvc.
Change-Id: I4ff621443f5e3f313ed2e3efbc617d08fdb3eeaa
---
gdb/windows-nat.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index def8fa606f4..9b223912a82 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -871,8 +871,9 @@ windows_per_inferior::handle_output_debug_string
}
}
- DEBUG_EVENTS ("gdb: cygwin signal %d, thread 0x%x, CONTEXT @ %p",
- gotasig, thread_id, x);
+ DEBUG_EVENTS ("gdb: cygwin signal %d, thread 0x%x, CONTEXT @ %s",
+ gotasig, thread_id,
+ host_address_to_string (x));
}
#endif
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 22/27] gdb.base/maint-info-sections.exp: Match exec file name with optional .exe
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (20 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 21/27] gdb: %p => host_address_to_string, handle_output_debug_string Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 23/27] gdb.base/maint-info-sections.exp: Remove stale Windows DATA xfail Pedro Alves
` (4 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
Two tests of gdb.base/maint-info-sections.exp match a header line
against the expected binary name:
1. The "maint info sections" test matches the "Exec file:" header
with:
Exec file: .*${binfile}., file type...
where the trailing "." is meant to match the closing quote after
the file name.
2. The "maint info sections -all-objects" test matches the "Object
file:" header, expecting the closing quote immediately after
$binfile. Both assume the printed name is exactly $binfile.
But on a host where the executable has a ".exe" suffix that is not
part of $binfile, the printed name is "$binfile.exe", so neither
header matches: the single "." matches the dot instead of the quote,
and the "Object file:" quote does not line up at all. The tests then
fail, e.g., on x86_64-w64-mingw32:
FAIL: gdb.base/maint-info-sections.exp: maint info sections
FAIL: gdb.base/maint-info-sections.exp: maint info sections -all-objects
Fix this by allowing for an optional ".exe" between the file name and
the closing quote in both, matching the closing quote explicitly.
Tested on:
x86_64-pc-linux-gnu
x86_64-pc-cygwin
x86_64-w64-mingw32
x86_64-pc-windows-msvc
Change-Id: Icce62d69d8e23a8e859639a2e4a72c6f5c24ec0e
---
gdb/testsuite/gdb.base/maint-info-sections.exp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/gdb/testsuite/gdb.base/maint-info-sections.exp b/gdb/testsuite/gdb.base/maint-info-sections.exp
index ac712137cc6..3cc128c0ad3 100644
--- a/gdb/testsuite/gdb.base/maint-info-sections.exp
+++ b/gdb/testsuite/gdb.base/maint-info-sections.exp
@@ -123,19 +123,23 @@ gdb_test_multiple "maint info sections" "general output check" {
set text_section ".text"
set data_section ".data"
+# On some hosts the executable has a ".exe" suffix that is not part of
+# $binfile (e.g. a native Windows build), so allow for it between the
+# file name and the closing quote.
+set exec_re "Exec file: .*${binfile}(\\.exe)?', file type"
gdb_test_multiple "maint info sections" "" {
- -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" {
+ -re -wrap "${exec_re}.*ER_RO.*" {
# Looks like RealView which uses different section names.
set text_section ER_RO
set data_section ER_RW
pass "maint info sections"
}
- -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" {
+ -re -wrap "${exec_re}.*neardata.*" {
# c6x doesn't have .data section. It has .neardata and .fardata section.
set data_section ".neardata"
pass "maint info sections"
}
- -re -wrap "Exec file: .*${binfile}., file type.*" {
+ -re -wrap "${exec_re}.*" {
pass "maint info sections"
}
}
@@ -207,7 +211,7 @@ gdb_test_no_output "maint info sections" \
set seen_header false
set seen_a_section false
gdb_test_multiple "maint info sections -all-objects" "" {
- -re "Object file: `${binfile}', file type \[^.\]+\.\r\n" {
+ -re "Object file: `${binfile}(\\.exe)?', file type \[^.\]+\.\r\n" {
set seen_header true
exp_continue
}
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 23/27] gdb.base/maint-info-sections.exp: Remove stale Windows DATA xfail
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (21 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 22/27] gdb.base/maint-info-sections.exp: Match exec file name with optional .exe Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 24/27] gdb.base/solib-weak.exp: Skip on all PE/COFF targets Pedro Alves
` (3 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The "maint info sections DATA" test of
gdb.base/maint-info-sections.exp was marked XFAIL on cygwin and mingw,
on the grounds that Windows text sections were tagged DATA, so the
DATA filter would wrongly list the text section.
The Cygwin xfail dates back to commit dbdfa66c308 in 2005, the MinGW
one to commit 58e8570aabf ("gdb.base/maint.exp: XFAIL "maint info
sections DATA" on MinGW as well as Cygwin.") in 2011, and both moved
to this file unchanged in commit f4be677293a ("gdb/testsuite: split
'maint info sections' tests to a new file").
On current cygwin and mingw the text section is not reported as DATA,
the test passes, and the xfail turns into an XPASS:
XPASS: gdb.base/maint-info-sections.exp: maint info sections DATA
I have not tracked down exactly which change fixed this -- given the
xfail is roughly fifteen to twenty years old, it could be a change in
GDB, in BFD's PE section-flag handling, or in the toolchains that
produce the section flags in the first place.
It does not really matter for this test IMHO: what it checks is GDB's
report of the current binary's section flags, and on the toolchains
anyone is realistically testing with today that report is correct, as
the XPASS shows.
A stale xfail that always XPASSes is just noise, so I'd rather remove
it and let the test report a plain PASS. If it turns out this still
fails on a modern toolchain, we can add the xfail back with some more
targeted check, based on toolchain version or some such.
Tested on:
x86_64-pc-linux-gnu
x86_64-pc-cygwin
x86_64-w64-mingw32
x86_64-pc-windows-msvc
Change-Id: Ia64c4297fb219058353fb9d88913f89cca2cd68b
---
gdb/testsuite/gdb.base/maint-info-sections.exp | 6 ------
1 file changed, 6 deletions(-)
diff --git a/gdb/testsuite/gdb.base/maint-info-sections.exp b/gdb/testsuite/gdb.base/maint-info-sections.exp
index 3cc128c0ad3..0bb15246d52 100644
--- a/gdb/testsuite/gdb.base/maint-info-sections.exp
+++ b/gdb/testsuite/gdb.base/maint-info-sections.exp
@@ -173,12 +173,6 @@ gdb_test_multiple "maint info sections CODE" "" {
# Test for new option: DATA section flag
# If your text section is tagged DATA, xfail this test.
-#
-# The "maint info sections DATA" test is marked for XFAIL on Windows,
-# because Windows has text sections marked DATA.
-setup_xfail "*-*-*cygwin*"
-setup_xfail "*-*-*mingw*"
-
gdb_test_multiple "maint info sections DATA" "" {
-re -wrap " $text_section .*" {
fail $gdb_test_name
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 24/27] gdb.base/solib-weak.exp: Skip on all PE/COFF targets
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (22 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 23/27] gdb.base/maint-info-sections.exp: Remove stale Windows DATA xfail Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 25/27] gdb.server/wrapper.exp: Skip on all Windows targets Pedro Alves
` (2 subsequent siblings)
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The gdb.base/solib-weak.exp testcase sets a breakpoint on a function
that two shared libraries both provide, where one library defines it
as a weak symbol and the other as a strong symbol, and checks that GDB
picks the right copy. This relies on a weak symbol in one shared
library being overridden by a strong symbol of the same name in
another, resolved at load time, which is an ELF dynamic-linking
behavior.
The test was already skipped on mingw, cygwin and pe, since that
override does not happen on Windows: PE/COFF resolves symbols at link
time, per module, so a weak symbol in one DLL is not overridden by a
strong one in another DLL. GCC on mingw does accept
__attribute__((weak)) and binutils does emit PE weak externals, but
those are a link-time, single-module alias-with-fallback mechanism,
not the cross-DLL runtime override the test exercises, so the test
fails there.
The existing early return open-codes mingw/cygwin/pe and so did not
cover windows-msvc, whose triplet is
{x86_64,aarch64,i686}-pc-windows-msvc. Use is_pecoff_target instead,
which covers windows-msvc too, and reword the comment to say why the
test does not apply rather than just that "weak symbols are not
meaningful".
Confirmed the test still fails on windows-msvc before this change.
Tested on:
x86_64-pc-linux-gnu
x86_64-pc-cygwin
x86_64-w64-mingw32
x86_64-pc-windows-msvc
Change-Id: I5b12784d32ecd6b0595d721e28bd10a61a9f1901
---
gdb/testsuite/gdb.base/solib-weak.exp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/gdb/testsuite/gdb.base/solib-weak.exp b/gdb/testsuite/gdb.base/solib-weak.exp
index 319100e4a55..21449061e14 100644
--- a/gdb/testsuite/gdb.base/solib-weak.exp
+++ b/gdb/testsuite/gdb.base/solib-weak.exp
@@ -19,12 +19,13 @@
require allow_shlib_tests
-# These targets have shared libraries, but weak symbols are not meaningful.
-if {([istarget *-*-mingw*]
- || [istarget *-*-cygwin*]
- || [istarget *-*-pe*])} {
- return
-}
+# This test relies on a weak symbol in one shared library being
+# overridden by a strong symbol of the same name in another, resolved
+# at load time. That is an ELF dynamic-linking behavior. PE/COFF
+# resolves symbols at link time, per module, so a weak symbol in one
+# DLL is not overridden by a strong one in another DLL -- the scenario
+# this test exercises does not exist there.
+require !is_pecoff_target
# This test uses GCC-specific syntax.
if {![test_compiler_info "gcc-*"]} {
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 25/27] gdb.server/wrapper.exp: Skip on all Windows targets
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (23 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 24/27] gdb.base/solib-weak.exp: Skip on all PE/COFF targets Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 26/27] gdb/testsuite: Factor out dlopen/LoadLibrary shim into lib/gdb-dlfcn.h Pedro Alves
2026-07-23 13:01 ` [PATCH 27/27] gdb/testsuite/lib/gdb-dlfcn.h: __WIN32__ => _WIN32 Pedro Alves
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
The gdb.server/wrapper.exp testcase exercises GDBserver's --wrapper
option, which GDBserver does not support on Windows (PR server/15967),
so the testcase is skipped there. The skip open-codes mingw and
cygwin though, and so does not cover windows-msvc, whose triplet is
x86_64-pc-windows-msvc. Use is_windows_based_target instead, which
covers all three.
Tested on:
x86_64-pc-linux-gnu
x86_64-pc-cygwin
x86_64-w64-mingw32
x86_64-pc-windows-msvc
Change-Id: I5031816740d94bad1ecc9c0d309386922789c571
---
gdb/testsuite/gdb.server/wrapper.exp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.server/wrapper.exp b/gdb/testsuite/gdb.server/wrapper.exp
index 40c29c441fa..c870576f800 100644
--- a/gdb/testsuite/gdb.server/wrapper.exp
+++ b/gdb/testsuite/gdb.server/wrapper.exp
@@ -23,8 +23,7 @@ standard_testfile
require allow_gdbserver_tests
-if { [istarget *-*-mingw*]
- || [istarget *-*-cygwin*] } {
+if { [is_windows_based_target] } {
unsupported "gdbserver does not support --wrapper on this target (PR server/15967)"
return
}
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 26/27] gdb/testsuite: Factor out dlopen/LoadLibrary shim into lib/gdb-dlfcn.h
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (24 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 25/27] gdb.server/wrapper.exp: Skip on all Windows targets Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
2026-07-23 13:01 ` [PATCH 27/27] gdb/testsuite/lib/gdb-dlfcn.h: __WIN32__ => _WIN32 Pedro Alves
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
Several testcases that dlopen a shared library at runtime have a set
of similar preprocessor shims that map the POSIX
dlopen/dlsym/dlclose/dlerror interfaces onto the equivalent Win32
functions on Windows.
This commit moves the shims into a new testsuite/lib/gdb-dlfcn.h, and
includes it from each testcase. gdb_compile already adds
testsuite/lib/ to the include path, so no .exp changes are needed.
The header provides a small static gdb_dlerror() for the Windows side,
formatting GetLastError() the way watchpoint-solib.c and unload.c used
to do inline, so those two lose their in-body __WIN32__ blocks too and
just call dlerror() unconditionally.
TEXT() is dropped: it only matters for the WinCE wide-char build
(_WIN32_WCE), and we dropped WinCE support long ago.
This will make the following patch trivial.
Change-Id: I7618808a3c766ae5570358f6e0bfb9ceabf4f4c0
---
gdb/testsuite/gdb.base/bp-disabled-by-cond.c | 13 +----
gdb/testsuite/gdb.base/catch-load.c | 8 +--
.../gdb.base/corefile-buildid-shlib.c | 10 +---
gdb/testsuite/gdb.base/jit-unload.c | 9 +---
gdb/testsuite/gdb.base/shlib-unload.c | 13 +----
gdb/testsuite/gdb.base/solib-disc.c | 10 +---
gdb/testsuite/gdb.base/unload.c | 21 +-------
gdb/testsuite/gdb.base/watchpoint-solib.c | 17 +------
gdb/testsuite/gdb.mi/mi-catch-load.c | 8 +--
gdb/testsuite/gdb.mi/mi-dprintf-modified.c | 13 +----
gdb/testsuite/gdb.perf/solib.c | 9 +---
gdb/testsuite/gdb.python/py-event-load.c | 8 +--
gdb/testsuite/lib/gdb-dlfcn.h | 51 +++++++++++++++++++
13 files changed, 63 insertions(+), 127 deletions(-)
create mode 100644 gdb/testsuite/lib/gdb-dlfcn.h
diff --git a/gdb/testsuite/gdb.base/bp-disabled-by-cond.c b/gdb/testsuite/gdb.base/bp-disabled-by-cond.c
index 0d147b34410..f09f90b43a6 100644
--- a/gdb/testsuite/gdb.base/bp-disabled-by-cond.c
+++ b/gdb/testsuite/gdb.base/bp-disabled-by-cond.c
@@ -18,18 +18,7 @@
#include <assert.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#ifdef _WIN32_WCE
-# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
-#else
-# define dlsym(handle, func) GetProcAddress (handle, func)
-#endif
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
void
breakpt ()
diff --git a/gdb/testsuite/gdb.base/catch-load.c b/gdb/testsuite/gdb.base/catch-load.c
index bb53fddc557..e9f8f63362d 100644
--- a/gdb/testsuite/gdb.base/catch-load.c
+++ b/gdb/testsuite/gdb.base/catch-load.c
@@ -17,13 +17,7 @@
#include <stdio.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
/* This is updated by the .exp file. */
char *libname = "catch-load-so.so";
diff --git a/gdb/testsuite/gdb.base/corefile-buildid-shlib.c b/gdb/testsuite/gdb.base/corefile-buildid-shlib.c
index 480494d98f7..dca51bc6749 100644
--- a/gdb/testsuite/gdb.base/corefile-buildid-shlib.c
+++ b/gdb/testsuite/gdb.base/corefile-buildid-shlib.c
@@ -19,15 +19,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (name)
-#define dlsym(handle, func) GetProcAddress (handle, func)
-#define dlclose(handle) FreeLibrary (handle)
-#define dlerror() "an error occurred"
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
const char *the_shlib = SHLIB_NAME;
diff --git a/gdb/testsuite/gdb.base/jit-unload.c b/gdb/testsuite/gdb.base/jit-unload.c
index 058fb54fd71..e10ba221314 100644
--- a/gdb/testsuite/gdb.base/jit-unload.c
+++ b/gdb/testsuite/gdb.base/jit-unload.c
@@ -20,14 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#define dlclose(handle) FreeLibrary (handle)
-#define dlerror() "an error occurred"
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
int
diff --git a/gdb/testsuite/gdb.base/shlib-unload.c b/gdb/testsuite/gdb.base/shlib-unload.c
index e2c2051a19f..6332945b690 100644
--- a/gdb/testsuite/gdb.base/shlib-unload.c
+++ b/gdb/testsuite/gdb.base/shlib-unload.c
@@ -17,18 +17,7 @@
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#ifdef _WIN32_WCE
-# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
-#else
-# define dlsym(handle, func) GetProcAddress (handle, func)
-#endif
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
#include <assert.h>
diff --git a/gdb/testsuite/gdb.base/solib-disc.c b/gdb/testsuite/gdb.base/solib-disc.c
index 9230ab13c67..365e352f579 100644
--- a/gdb/testsuite/gdb.base/solib-disc.c
+++ b/gdb/testsuite/gdb.base/solib-disc.c
@@ -18,15 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (name)
-#define dlsym(handle, func) GetProcAddress (handle, func)
-#define dlclose(handle) FreeLibrary (handle)
-#define dlerror() "an error occurred"
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
int main()
{
diff --git a/gdb/testsuite/gdb.base/unload.c b/gdb/testsuite/gdb.base/unload.c
index 7c365aef9ef..98451a43a27 100644
--- a/gdb/testsuite/gdb.base/unload.c
+++ b/gdb/testsuite/gdb.base/unload.c
@@ -18,18 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#ifdef _WIN32_WCE
-# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
-#else
-# define dlsym(handle, func) GetProcAddress (handle, func)
-#endif
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
int k = 0;
@@ -52,11 +41,7 @@ int main()
if (!unloadshr)
{
-#ifdef __WIN32__
- fprintf (stderr, "error %d occurred\n", GetLastError ());
-#else
fprintf (stderr, "%s\n", dlerror ());
-#endif
exit (1);
}
@@ -79,11 +64,7 @@ int main()
if (!unloadshr)
{
-#ifdef __WIN32__
- fprintf (stderr, "error %d occurred\n", GetLastError ());
-#else
fprintf (stderr, "%s\n", dlerror ());
-#endif
exit (1);
}
diff --git a/gdb/testsuite/gdb.base/watchpoint-solib.c b/gdb/testsuite/gdb.base/watchpoint-solib.c
index 79a9e91c642..0e4732f8325 100644
--- a/gdb/testsuite/gdb.base/watchpoint-solib.c
+++ b/gdb/testsuite/gdb.base/watchpoint-solib.c
@@ -18,18 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#ifdef _WIN32_WCE
-# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
-#else
-# define dlsym(handle, func) GetProcAddress (handle, func)
-#endif
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
void open_shlib ()
@@ -41,11 +30,7 @@ void open_shlib ()
if (!handle)
{
-#ifdef __WIN32__
- fprintf (stderr, "error %d occurred\n", GetLastError ());
-#else
fprintf (stderr, "%s\n", dlerror ());
-#endif
exit (1);
}
diff --git a/gdb/testsuite/gdb.mi/mi-catch-load.c b/gdb/testsuite/gdb.mi/mi-catch-load.c
index 0808d9fa759..bad7f79a37b 100644
--- a/gdb/testsuite/gdb.mi/mi-catch-load.c
+++ b/gdb/testsuite/gdb.mi/mi-catch-load.c
@@ -17,13 +17,7 @@
#include <stdio.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
char *libname = "mi-catch-load-so.so";
diff --git a/gdb/testsuite/gdb.mi/mi-dprintf-modified.c b/gdb/testsuite/gdb.mi/mi-dprintf-modified.c
index 03b88712bfc..af8ca6c5940 100644
--- a/gdb/testsuite/gdb.mi/mi-dprintf-modified.c
+++ b/gdb/testsuite/gdb.mi/mi-dprintf-modified.c
@@ -17,18 +17,7 @@
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#ifdef _WIN32_WCE
-# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
-#else
-# define dlsym(handle, func) GetProcAddress (handle, func)
-#endif
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
#include <assert.h>
diff --git a/gdb/testsuite/gdb.perf/solib.c b/gdb/testsuite/gdb.perf/solib.c
index 372330b50a7..c4be9e9b46e 100644
--- a/gdb/testsuite/gdb.perf/solib.c
+++ b/gdb/testsuite/gdb.perf/solib.c
@@ -18,14 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-# define dlsym(handle, func) GetProcAddress (handle, func)
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
static void **handles;
diff --git a/gdb/testsuite/gdb.python/py-event-load.c b/gdb/testsuite/gdb.python/py-event-load.c
index 1ab5bf832e9..e4887e1a056 100644
--- a/gdb/testsuite/gdb.python/py-event-load.c
+++ b/gdb/testsuite/gdb.python/py-event-load.c
@@ -17,13 +17,7 @@
#include <unistd.h>
-#ifdef __WIN32__
-#include <windows.h>
-#define dlopen(name, mode) LoadLibrary (TEXT (name))
-#define dlclose(handle) FreeLibrary (handle)
-#else
-#include <dlfcn.h>
-#endif
+#include "gdb-dlfcn.h"
/* This is updated by the .exp file. */
char *libname = "py-events-shlib.so";
diff --git a/gdb/testsuite/lib/gdb-dlfcn.h b/gdb/testsuite/lib/gdb-dlfcn.h
new file mode 100644
index 00000000000..02cd6141b2c
--- /dev/null
+++ b/gdb/testsuite/lib/gdb-dlfcn.h
@@ -0,0 +1,51 @@
+/* This file is part of GDB, the GNU debugger.
+
+ Copyright 2026 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ 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, see <http://www.gnu.org/licenses/>. */
+
+/* Provide the POSIX dlopen/dlsym/dlclose/dlerror interface for test
+ programs that load a shared library at runtime, mapping it to the
+ Win32 loader API on Windows. */
+
+#ifndef GDB_DLFCN_H
+#define GDB_DLFCN_H
+
+#ifdef __WIN32__
+
+#include <windows.h>
+#include <stdio.h>
+
+#define dlopen(name, mode) LoadLibrary (name)
+#define dlsym(handle, func) GetProcAddress (handle, func)
+#define dlclose(handle) FreeLibrary (handle)
+#define dlerror() gdb_dlerror ()
+
+static char _gdb_dlerror_buf[64];
+
+static const char *
+gdb_dlerror (void)
+{
+ snprintf (_gdb_dlerror_buf, sizeof (_gdb_dlerror_buf),
+ "error %lu occurred", (unsigned long) GetLastError ());
+ return _gdb_dlerror_buf;
+}
+
+#else /* POSIX systems */
+
+#include <dlfcn.h>
+
+#endif
+
+#endif /* GDB_DLFCN_H */
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 27/27] gdb/testsuite/lib/gdb-dlfcn.h: __WIN32__ => _WIN32
2026-07-23 13:00 [PATCH 00/27] Teach the testsuite about the Windows/MSVC target Pedro Alves
` (25 preceding siblings ...)
2026-07-23 13:01 ` [PATCH 26/27] gdb/testsuite: Factor out dlopen/LoadLibrary shim into lib/gdb-dlfcn.h Pedro Alves
@ 2026-07-23 13:01 ` Pedro Alves
26 siblings, 0 replies; 28+ messages in thread
From: Pedro Alves @ 2026-07-23 13:01 UTC (permalink / raw)
To: gdb-patches
testsuite/lib/gdb-dlfcn.h guards the Windows branch with __WIN32__,
which is a GCC/MinGW-ism. __WIN32__ is not defined by MSVC nor by
Clang targeting *-windows-msvc, so when testing with (e.g.)
--target=x86_64-pc-windows-msvc gdb-dlfcn.h takes the <dlfcn.h> branch
and we fail to build the testcase that included it.
Fix this by using _WIN32 instead, which is defined on every (native)
Windows toolchain (and not by Cygwin).
There are no other references to __WIN32__ in the testsuite.
Tested by running the affected testcases on:
x86_64-pc-linux-gnu
x86_64-pc-cygwin
x86_64-w64-mingw32
x86_64-pc-windows-msvc
Change-Id: Iacb54478519231e81fada2d55fec80a0831ab6d3
---
gdb/testsuite/lib/gdb-dlfcn.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/lib/gdb-dlfcn.h b/gdb/testsuite/lib/gdb-dlfcn.h
index 02cd6141b2c..66b6816db6a 100644
--- a/gdb/testsuite/lib/gdb-dlfcn.h
+++ b/gdb/testsuite/lib/gdb-dlfcn.h
@@ -22,7 +22,7 @@
#ifndef GDB_DLFCN_H
#define GDB_DLFCN_H
-#ifdef __WIN32__
+#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
--
2.54.0
^ permalink raw reply [flat|nested] 28+ messages in thread