NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-amd64/39691: libgcc is missing for gcc -m32 on amd64



>Number:         39691
>Category:       port-amd64
>Synopsis:       It is not possible to link programs requiring libgcc with -m32
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-amd64-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 04 00:20:00 +0000 2008
>Originator:     Pierre Pronchery <khorben%defora.org@localhost>
>Release:        NetBSD 4.99.42
>Organization:
>Environment:
Architecture: x86_64
Machine: amd64
>Description:

It is possible to compile, link and run simple programs using gcc with -m32 on
NetBSD/amd64. However, when operations usually found in libgcc are needed (eg
division), the relevant library is absent.

>How-To-Repeat:

To achieve this, I am using my own libc, also compiled with -m32 natively on
NetBSD/amd64. Don't hesitate to reply to this bug report for instructions to
obtain and use it.

Simple programs are working:

=== BEGIN PASTE ===
khorben@syn:~/temp$ uname -a && \
echo -e '#include <stdio.h>\nint main() {\nprintf("Hello...\\n");\nreturn 
0;\n}' > test.c && \
gcc -m32 -nostdinc -I ~/Projects/libc/include -W -Wall -ffreestanding -g -c 
test.c && \
gcc -m32 -o test test.o -nostdlib -static ~/Projects/libc/src/start.o 
~/Projects/libc/src/.libs/libc.a && \
ktruss ./test
NetBSD syn.defora.rom 4.99.72 NetBSD 4.99.72 (GENERIC) #1: Fri Oct  3 23:51:20 
CEST 2008  
khorben%syn.defora.rom@localhost:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
 27313      1 ktruss   emul(netbsd)
 27313      1 ktruss   fktrace                     = 0
Hello...
 27313      1 ktruss   fcntl(0x4, 0x3, 0)          = 1
 27313      1 ktruss   fcntl(0x4, 0x4, 0x1)        = 0
 27313      1 test     emul(netbsd32)
 27313      1 test     netbsd32_execve("./test", 0x7f7fffffd678, 
0x7f7fffffd688) JUSTRETURN
 27313      1 test     netbsd32_write(0x1, 0x804d048, 0x8) = 8
       "Hello..."
 27313      1 test     netbsd32_write(0x1, 0x804d050, 0x1) = 1
       "\n"
 27313      1 test     netbsd32_break(0x80534e4)   = 0
 27313      1 test     netbsd32_break(0x8053450)   = 0
 27313      1 test     netbsd32_exit(0)
=== END PASTE ===

This, however, doesn't:

=== BEGIN PASTE ===
khorben@syn:~/temp$ uname -a && \
echo -e '#include <stdio.h>\nint main(int argc, char * argv[]) {\nunsigned long 
long i = argc; printf("Hello %lu...\\n", argc / i);\nreturn 0;\n}' > test.c && \
gcc -m32 -nostdinc -I ~/Projects/libc/include -W -Wall -ffreestanding -g -c 
test.c && \
gcc -m32 -o test test.o -nostdlib -static ~/Projects/libc/src/start.o 
~/Projects/libc/src/.libs/libc.a && \
ktruss ./test
NetBSD syn.defora.rom 4.99.72 NetBSD 4.99.72 (GENERIC) #1: Fri Oct  3 23:51:20 
CEST 2008  
khorben%syn.defora.rom@localhost:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
test.c:2: warning: unused parameter 'argv'
test.o: In function `main':
/home/khorben/temp/test.c:3: undefined reference to `__udivdi3'
=== END PASTE ===

This last example works with /usr/lib/libgcc.a copied directly from NetBSD/i386.

Fixing this allows the compilation of either i386 or amd64 binaries with the
native compiler. (With my libc, I can even compile Linux or *BSD binaries this
way, which is kinda fun)

>Fix:

Provide libgcc.a suitable for compilation with -m32 somewhere in the base
install.

For the -m32 option to be useful in most cases, a 32-bit version of all
libraries from base should also be included.



Home | Main Index | Thread Index | Old Index