Bug 169187

Summary: Bad sizeof(uint64_t) with -m32 compiler flag
Product: Base System Reporter: Eric McCorkle <eric>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Eric McCorkle 2012-06-18 01:40:11 UTC
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.

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.
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.
Comment 1 Remko Lodder freebsd_committer freebsd_triage 2012-06-18 13:07:34 UTC
Responsible Changed
From-To: freebsd-i386->freebsd-bugs

This is not i386 specific.
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:49:54 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"
Comment 3 Andriy Gapon freebsd_committer freebsd_triage 2018-05-21 05:59:44 UTC
$ ./test
8