[PATCH v2 0/1] bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct elf_prstatus size
lijian1@kylinos.cn
lijian1@kylinos.cn
Tue Oct 28 13:52:50 GMT 2025
From: lijian1 <lijian1@kylinos.cn>
In-Reply-To: <20251022062230.3053-1-lijian1@kylinos.cn>
Supersedes: <20251022062230.3053-1-lijian1@kylinos.cn>
Hi all,this cover patch contains the problem analysis.
The problem I met is:
I generate a corefile by crash-gcore-command(a third-party tool to generate corefile in crash context), while the note section likes this:
[root@localhost 127.0.0.1-2025-10-20-15:29:30]# readelf -n core.3925.bash
Displaying notes found at file offset 0x000005f0 with length 0x000007c0:
所有者 Data size Description
CORE 0x000001e0 NT_PRSTATUS (prstatus 结构)
CORE 0x00000088 NT_PRPSINFO (prpsinfo 结构)
CORE 0x00000150 NT_AUXV (auxiliary vector)
CORE 0x000003b6 NT_FILE (mapped files)
Cannot decode 64-bit note in 32-bit build
Notice that the NT_PRSTATUS part has the size of 480bytes(0x1e0) with the kernel value and distro.
During the deal process for gdb to translate the note prstatus part to .reg section.
With the debug command like this: "gdb -q -ex "file gdb" -nx -ex "break core_target_open" -ex "break loongarch_elf_grok_prstatus" -ex "break _bfd_elfcore_make_pseudosection" -ex "run -nx -ex 'file /bin/bash' -ex 'set pagination off' -ex 'set debug arch 1' -ex 'core-file core.3925.bash' -ex '-d /root/code/gdb/binutils-gdb'""
Thread 1 "gdb" hit Breakpoint 2.1, loongarch_elf_grok_prstatus (abfd=0x55555649b7e0, note=0x7ffffffd25a8) at ../../bfd/elfnn-loongarch.c:4515
4515 switch (note->descsz)
(gdb) p note->descsz
$1 = 480
at this point, the size doesn't match for the loongarch64 macro definition(#define PRSTATUS_SIZE 0x1d8), then as the control flow defined:
static bool
loongarch_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
{
switch (note->descsz)
{
default:
/*hit this branch*/
return false;
/* The sizeof (struct elf_prstatus) on Linux/LoongArch. */
case PRSTATUS_SIZE:
/* pr_cursig */
elf_tdata (abfd)->core->signal =
bfd_get_16 (abfd, note->descdata + PRSTATUS_OFFSET_PR_CURSIG);
/* pr_pid */
elf_tdata (abfd)->core->lwpid =
bfd_get_32 (abfd, note->descdata + PRSTATUS_OFFSET_PR_PID);
break;
}
/* Make a ".reg/999" section. */
return _bfd_elfcore_make_pseudosection (abfd, ".reg", ELF_GREGSET_T_SIZE,
note->descpos
+ PRSTATUS_OFFSET_PR_REG);
}
As the definition for elf_backend_grok_prstatus in elfnn-loongarch.c
#define elf_backend_grok_prstatus loongarch_elf_grok_prstatus
Thread 1 "gdb" hit Breakpoint 3, _bfd_elfcore_make_pseudosection (abfd=0x55555649dd30, name=0x555555d521f8 ".reg", size=360, filepos=1652)
at ../../bfd/elf.c:10331
10331 {
(gdb) bt
#0 _bfd_elfcore_make_pseudosection (abfd=0x55555649dd30, name=0x555555d521f8 ".reg", size=360, filepos=1652) at ../../bfd/elf.c:10331
#1 0x0000555555c40dfc in elf_parse_notes (abfd=abfd@entry=0x55555649dd30, buf=buf@entry=0x555556435eb0 "\005", size=size@entry=1984,
offset=offset@entry=1520, align=4, align@entry=0) at ../../bfd/elf.c:13412
#2 0x0000555555c56794 in elf_read_notes (abfd=0x55555649dd30, offset=1520, size=1984, align=0) at ../../bfd/elf.c:13461
#3 0x0000555555c3e684 in bfd_elf64_core_file_p (abfd=0x55555649dd30) at ../../bfd/elfcore.h:266
#4 0x0000555555c27860 in bfd_check_format_matches (abfd=0x55555649dd30, format=<optimized out>, matching=<optimized out>)
at ../../bfd/format.c:431
#5 0x00005555557ea6c8 in core_target_open (arg=<optimized out>, from_tty=<optimized out>) at ../../gdb/corelow.c:655
#6 0x00005555557aaa68 in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>) at ../../gdb/cli/cli-decode.c:2735
#7 0x0000555555b58c9c in execute_command (p=<optimized out>, p@entry=<error reading variable: value has been optimized out>,
from_tty=<error reading variable: value has been optimized out>) at ../../gdb/top.c:575
#8 0x00005555559985a8 in catch_command_errors (command=<optimized out>, arg=<optimized out>, from_tty=<optimized out>,
do_bp_actions=do_bp_actions@entry=true) at ../../gdb/main.c:513
#9 0x0000555555998738 in execute_cmdargs (cmdarg_vec=cmdarg_vec@entry=0x7ffffffd2eb0, file_type=file_type@entry=CMDARG_FILE,
cmd_type=cmd_type@entry=CMDARG_COMMAND, ret=ret@entry=0x7ffffffd2ea4) at ../../gdb/main.c:612
#10 0x000055555599a8ac in captured_main_1 (context=context@entry=0x7ffffffd30c0) at ../../gdb/main.c:1293
#11 0x000055555599b120 in captured_main (data=0x7ffffffd30c0) at ../../gdb/main.c:1314
#12 gdb_main (args=args@entry=0x7ffffffd30e0) at ../../gdb/main.c:1343
#13 0x0000555555676ee4 in main (argc=<optimized out>, argv=0x7ffffffd3288) at ../../gdb/gdb.c:47
(gdb)
It goes to the _bfd_elfcore_make_pseudosection for default process.
While, there will be some warning info like this:
Thread 1 "gdb" hit Breakpoint 3, _bfd_elfcore_make_pseudosection (abfd=0x55555649b7e0, name=0x555555dd6540 ".note.linuxcore.file", size=950,
filepos=2552) at ../../bfd/elf.c:10331
10331 {
(gdb) c
Continuing.
gdbarch_find_by_info: info.bfd_arch_info Loongarch64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0x55555649b7e0
gdbarch_find_by_info: Previous architecture 0x55555626d7f0 (Loongarch64) selected
[New LWP 3925]
warning: Unexpected size of section `.reg/3925' in core file.
gdbarch_find_by_info: info.bfd_arch_info Loongarch64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0x5555564d0a30
gdbarch_find_by_info: Previous architecture 0x55555626d7f0 (Loongarch64) selected
Core was generated by ` '.
warning: Unexpected size of section `.reg/3925' in core file.
#0 0x00007ffff2978c94 in ?? ()
Undefined command: "-d". Try "help".
(gdb)
This means the corefile generated in loonarch64 should be dealed by the loongarch64 backend.And if the loongarch64 macro definition change to match the value of the kernel struct elf_prstatus size , things will be normal. While in my mind, these two part should keep the same value as desinged.
The output will change to like this:
Thread 1 "gdb" hit Breakpoint 3, _bfd_elfcore_make_pseudosection (abfd=0x5555562e1f30, name=0x555555d6eb08 ".note.linuxcore.file", size=950,
filepos=2552) at ../../bfd/elf.c:10330
10330 sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd));
(gdb) c
Continuing.
gdbarch_find_by_info: info.bfd_arch_info Loongarch64
gdbarch_find_by_info: info.byte_order 1 (little)
gdbarch_find_by_info: info.osabi 5 (GNU/Linux)
gdbarch_find_by_info: info.abfd 0x5555562e1f30
gdbarch_find_by_info: Previous architecture 0x555556153850 (Loongarch64) selected
[New LWP 3925]
Core was generated by ` '.
#0 0x00007ffff2978c94 in ?? ()
❌️ Undefined command: "-d". Try "help".
(gdb)
As we see, it has no warning info then.And the thread has been eatablished.
As mentioned above, this is the problem I met and the root case annalysis for this commit.
lijian1 (1):
bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct
elf_prstatus size
bfd/elfnn-loongarch.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.43.0
More information about the Binutils
mailing list