Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Dragorn421 <dragorn421@gmail.com>
To: gdb-patches@sourceware.org
Cc: Dragorn421 <dragorn421@gmail.com>
Subject: [PATCH v4 2/2] `add-symbol-file`: add test for mixing -o and -s
Date: Sat, 26 Sep 2026 08:47:24 +0200	[thread overview]
Message-ID: <20260926064742.29327-3-dragorn421@gmail.com> (raw)
In-Reply-To: <20260926064742.29327-1-dragorn421@gmail.com>

The test makes use of a built .plf (partially linked file) file,
which is needed to exhibit the previously fixed bug, as unlinked
.o object files only have 0 as address for their sections.
---
 gdb/testsuite/gdb.base/relocate_linked.c   | 28 +++++++++
 gdb/testsuite/gdb.base/relocate_linked.exp | 71 ++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/relocate_linked.c
 create mode 100644 gdb/testsuite/gdb.base/relocate_linked.exp

diff --git a/gdb/testsuite/gdb.base/relocate_linked.c b/gdb/testsuite/gdb.base/relocate_linked.c
new file mode 100644
index 00000000000..ac48ea28dc0
--- /dev/null
+++ b/gdb/testsuite/gdb.base/relocate_linked.c
@@ -0,0 +1,28 @@
+/* This testcase 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/>.  */
+
+int
+text ()
+{
+  return 0;
+}
+
+int data = 1;
+
+const int rodata = 2;
+
+int bss;
diff --git a/gdb/testsuite/gdb.base/relocate_linked.exp b/gdb/testsuite/gdb.base/relocate_linked.exp
new file mode 100644
index 00000000000..6759ef04746
--- /dev/null
+++ b/gdb/testsuite/gdb.base/relocate_linked.exp
@@ -0,0 +1,71 @@
+# Copyright 2010-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/>.  */
+
+# relocate_linked.exp -- Expect script to test loading symbols from linked
+#		  relocatable object files (also known as partially linked files).
+
+standard_testfile .c
+
+# plf stands for "partially linked file"
+remote_exec build "rm -f ${binfile}.o ${binfile}.plf"
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}.o" object {debug}] != "" } {
+    untested "failed to compile"
+    return
+}
+
+set board [target_info name]
+if {[board_info $board exists mathlib]} {
+    set saved_mathlib [board_info $board mathlib]
+    set_board_info mathlib ""
+    set err [gdb_compile "${binfile}.o" "${binfile}.plf" executable \
+		 {additional_flags=-nostdlib ldflags=-Wl,-r}]
+    set_board_info mathlib $saved_mathlib
+} else {
+    set_board_info mathlib ""
+    set err [gdb_compile "${binfile}.o" "${binfile}.plf" executable \
+		 {additional_flags=-nostdlib ldflags=-Wl,-r}]
+    unset_board_info mathlib
+}
+if { $err != "" } {
+    untested "failed to partially link"
+    return
+}
+
+# Check that the -s address is respected when -o is used.
+clean_restart
+set offset 0xff000000
+set offset_re 0x0*ff000000
+set data 0x12340
+set data_re 0x0*12340
+set saw_data_section_with_correct_address 0
+gdb_test_multiple "add-symbol-file $binfile.plf -o $offset -s .data $data" \
+    "add-symbol-file with offset and explicit data section address" {
+    -re "add symbol table from file .*${testfile}\\.plf.*at\[ \\t\\r\\n\]+\\.data_addr = ${data_re}\[\\r\\n\]+with other sections offset by ${offset_re}\[\\r\\n\]+\\(y or n\\) " {
+	send_gdb "y\n"
+	exp_continue
+    }
+    -re "Reading symbols from .*\\.\\.\\.\\r\\n$gdb_prompt " {
+	send_gdb "maint info sections -all-objects\n"
+	exp_continue
+    }
+    -re "$data_re->$hex .*: \\.data" {
+	set saw_data_section_with_correct_address 1
+	exp_continue
+    }
+    -re -wrap "" {
+	gdb_assert { $saw_data_section_with_correct_address } \
+	    "explicit .data section address is preserved"
+    }
+}
-- 
2.43.0


      parent reply	other threads:[~2026-09-26  6:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26  6:47 [PATCH v4 0/2] Fix `add-symbol-file -o ... -s ...` address mapping bug Dragorn421
2026-09-26  6:47 ` [PATCH v4 1/2] " Dragorn421
2026-09-26  6:47 ` Dragorn421 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260926064742.29327-3-dragorn421@gmail.com \
    --to=dragorn421@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox