[PATCH] bfd: loongarch: modify NT_PRSTATUS note to 480 bytes for kernel uapi.And gdb need more protect for coredump.
Tiezhu Yang
yangtiezhu@loongson.cn
Fri Oct 24 09:10:54 GMT 2025
On 2025/10/22 下午2:22, lijian1@kylinos.cn wrote:
> From: lijian1 <lijian1@kylinos.cn>
>
> Signed-off-by: lijian1 <lijian1@kylinos.cn>
>
> -For loongarch64 from the kernel uapi,
It is not uapi, the definition of struct elf_prstatus is in
include/linux/elfcore.h in Linux kernel.
the sizeof (struct elf_prstatus) on Linux/LoongArch is 0x1e0(480bytes,
include the padding),from kernel 6.6-6.18,keep this value.But the old
value for PRSTATUS_SIZE(0x1d8) is 472bytes, this will lead to no .reg
section generated.And if there is no reg sections generated, the thread
list will not generate normally.So keep the value with kernel in bfd and
add protection for gdb.
> ---
> bfd/elfnn-loongarch.c | 2 +-
> gdb/thread.c | 3 +++
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index 53cdb783859..8f06fbbf12f 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -6540,7 +6540,7 @@ loongarch_elf_copy_indirect_symbol (struct bfd_link_info *info,
> _bfd_elf_link_hash_copy_indirect (info, dir, ind);
> }
>
> -#define PRSTATUS_SIZE 0x1d8
> +#define PRSTATUS_SIZE 0x1e0
Tested with the following simple program on LoongArch, the size
is 0x1e0.
fedora@linux:~$ cat test.c
#include <stdio.h>
#include <sys/procfs.h>
int main()
{
char *p = NULL;
printf("0x%x\n", sizeof(struct elf_prstatus));
*p = 1;
return 0;
}
fedora@linux:~$ gcc -g test.c -o test
fedora@linux:~$ ./test
0x1e0
Segmentation fault (core dumped)
If PRSTATUS_SIZE is 0x1d8, what is the real problem? How to reproduce?
Please provide a simple example and detail steps.
> #define PRSTATUS_OFFSET_PR_CURSIG 0xc
> #define PRSTATUS_OFFSET_PR_PID 0x20
> #define ELF_GREGSET_T_SIZE 0x168
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 472f41969cf..92908b0f78e 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -298,6 +298,9 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid)
> gdb_assert (targ != nullptr);
>
> inferior *inf = find_inferior_ptid (targ, ptid);
> +
> + /*if there is no reg section, the inf will be null*/
> + gdb_assert(inf != nullptr);
If PRSTATUS_SIZE is correct in bfd/elfnn-loongarch.c, I am not sure
whether the above change of GDB is necessary, it is up to the GDB
global maintainers.
Anyway, if the change of GDB is necessary, please split into two
patches, one for bfd and one for gdb, use proper patch title and
describe the current problem with detailed info in the commit
message. If the change of GDB is not necessary, you can drop the
change of GDB.
Thanks,
Tiezhu
More information about the Binutils
mailing list