gcc-4.3.1 for mips linux failed to execute dynamically linked elf executables

hjksfw hjksfw hjksfw@gmail.com
Tue Sep 2 01:46:00 GMT 2008


Hi all, I have build mips-linux-gcc on debian i486 pc from  following sources:
Gcc-4.3.1
Binutils-2.18
Glibc-2.4
Kernel-headers-2.6.18

The cross-complied mips-linux-gcc is good for kernel building, and the
vmlinux  boots on the target board correctly, but the problem is that
all dynamically linked executable programs are failed to be executed
and statically linked executable programs are successful.
$ mips-linux-gcc -v
Using built-in specs.
Target: mips-linux
Configured with: ../post-gcc-4.3.1/configure --target=mips-linux
--with-float=soft --enable-cxx-flags=-msoft-float --enable-symvers=gnu
--prefix=/tools --disable-nls --enable-shared --enable-languages=c,c++
--enable-__cxa_atexit --enable-c99 --enable-long-long
--enable-threads=posix --with-arch=mips32r2 --with-tune=24kec
Thread model: posix
gcc version 4.3.1 (GCC)

when I compile linux-2.6.18 from mips-linux-gcc 4.3.1, there is an error:

$ make vmlinux.bin
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  CC      arch/mips/kernel/asm-offsets.s
arch/mips/kernel/asm-offsets.c: In function 'output_mm_defines':
arch/mips/kernel/asm-offsets.c:228: error: invalid 'asm':
invalid use of '%X'
arch/mips/kernel/asm-offsets.c:229: error: invalid 'asm':
invalid use of '%X'
arch/mips/kernel/asm-offsets.c:230: error: invalid 'asm':
invalid use of '%X'
make[1]: *** [arch/mips/kernel/asm-offsets.s] Error 1
make: *** [prepare0] Error 2

the above error is due to the macro:
#define constant(string, member) \
        __asm__("\n@@@" string "%X0" : : "ri" (member))
in arch/mips/kernel/asm-offset.c
when I change the "%X0" to "%0":
#define constant(string, member) \
        __asm__("\n@@@" string "%0" : : "ri" (member))

the kernel compiled successfully.But mips-linux-gcc-4.1.1 have no such problem.
And the following is problems for dynamically linked elf.
A simplest test program:
#include
int main()
{
        printf("hello mips\n");
       return 0;
}


mips-linux-gcc test.c ¨Co test-dyn
Mips-linux-gcc test.c ¨Co test-static ¨Cstatic


$ file ./test-dyn
./test-dyn: ELF 32-bit MSB MIPS64 executable, MIPS, version 1 (SYSV),
for GNU/Linux 2.0.0, dynamically linked (uses shared libs), not
stripped
$ file ./test-static
./test-static: ELF 32-bit MSB MIPS64 executable, MIPS, version 1
(SYSV), for GNU/Linux 2.0.0, statically linked, not stripped

The strace results on the target mips board are following,(strace is
statically linked, so it can be executed):
Strace the program:
/ # strace ./test-dyn
execve("./test-dyn", ["./test-dyn"], [/* 6 vars */]) = 0
do_page_fault() #2: sending SIGSEGV to test-dyn for invalid read access from
0002e258 (epc == 2aabf140, ra == 2aab4f70)
uname({sys="Linux", node="192.168.172.44", ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x2aac5000
access("/etc/ld.so.preload", R_OK)      = 0
open("/etc/ld.so.preload", O_RDONLY)    = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
close(3)                                = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Process 98 detached
/ # strace ./test-static
execve("./test-static", ["./test-static"], [/* 6 vars */]) = 0
svr4_syscall()                          = 4122
svr4_syscall()                          = 4045
brk(0x494c98)                           = 0x494c98
set_thread_area(0x49b460)               = -2143376080
brk(0x4b5c98)                           = 0x4b5c98
brk(0x4b6000)                           = 0x4b6000
fstat64(1, {st_mode=S_IFCHR|0646, st_rdev=makedev(5, 1), ...}) = 0
ioctl(1, TIOCNXCL, {B115200 opost isig icanon echo ...}) = 0
old_mmap(NULL, 131072, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaa8000
write(1, "hello mips\n", 11hello mips
)            = 11
exit_group(0)                           = ?
Process 100 detached

I don't know what's wrong with the mips-linux-gcc 4.3.1, would you
help me please?
And I have also tried to cross-compile gcc for mips-linux from:
Gcc-4.1.1
Binutils-2.17
Glibc-2.4
kernel-headers-2.6.18
This cross-compiled gcc worked fine for both kernel and programs.


More information about the Gcc-help mailing list