From owner-freebsd-bugs@FreeBSD.ORG Thu Jul 18 10:30:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 374822C6 for ; Thu, 18 Jul 2013 10:30:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 1F4673DC for ; Thu, 18 Jul 2013 10:30:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r6IAU0fI033353 for ; Thu, 18 Jul 2013 10:30:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r6IAU00s033352; Thu, 18 Jul 2013 10:30:00 GMT (envelope-from gnats) Resent-Date: Thu, 18 Jul 2013 10:30:00 GMT Resent-Message-Id: <201307181030.r6IAU00s033352@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jukka Ukkonen Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id ACC69E2 for ; Thu, 18 Jul 2013 10:25:57 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121]) by mx1.freebsd.org (Postfix) with ESMTP id 85A0E395 for ; Thu, 18 Jul 2013 10:25:57 +0000 (UTC) Received: from oldred.freebsd.org ([127.0.1.6]) by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r6IAPtnq014592 for ; Thu, 18 Jul 2013 10:25:55 GMT (envelope-from nobody@oldred.freebsd.org) Received: (from nobody@localhost) by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r6IAPtvc014591; Thu, 18 Jul 2013 10:25:55 GMT (envelope-from nobody) Message-Id: <201307181025.r6IAPtvc014591@oldred.freebsd.org> Date: Thu, 18 Jul 2013 10:25:55 GMT From: Jukka Ukkonen To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: kern/180628: Make 32-bit i386 compilation work properly on AMD64 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 10:30:01 -0000 >Number: 180628 >Category: kern >Synopsis: Make 32-bit i386 compilation work properly on AMD64 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Jul 18 10:30:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Jukka Ukkonen >Release: 9.2-PRERELEASE >Organization: ----- >Environment: FreeBSD sleipnir 9.2-PRERELEASE FreeBSD 9.2-PRERELEASE #6 r253336M: Thu Jul 18 09:59:05 EEST 2013 root@sleipnir:/usr/obj/usr/src/sys/Sleipnir amd64 >Description: When building 32-bit compilations of anything needing int64_t sized integers the current defines such types as long or unsigned long. These are clearly wrong. When -m32 is used as part of the compilation command the proper definitions would be long long and unsigned long long as they are defined for i386. The proposed change should fix also kern/169187 and some other trouble tickets referring to problems with 32-bit compilation on amd64. The problem is simply that the current is single mindedly geared towards 64-bit environments, though, it should be tuned for both 64 and 32 bit binaries. >How-To-Repeat: Try compiling this code snippet on amd64 with and without -m32, run the resulting binary, and compare the output of the two binaries... #include #include #include #include #include int main (ac, av) int ac; char *av[]; { printf ("sizeof (id_t) == %lu\n", (unsigned long) sizeof (id_t)); printf ("sizeof (int64_t) == %lu\n", (unsigned long) sizeof (int64_t)); printf ("sizeof (long) == %lu\n", (unsigned long) sizeof (long)); printf ("sizeof (long long) == %lu\n", (unsigned long) sizeof (long long)); exit (0); } For a 64-bit binary you should see... sizeof (id_t) == 8 sizeof (int64_t) == 8 sizeof (long) == 8 sizeof (long long) == 8 For a 32-bit binary the output is expected to be... sizeof (id_t) == 4 sizeof (int64_t) == 4 sizeof (long) == 4 sizeof (long long) == 8 This causes a whole lot of unnecessary alignment issues as well as truncated values among other problems. >Fix: Install sys/i386/include/_types.h to machine/_i386_types.h and sys/amd64/include/_types.h to machine/_amd64_types.h. Remember to hange the inclusion test macros to _MACHINE__I386_TYPES_H_ and _MACHINE__AMD64_TYPES_H_ in the beginning of the new header files. Then replace the contents of the current machine/_types.h with this... #ifndef _MACHINE__TYPES_H_ #define _MACHINE__TYPES_H_ #if defined(__amd64__) # include #else # include #endif #endif /* !_MACHINE__TYPES_H_ */ and magically 32-bit compilations should start coming out just fine. When -m32 is given on the command line the __amd64__ macro will no longer be defined during compilation. So, the correctly tuned type definition will be included automatically. >Release-Note: >Audit-Trail: >Unformatted: