[PATCH 01/27] gdb/testsuite: Don't link with -lm on windows-msvc
Pedro Alves <[email protected]> Thu, 23 Jul 2026 14:00:52 +0100
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
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