From: Keith Seitz <keiths@redhat.com>
To: Dragorn421 <dragorn421@gmail.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v3 2/2] `add-symbol-file`: add test for mixing -o and -s
Date: Thu, 24 Sep 2026 11:57:28 -0700 [thread overview]
Message-ID: <f032e180-fe15-4441-9bf4-cf8467ddba0f@redhat.com> (raw)
In-Reply-To: <20260924035202.4533-3-dragorn421@gmail.com>
Hi,
Thank you for the test case! See my comments below.
On 9/23/26 8:51 PM, Dragorn421 wrote:
> 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..64c25dfab7b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/relocate_linked.exp
> @@ -0,0 +1,58 @@
> +# 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/>. */
> +
> +# 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
> +}
> +if { [target_link "${binfile}.o" "${binfile}.plf" --relocatable] != "" } {
> + untested "failed to partially link"
> + return
> +}
> +
Unfortunately, using target_link is problematic. It invokes bare ld
while ignoring build flags such as -m32. When running the test suite
in 32-bit mode:
$ make check RUNTESTFLAGS="--target_board unix/-m32"
TESTS=gdb.base/relocate_linked.exp
...
ld: relocatable linking with relocations from format elf32-i386
(...) to format elf64-x86-64 (...) is not supported
UNTESTED: gdb.base/relocate_linked.exp: failed to partially link
It would be better to drive this through gdb_compile so that any
target multilib flags are applied. Unfortunately, this gets a little
complicated because of linking with the math library. I think it best
to follow gdb.base/nostdlib.exp. Something like this on top of your
patch seems a safer (and broader) approach:
diff --git a/gdb/testsuite/gdb.base/relocate_linked.exp
b/gdb/testsuite/gdb.base/relocate_linked.exp
index 64c25dfab7b..69d715c86eb 100644
--- a/gdb/testsuite/gdb.base/relocate_linked.exp
+++ b/gdb/testsuite/gdb.base/relocate_linked.exp
@@ -24,7 +24,21 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}"
"${binfile}.o" object {debug}
untested "failed to compile"
return
}
-if { [target_link "${binfile}.o" "${binfile}.plf" --relocatable] != "" } {
+
+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
}
[I just copied that from nostdlib.exp.]
> +# 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"
> + pass $gdb_test_name
> + }
> +}
This final 'pass' emits a misleading PASS. On an unpatched gdb, for
example, we will mark both a FAIL and a PASS. gdb_assert will issue
PASS/FAIL messages on its own, so I don't think this "pass
$gdb_test_name" is needed.
Keith
prev parent reply other threads:[~2026-09-24 18:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 3:51 [PATCH v3 0/2] Fix `add-symbol-file -o ... -s ...` address mapping bug Dragorn421
2026-09-24 3:51 ` [PATCH v3 1/2] " Dragorn421
2026-09-24 18:54 ` Keith Seitz
2026-09-25 7:15 ` Dragorn421
2026-09-25 17:06 ` Keith Seitz
2026-09-24 3:51 ` [PATCH v3 2/2] `add-symbol-file`: add test for mixing -o and -s Dragorn421
2026-09-24 18:57 ` Keith Seitz [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=f032e180-fe15-4441-9bf4-cf8467ddba0f@redhat.com \
--to=keiths@redhat.com \
--cc=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