Hi all, I want to compile 32bit binary on amd64, but I met with the problem. Could you teach me the best solution, please? My environment is FreeBSD 8.1-PRERELEASE #0: Tue May 18 12:01:26 JST 2010. I compiled and executed test.c as below on amd64. -- begin -- test.c ------------------------------------------------------ #include <stdlib.h> #include <stdio.h> #include <sys/mman.h> #include <unistd.h> int main() { void *ptr; ptr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0); if (ptr == MAP_FAILED) { perror("mmap"); exit(1); } printf("%lx\n", (unsigned long)ptr); munmap(ptr, 4096); exit(0); } -- end -- test.c -------------------------------------------------------- % gcc -m32 -B/usr/lib32 test.c % ./a.out mmap: Invalid argument I disassembled a.out. I think that 'movl $0x0,0x18(%esp)' is needed. This error is occured by 'off_t offset'. 80484ce: 83 ec 34 sub $0x34,%esp 80484d1: c7 44 24 14 00 00 00 movl $0x0,0x14(%esp) 80484d8: 00 80484d9: c7 44 24 10 ff ff ff movl $0xffffffff,0x10(%esp) 80484e0: ff 80484e1: c7 44 24 0c 00 10 00 movl $0x1000,0xc(%esp) 80484e8: 00 80484e9: c7 44 24 08 03 00 00 movl $0x3,0x8(%esp) 80484f0: 00 80484f1: c7 44 24 04 00 10 00 movl $0x1000,0x4(%esp) 80484f8: 00 80484f9: c7 04 24 00 00 00 00 movl $0x0,(%esp) 8048500: e8 43 fe ff ff call 8048348 <mmap_at_plt> I found this solution. I modified machine depended header as below. # cd /usr/include/machine # cp /usr/src/sys/i386/include/_types.h _types32.h # patch < _types.h.diff -- begin -- _types.h.diff ------------------------------------------------ --- _types.h.org 2010-05-24 13:34:55.406874258 +0900 +++ _types.h 2010-05-24 13:35:33.790522354 +0900 _at__at_ -36,6 +36,10 _at__at_ * $FreeBSD: src/sys/amd64/include/_types.h,v 1.12.2.1 2009/08/03 08:13:06 kensmith Exp $ */ +#ifdef __i386__ +#include <machine/_types32.h> +#else + #ifndef _MACHINE__TYPES_H_ #define _MACHINE__TYPES_H_ _at__at_ -115,3 +119,4 _at__at_ #endif #endif /* !_MACHINE__TYPES_H_ */ +#endif /* __i386__ */ -- end -- _types.h.diff ---------------------------------------------- In this case, 'off_t offset' is set correctly as below. 80484d1: c7 44 24 14 00 00 00 movl $0x0,0x14(%esp) 80484d8: 00 80484d9: c7 44 24 18 00 00 00 movl $0x0,0x18(%esp) 80484e0: 00 80484e1: c7 44 24 10 ff ff ff movl $0xffffffff,0x10(%esp) 80484e8: ff 80484e9: c7 44 24 0c 00 10 00 movl $0x1000,0xc(%esp) 80484f0: 00 80484f1: c7 44 24 08 03 00 00 movl $0x3,0x8(%esp) 80484f8: 00 80484f9: c7 44 24 04 00 10 00 movl $0x1000,0x4(%esp) 8048500: 00 8048501: c7 04 24 00 00 00 00 movl $0x0,(%esp) 8048508: e8 3b fe ff ff call 8048348 <mmap_at_plt> How should we deal with this problem? Best reards, Kohji OkunoReceived on Mon May 24 2010 - 02:49:59 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:03 UTC