[PATCH 14/27] gdb/testsuite: Support text_segment on windows-msvc via /BASE
Pedro Alves <[email protected]> Thu, 23 Jul 2026 14:01:05 +0100
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
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