Re: dietlibc broken on i386 since Feb 2018?

Frank Bergmann <[email protected]> Sun, 15 Sep 2019 22:32:49 +0200
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
> Please compile dietlibc with
> 
>   $ make DEBUG=1
> 
> and then run the binary in gdb so you can tell me where exactly the
> segfault happens. It does not happen on my system and I do not have an
> i386 system with a kernel old enough to not pass the random value.

Thanks for your hint. See output below.
Is this sufficient or do you need more details? I'm not a gdb expert.
Does it look like auxvec is too short?

gdb --args bin-i386/diet gcc -D__dietlibc__ -pipe -nostdinc -D_REENTRANT -ffunction-sections -fdata-s
sections -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4 -W -Wall -Wextra -Wc
char-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow -o bin-i386/elftrunc con
ntrib/elftrunc.c -Wl,--gc-sections -Wl,-z,noseparate-code
GNU gdb (GDB) CentOS (7.0.1-45.el5.centos)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/frank/dietlibc/bin-i386/diet...(no debugging symbols found)...done.
(gdb) run
Starting program: /home/frank/dietlibc/bin-i386/diet gcc -D__dietlibc__ -pipe -nostdinc -D_REENTRANT -ffunction-sections -fdata-sections -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4 -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow -o bin-i386/elftrunc contrib/elftrunc.c -Wl,--gc-sections -Wl,-z,noseparate-code

Program received signal SIGSEGV, Segmentation fault.
0x08049cb5 in stackgap (argc=29, argv=0xbfffd4b4, envp=0xbfffd52c, fp=0) at lib/stackgap-common.h:534
534	  __guard=*(unsigned long*)rand;
(gdb) quit
A debugging session is active.

	Inferior 1 [process 7593] will be killed.

Quit anyway? (y or n) y
$ gdb --args bin-i386/diet gcc -D__dietlibc__ -pipe -nostdinc -D_REENTRANT -ffunction-sections -fdata-s
sections -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4 -W -Wall -Wextra -Wc
char-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow -o bin-i386/elftrunc con
ntrib/elftrunc.c -Wl,--gc-sections -Wl,-z,noseparate-code
GNU gdb (GDB) CentOS (7.0.1-45.el5.centos)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/frank/dietlibc/bin-i386/diet...(no debugging symbols found)...done.
(gdb) break stackgap
Breakpoint 1 at 0x8049c72: file lib/stackgap-common.h, line 352.
(gdb) run
Starting program: /home/frank/dietlibc/bin-i386/diet gcc -D__dietlibc__ -pipe -nostdinc -D_REENTRANT -ffunction-sections -fdata-sections -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=4 -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls -Wshadow -o bin-i386/elftrunc contrib/elftrunc.c -Wl,--gc-sections -Wl,-z,noseparate-code

Breakpoint 1, stackgap (argc=29, argv=0xbfffe094, envp=0xbfffe10c, fp=0) at lib/stackgap-common.h:352
352	  long* auxvec=(long*)envp;
(gdb) break getauxval
Breakpoint 2 at 0x804a1a4: file lib/getauxval.c, line 16.
(gdb) c
Continuing.

Breakpoint 2, getauxval (type=25) at lib/getauxval.c:16
16	  return (long)find_in_auxvec(_auxvec,type);
(gdb) si
0x0804a1a7	16	  return (long)find_in_auxvec(_auxvec,type);
(gdb) si
0x0804a1ad	16	  return (long)find_in_auxvec(_auxvec,type);
(gdb) si
0x0804a1b1	16	  return (long)find_in_auxvec(_auxvec,type);
(gdb) si
0x0804a1b4	16	  return (long)find_in_auxvec(_auxvec,type);
(gdb) si
find_in_auxvec (x=0xbfffe17c, what=25) at lib/getauxval.c:4
4	static void* find_in_auxvec(long* x,long what) {
(gdb) l
1	#include <stdio.h>
2	#include <sys/auxv.h>
3	
4	static void* find_in_auxvec(long* x,long what) {
5	  while (*x) {
6	    if (*x==what)
7	      return (void*)x[1];
8	    x+=2;
9	  }
10	  return NULL;
(gdb) s
5	  while (*x) {
(gdb) x/30xw x
0xbfffe17c:	0x00000020	0x00110400	0x00000021	0x00110000
0xbfffe18c:	0x00000010	0x0f898371	0x00000006	0x00001000
0xbfffe19c:	0x00000011	0x00000064	0x00000003	0x08048034
0xbfffe1ac:	0x00000004	0x00000020	0x00000005	0x00000004
0xbfffe1bc:	0x00000007	0x00000000	0x00000008	0x00000000
0xbfffe1cc:	0x00000009	0x080480b4	0x0000000b	0x000003f2
0xbfffe1dc:	0x0000000c	0x000003f2	0x0000000d	0x000003f2
0xbfffe1ec:	0x0000000e	0x000003f2
(gdb) b 10
Breakpoint 3 at 0x804a192: file lib/getauxval.c, line 10.
(gdb) c
Continuing.

Breakpoint 3, find_in_auxvec (x=0xbfffe204, what=25) at lib/getauxval.c:10
10	  return NULL;
(gdb) s
11	}
(gdb) 
getauxval (type=25) at lib/getauxval.c:17
17	}
(gdb) 
stackgap (argc=29, argv=0xbfffe094, envp=0xbfffe10c, fp=0) at lib/stackgap-common.h:534
534	  __guard=*(unsigned long*)rand;
(gdb) p rand
$2 = 0x0
(gdb) quit
A debugging session is active.

	Inferior 1 [process 7598] will be killed.

Quit anyway? (y or n) y