Subject: Malformed core dumps on Guix System

From: Mathieu Othacehe <[email-masked]>
Date: Mon, 31 Oct 2022 11:23:48 +0100

Hello,

Working on https://issues.guix.gnu.org/58733, I noticed that there is
something wrong with the core dumps we are generating on Guix System.

--8<---------------cut here---------------start------------->8---
mathieu@meije ~/tmp [env]$ cat test.c 
#include <stdio.h>
int main() {
	int *t = NULL;
	return *t;
}

mathieu@meije ~/tmp [env]$ gcc test.c 
mathieu@meije ~/tmp [env]$ ulimit -c unlimited
mathieu@meije ~/tmp [env]$ ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) unlimited

mathieu@meije ~/tmp [env]$ echo "/tmp/my-core-%p" | sudo tee /proc/sys/kernel/core_pattern
/tmp/my-core-%p

mathieu@meije ~/tmp [env]$ ./a.out 
Segmentation fault (core dumped)

mathieu@meije ~/tmp [env]$ gdb ./a.out /tmp/my-core-5622
...
BFD: warning: /tmp/my-core-5622 has a segment extending past end of file
...
Failed to read a valid object file image from memory.
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000401102 in main ()
(gdb) bt
#0  0x0000000000401102 in main ()
Backtrace stopped: Cannot access memory at address 0x7fff14e14168
--8<---------------cut here---------------end--------------->8---

The "has a segment extending past end of file" warning appears to be
problematic and the "bt" command does not work which makes core dump
generation a bit useless.

Thanks,

Mathieu