Problems in __environ in mips

Lluís Batlle viriketo at gmail.com
Sun Mar 14 10:48:28 UTC 2010


Hello,

I'm trying to build a program for a mips (OpenWRT in brcm63xx), linux
2.6.32.9, statically linked.

Having built the program with a cross-toolchain (linux-headers
2.6.32.9, gcc 4.4.3, binutils 2.20, uclibc 0.9.30.2) for
mips-unknown-linux, I'm having problems with the __environ variable.

Debugging the target, I see that the contents of __environ just after
the __uClibc_main line saying:
293         __environ = &argv[argc + 1];

The values of __environ are:
(gdb) print __environ[0]
$30 = 0x7f855f5e "USER=root"
(gdb) print __environ[1]
$31 = 0x43a2e0 <Address 0x43a2e0 out of bounds>
(gdb) print __environ[2]
$33 = 0x7f855f74 "HOME=/root"
(gdb) print __environ[3]
$32 = 0x7f855f7f "PS1=\\u@\\h:\\w\\$ "

As you see, accessing __environ[1] causes a segfault. According to
/proc/PID/environ, that should contain "OLDPWD=/etc".

And, if it rings a bell to anyone, the value 0x43a2e0 is also the
content of the register 'gp'. And looking at the argv array, the
__environ[1] value is already bad at the start of __uClibc_main.

Any help? What am I doing wrong?

For what it matters, I'm using the O32 ABI, and the MIPS32 cpu, for
both uclibc and the program I link.

Regards,
Lluís.


More information about the uClibc mailing list