| Summary: | Bad sizeof(uint64_t) with -m32 compiler flag | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Eric McCorkle <eric> |
| Component: | kern | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | CC: | emaste |
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
Responsible Changed From-To: freebsd-i386->freebsd-bugs This is not i386 specific. For bugs matching the following conditions: - Status == In Progress - Assignee == "bugs@FreeBSD.org" - Last Modified Year <= 2017 Do - Set Status to "Open" $ ./test 8 |
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.