On Wed, Jan 02, 2008 at 10:38:40PM -0800, Jason Evans wrote:
quoted text > Poul-Henning noticed today that xchat fails to start if malloc uses sbrk=
=20
quoted text > internally. This failure happens during the first call to malloc, with=
=20
quoted text > the following message:
>=20
> Fatal error 'Can't allocate initial thread' at line 335 in file=20
> /usr/src/lib/libthr/thread/thr_init.c (errno =3D 12)
>=20
> This can be worked around with MALLOC_OPTIONS=3DdM .
>=20
> The problem does not appear to be specific to jemalloc; I reverted=20
> src/lib/libc/stdlib/malloc.c to revision 1.92 (last phkmalloc revision),=
=20
quoted text > which also uses sbrk, and the failure mode is the same.
>=20
> The failure occurs on both i386 and amd64. It appears that sbrk(0)=20
> returns an address that is in the address range normally used by mmap.=20
> So, the first call to sbrk with a non-zero increment is fantastically=20
> wrong. On i386 (ktrace output):
>=20
> 1013 xchat CALL break(0x28200000)
> 1013 xchat RET break -1 errno 12 Cannot allocate memory
>=20
> On amd64 (truss ouput):
>=20
> break(0x800900000) ERR#12 'Cannot allocate memory'
>=20
> sbrk is not a true system call, so it seems like the problem should have=
=20
quoted text > something to do with the _end data symbol. I looked at it in gdb though=
=20
quoted text > and never saw an unreasonable value, despite bogus sbrk(0) results. I=20
> do not know offhand how to get the addresses of .minbrk and .curbrk=20
> (register inspection within gdb while stepping through sbrk?), which are=
=20
quoted text > what sbrk actually uses (see src/lib/libc/amd64/sys/sbrk.S). Perhaps=20
> the loader isn't initializing them correctly...
>=20
> I am quite pressed for time at the moment, and cannot look into this in=
=20
quoted text > any more detail for at least a couple of weeks. If anyone knows what=20
> the problem is, please let me know.
I cannot say definitely what happen, but please note that the _end
symbol is defined by linker script, and it shall be present in all
executable and shared objects. The value you reported would be naturally
the _end value for some shared object.
I tried both the RELENG_7 and HEAD, and sbrk(0) correctly returns a
seemingly valid value like 0x8049644.
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int
main(int argc, char *argv)
{
void *p;
p =3D sbrk(0);
printf("%p\n", p);
return (0);
}