[PATCH 13/27] gdb/testsuite: Skip -Ttext-segment on PE

Pedro Alves <[email protected]> Thu, 23 Jul 2026 14:01:04 +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 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