From: Craig Blackmore <craig.blackmore@embecosm.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Cc: Simon Cook <simon.cook@embecosm.com>
Subject: Re: [PATCH] Add missing null pointer check in get_sal_arch
Date: Fri, 21 Aug 2026 11:09:56 +0100 [thread overview]
Message-ID: <036b0f35-b8a4-40bb-ac57-42cb44628abc@embecosm.com> (raw)
In-Reply-To: <87ldarmfgy.fsf@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 6313 bytes --]
Hi Andrew,
Thanks for the reviews.
On 31/07/2026 14:54, Andrew Burgess wrote:
> Isn't a test with a custom linker script, especially one that's placing
> text sections going to be architecture specific? I would have expected
> this to be a gdb.arch/ test?
I have moved the test to gdb.arch.
> If this does work more widely then maybe a list of the targets it has
> been confirmed to work on would be good.
I have updated the test to work more widely and so far confirmed it
works on arm, riscv and x86_64. The patch below contains the updated
test only - I will discuss how to proceed with the fix in my next reply.
The test is now linked with -nostdlib to avoid linking library code that
references specific symbols that would usually be defined in the linker
script. I have updated the linker script to ensure there are three LOAD
segments, as at least three are needed to reproduce the issue.
I have also included the cleanups suggested by you and Tom de Vries and
fixed the strangely defined memory regions in the linker script.
> You can push a `try` branch to sourceware into your username namespace,
> e.g. I could push to 'aburgess/try-my-awesome-fix' and the sourceware CI
> will spot this branch, run its tests, and email you the results. The
> key is the 'try-' part of the branch name. Though thinking about it,
> I'm not sure if it runs all tests, or just a subset, I guess you'd have
> to "try" it and find out.
I would like to try this but I don't have gdb write permission. I know I
need to send an email to admin-requests. Would you be willing to approve
me having write after approval access please?
Thanks,
Craig
---
commit 00c611b0c754a03c426af0e8476ee1e9347919e3
Author: Craig Blackmore<craig.blackmore@embecosm.com>
Date: Thu Aug 20 16:47:52 2026 +0100
[WIP] Updated testcase
This is the test case only. It does not include either fix.
diff --git a/gdb/testsuite/gdb.arch/bp-non-alloc.c b/gdb/testsuite/gdb.arch/bp-non-alloc.c
new file mode 100644
index 00000000000..2eb9f523887
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/bp-non-alloc.c
@@ -0,0 +1,21 @@
+/* Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 main ()
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/bp-non-alloc.exp b/gdb/testsuite/gdb.arch/bp-non-alloc.exp
new file mode 100644
index 00000000000..79f29dbb1da
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/bp-non-alloc.exp
@@ -0,0 +1,40 @@
+# Copyright (C) 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/>.
+
+# Test that a breakpoint can be set on a function in an ELF file that has all
+# of the following properties:
+# 1. There is no section called ".text"
+# 2. The first section is non-allocatable
+# 3. There are three LOAD segments
+# This previously caused GDB to segfault due to attempting to dereference a null
+# objfile within a sal section.
+
+# This test has a custom linker script so may not work on all targets. It has
+# been confirmed to work on arm-none-eabi, riscv64-unknown-elf and
+# x64_64-linux-gnu.
+require {is_any_target "arm*-*-*" "riscv*-*-*" "x86_64*-*-*"} is_elf_target
+
+standard_testfile
+
+set linker_script $srcdir/$subdir/$testfile.ld
+
+set options "debug ldscript=-Wl,-T${linker_script} ldflags=-nostdlib"
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options]} {
+ return
+}
+
+# The executable does not support actually running, so we do not run to main
+# here.
+gdb_breakpoint main -message
diff --git a/gdb/testsuite/gdb.arch/bp-non-alloc.ld b/gdb/testsuite/gdb.arch/bp-non-alloc.ld
new file mode 100644
index 00000000000..73801e9f865
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/bp-non-alloc.ld
@@ -0,0 +1,42 @@
+/* Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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/>.
+
+ This linker script is used to produce an executable that starts with a
+ non-allocatable section, does not contain a `.text` section and has three
+ LOAD segments. */
+
+MEMORY
+{
+ TEXT (rx) : ORIGIN = 0x80000000, LENGTH = 0x10000
+ DATA (rw) : ORIGIN = 0x80010000, LENGTH = 0x10000
+}
+
+PHDRS
+{
+ text PT_LOAD ;
+ data1 PT_LOAD ;
+ data2 PT_LOAD ;
+}
+
+SECTIONS
+{
+ . = SIZEOF_HEADERS;
+ .my_non_alloc_sec (INFO) : { . = . + 0x10; }
+ .text.all : { *(.text) } > TEXT :text
+ .data : { *(.data) } > DATA :data1
+ .bss : { *(.bss) } > DATA :data2
+}
[-- Attachment #2: Type: text/html, Size: 7420 bytes --]
next prev parent reply other threads:[~2026-08-21 10:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 15:06 Craig Blackmore
2026-07-31 13:27 ` Tom de Vries
2026-08-21 9:51 ` Craig Blackmore
2026-07-31 13:54 ` Andrew Burgess
2026-08-21 10:09 ` Craig Blackmore [this message]
2026-07-31 14:31 ` Andrew Burgess
2026-07-31 15:27 ` Andrew Burgess
2026-08-21 10:25 ` Craig Blackmore
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=036b0f35-b8a4-40bb-ac57-42cb44628abc@embecosm.com \
--to=craig.blackmore@embecosm.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.cook@embecosm.com \
/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