Date: Mon, 18 Jun 2012 00:39:30 GMT From: Eric McCorkle <eric@shadowsun.net> To: freebsd-gnats-submit@FreeBSD.org Subject: i386/169187: Bad sizeof(uint64_t) with -m32 compiler flag Message-ID: <201206180039.q5I0dUY7022002@red.freebsd.org> Resent-Message-ID: <201206180040.q5I0eBVv088320@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 169187 >Category: i386 >Synopsis: Bad sizeof(uint64_t) with -m32 compiler flag >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-i386 >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jun 18 00:40:11 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Eric McCorkle >Release: 9.0, also appears on 10.0 >Organization: >Environment: FreeBSD atom-edge 9.0-STABLE FreeBSD 9.0-STABLE #118 r236960M: Wed Jun 13 08:44:31 EDT 2012 root@atom-edge:/usr/obj/usr/src/sys/CUSTOM amd64 >Description: When compiling programs on an amd64 machine with the -m32 compiler flag, uint64_t variables are incorrectly sized, resulting in sizeof(uint64_t) == 4. Presumably this affects int64_t as well, and any types that are typedef'ed to one of these. >How-To-Repeat: Compile the following program: #include <stdio.h> #include <stdlib.h> int main() { printf("%d\n", sizeof(uint64_t)); return 0; } with the following command: gcc -m32 -o test test.c The output will be "4" as opposed to "8" like it should be. >Fix: The file <machine/_types.h> defines __uint64_t as unsigned long on amd64 platforms. When compiling with -m32, however, the compiler makes unsigned long a 32-bit integer, which seems to be the root of the problem. A simple fix is to detect when sizeof(unsigned long) == 4, and define __uint64_t as unsigned long long instead. >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206180039.q5I0dUY7022002>