Bug 186958

Summary: [headers] Incorrect definitions for platform-dependent types and macros
Product: Base System Reporter: Ivan Kosarev <ivan>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me CC: emaste
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Ivan Kosarev 2014-02-22 13:00:00 UTC
Revision 232261:

http://svnweb.freebsd.org/base?view=revision&revision=232261

address definition of some types, e.g, int64_t, on x64 FreeBSD when compiled in 32-bit mode.

This bug report is about some other types and macros to fix to define them correctly in 32-bit mode.

How-To-Repeat: $ cat test.c
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>

#include <sys/wait.h>


#define PRINT(x) \
    ((void) (printf(#x ": %d\n", (int) (x))))


int main(void)
{
    PRINT(sizeof(long));         // width of target

    PRINT(sizeof(int64_t)) ;     // '__int64_t' of <machine/_types.h>
    PRINT(sizeof(INT64_C(0)));   // 'INT64_C()' of <machine/_stdint.h>
    PRINT(sizeof(UINT64_C(0)));  // 'UINT64_C()' of <machine/_stdint.h>

    PRINT(sizeof(intptr_t)) ;    // '__intptr_t' of <machine/_types.h>
    PRINT(sizeof(INTPTR_MIN));   // 'INTPTR_MIN' of <machine/_stdint.h>
    PRINT(sizeof(INTPTR_MAX));   // 'INTPTR_MAX' of <machine/_stdint.h>

    PRINT(sizeof(uintptr_t)) ;   // '__uintptr_t' of <machine/_types.h>
    PRINT(sizeof(UINTPTR_MAX));  // 'UINTPTR_MAX' of <machine/_stdint.h>

    PRINT(sizeof(ptrdiff_t)) ;   // '__ptrdiff_t' of <machine/_types.h>
    PRINT(sizeof(PTRDIFF_MIN));  // 'PTRDIFF_MIN' of <machine/_stdint.h>
    PRINT(sizeof(PTRDIFF_MAX));  // 'PTRDIFF_MIN' of <machine/_stdint.h>

    PRINT(sizeof(size_t));       // '__size_t' of <machine/_types.h>
    PRINT(sizeof(SIZE_MAX));     // 'SIZE_MAX' of <machine/_stdint.h>

    PRINT(sizeof(__intfptr_t));  // '__intfptr_t' of <machine/_types.h>
    PRINT(sizeof(__uintfptr_t)); // '__uintfptr_t' of <machine/_types.h>

    PRINT(sizeof(__ssize_t));    // '__ssize_t' of <machine/_types.h>

    PRINT(sizeof(id_t));         // '__id_t' of <sys/_types.h>
    PRINT(sizeof(time_t));       // '__time_t' of <machine/_types.h>

    return EXIT_SUCCESS;
}

$ gcc -m32 -B/usr/lib32 test.c && ./a.out
sizeof(long): 4
sizeof(int64_t): 8
sizeof(INT64_C(0)): 4
sizeof(UINT64_C(0)): 4
sizeof(intptr_t): 4
sizeof(INTPTR_MIN): 8
sizeof(INTPTR_MAX): 8
sizeof(uintptr_t): 4
sizeof(UINTPTR_MAX): 8
sizeof(ptrdiff_t): 4
sizeof(PTRDIFF_MIN): 8
sizeof(PTRDIFF_MAX): 8
sizeof(size_t): 4
sizeof(SIZE_MAX): 8
sizeof(__intfptr_t): 4
sizeof(__uintfptr_t): 4
sizeof(__ssize_t): 4
sizeof(id_t): 8
sizeof(time_t): 4

Expected output:
sizeof(long): 4
sizeof(int64_t): 8
sizeof(INT64_C(0)): 8
sizeof(UINT64_C(0)): 8
sizeof(intptr_t): 4
sizeof(INTPTR_MIN): 4
sizeof(INTPTR_MAX): 4
sizeof(uintptr_t): 4
sizeof(UINTPTR_MAX): 4
sizeof(ptrdiff_t): 4
sizeof(PTRDIFF_MIN): 4
sizeof(PTRDIFF_MAX): 4
sizeof(size_t): 4
sizeof(SIZE_MAX): 4
sizeof(__ssize_t): 4
sizeof(id_t): 4
sizeof(time_t): 4

Things to fix:
sizeof(INT64_C(0))
sizeof(UINT64_C(0))
sizeof(INTPTR_MIN)
sizeof(INTPTR_MAX)
sizeof(UINTPTR_MAX)
sizeof(PTRDIFF_MIN)
sizeof(PTRDIFF_MAX)
sizeof(SIZE_MAX)
sizeof(id_t)
Comment 1 Ed Maste freebsd_committer freebsd_triage 2014-06-09 15:42:05 UTC
Current output on stable/9:

sizeof(long): 4
sizeof(int64_t): 8
sizeof(INT64_C(0)): 8
sizeof(UINT64_C(0)): 8
sizeof(intptr_t): 4
sizeof(INTPTR_MIN): 4
sizeof(INTPTR_MAX): 4
sizeof(uintptr_t): 4
sizeof(UINTPTR_MAX): 4
sizeof(ptrdiff_t): 4
sizeof(PTRDIFF_MIN): 4
sizeof(PTRDIFF_MAX): 4
sizeof(size_t): 4
sizeof(SIZE_MAX): 4
sizeof(__intfptr_t): 4
sizeof(__uintfptr_t): 4
sizeof(__ssize_t): 4
sizeof(id_t): 8
sizeof(time_t): 4
Comment 2 Ed Maste freebsd_committer freebsd_triage 2014-06-09 16:53:02 UTC
id_t is not a -m32 bug - it is int64_t on all of our platforms, including i386.

Related dfly issue: https://bugs.dragonflybsd.org/issues/1390
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:52:55 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"