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
+}