[PATCH v2 0/1] bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct elf_prstatus size
Tiezhu Yang
yangtiezhu@loongson.cn
Thu Oct 30 02:40:23 GMT 2025
More information about the Binutils mailing list
Thu Oct 30 02:40:23 GMT 2025
- Previous message (by thread): [PATCH v2 1/1] bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct elf_prstatus size
- Next message (by thread): [PATCH v2 0/1] bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct elf_prstatus size
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2025/10/28 下午9:52, lijian1@kylinos.cn wrote: > 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. This is OK and can be reproduced on my environment. But we can not reproduce the gdb warning used with the core file generated with the simple program. > 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. bfd/elf.c: static bool elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) { ... case NT_PRSTATUS: if (bed->elf_backend_grok_prstatus) if ((*bed->elf_backend_grok_prstatus) (abfd, note)) return true; #if defined (HAVE_PRSTATUS_T) return elfcore_grok_prstatus (abfd, note); #else return true; #endif ... } static bool elfcore_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) { ... /* Make a ".reg/999" section and a ".reg" section. */ return _bfd_elfcore_make_pseudosection (abfd, NOTE_PSEUDO_SECTION_REG, size, note->descpos + offset); } Could you please print the value of "size" here? Is it 0x168? If yes, there should be no the "Unexpected size of section" warning in the following code: void core_target::get_core_register_section (struct regcache *regcache, const struct regset *regset, const char *name, int section_min_size, const char *human_name, bool required) { ... size = bfd_section_size (section); ... if (size != section_min_size && !variable_size_section) { warning (_("Unexpected size of section `%s' in core file."), section_name.c_str ()); } ... } Could you please print the value of "size" and "section_min_size" here? Thanks, Tiezhu
- Previous message (by thread): [PATCH v2 1/1] bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct elf_prstatus size
- Next message (by thread): [PATCH v2 0/1] bfd/loongarch: set PRSTATUS_SIZE=0x1e0 to match kernel's struct elf_prstatus size
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list