Skip to content

Commit

Permalink
C std: remove stddef, make stdint a shadow of its former self
Browse files Browse the repository at this point in the history
  • Loading branch information
nwf committed Jun 6, 2020
1 parent b361406 commit 35c1195
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 226 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ set(ASM_COMPILER_FLAGS
set(C_COMPILER_FLAGS
${ASMC_COMPILER_FLAGS}
-ftls-model=local-exec
-nostdinc
# -nostdinc # TODO: -nostdinc -ibuiltininc
-fomit-frame-pointer
-ffreestanding
-O${O_LVL} # TODO: make this depend on the configuration
Expand Down
1 change: 1 addition & 0 deletions elf/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

#ifndef __ASSEMBLY__

#include <stddef.h>
#include "mips.h"
#include "stdarg.h"
#include "nano/nanotypes.h"
Expand Down
11 changes: 0 additions & 11 deletions include/mips.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@

#include <stdint.h>

/*
* Provide more convenient names for useful qualifiers from gcc/clang.
*/
#define __aligned__(x) __attribute__ ((aligned(x)))
#define __packed__ __attribute__ ((packed))

/*
* 64-bit MIPS types.
*/
Expand All @@ -100,11 +94,6 @@ typedef unsigned long size_t;
typedef long off_t;

#define NBBY 8 /* Number of bits per byte. */
#ifdef __cplusplus
#define NULL nullptr
#else
#define NULL ((void *)0)
#endif

/*
* Useful addresses on MIPS.
Expand Down
43 changes: 0 additions & 43 deletions include/stddef.h

This file was deleted.

177 changes: 7 additions & 170 deletions include/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,21 @@
* $FreeBSD$
*/

#include_next <stdint.h>

#ifndef _MACHINE__STDINT_H_
#define _MACHINE__STDINT_H_

/*
* Useful integer type names that we can't pick up from the compile-time
* environment.
* These are non-standard but pervasive in old code.
*/
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;

typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;

typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;

typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __UINT64_TYPE__ uintmax_t;

typedef __INTMAX_TYPE__ intmax_t;

typedef __PTRDIFF_TYPE__ ptrdiff_t;

typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;

typedef __INT64_TYPE__ quad_t;
typedef __UINT64_TYPE__ u_quad_t;

typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long u_long;
typedef unsigned int u_int;


/*
* XXX On CHERI, this should probably be vaddr_t, but that seems to post-date
* the CheriOS branch of LLVM.
Expand All @@ -92,156 +72,13 @@ typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;

#define define_intypes(size) \
typedef __INT_LEAST ## size ## _TYPE__ int_least ## size ## _t; \
typedef __UINT_LEAST ## size ## _TYPE__ uint_least ## size ## _t; \
typedef __INT_FAST ## size ## _TYPE__ int_fast ## size ## _t; \
typedef __UINT_FAST ## size ## _TYPE__ uint_fast ## size ## _t;

#define INT_SIZES(ITEM) ITEM(8) ITEM(16) ITEM(32) ITEM(64)

INT_SIZES(define_intypes)

#undef define_inttypes
#undef INT_SIZES
typedef int64_t quad_t;
typedef uint64_t u_quad_t;


#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)

#define INT8_C(c) (c)
#define INT16_C(c) (c)
#define INT32_C(c) (c)

#define UINT8_C(c) (c)
#define UINT16_C(c) (c)
#define UINT32_C(c) (c ## U)

#ifdef __mips_n64
#define INT64_C(c) (c ## L)
#define UINT64_C(c) (c ## UL)
#else
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

#define INTMAX_C(c) INT64_C(c)
#define UINTMAX_C(c) UINT64_C(c)

#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */

#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)

#ifndef __INT64_C
#ifdef __mips_n64
#define __INT64_C(c) (c ## L)
#define __UINT64_C(c) (c ## UL)
#else
#define __INT64_C(c) (c ## LL)
#define __UINT64_C(c) (c ## ULL)
#endif
#endif

/*
* ISO/IEC 9899:1999
* 7.18.2.1 Limits of exact-width integer types
* End non-standard but pervasive names.
*/
/* Minimum values of exact-width signed integer types. */
#define INT8_MIN (-__INT8_MAX__-1)
#define INT16_MIN (-__INT16_MAX__-1)
#define INT32_MIN (-__INT32_MAX__-1)
#define INT64_MIN (-__INT64_MAX__-1)

/* Maximum values of exact-width signed integer types. */
#define INT8_MAX __INT8_MAX__
#define INT16_MAX __INT16_MAX__
#define INT32_MAX __INT32_MAX__
#define INT64_MAX __INT64_MAX__

/* Maximum values of exact-width unsigned integer types. */
#define UINT8_MAX __UINT8_MAX__
#define UINT16_MAX __UINT16_MAX__
#define UINT32_MAX __UINT32_MAX__
#define UINT64_MAX __UINT64_MAX__

/*
* ISO/IEC 9899:1999
* 7.18.2.2 Limits of minimum-width integer types
*/
/* Minimum values of minimum-width signed integer types. */
#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__-1)
#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__-1)
#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__-1)
#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__-1)

/* Maximum values of minimum-width signed integer types. */
#define INT_LEAST8_MAX __INT_LEAST8_MAX__
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
#define INT_LEAST64_MAX __INT_LEAST64_MAX__

/* Maximum values of minimum-width unsigned integer types. */
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

/*
* ISO/IEC 9899:1999
* 7.18.2.3 Limits of fastest minimum-width integer types
*/
/* Minimum values of fastest minimum-width signed integer types. */
#define INT_FAST8_MIN (-__INT_FAST8_MAX__-1)
#define INT_FAST16_MIN (-__INT_FAST16_MAX__-1)
#define INT_FAST32_MIN (-__INT_FAST32_MAX__-1)
#define INT_FAST64_MIN (-__INT_FAST64_MAX__-1)

/* Maximum values of fastest minimum-width signed integer types. */
#define INT_FAST8_MAX __INT_FAST8_MAX__
#define INT_FAST16_MAX __INT_FAST16_MAX__
#define INT_FAST32_MAX __INT_FAST32_MAX__
#define INT_FAST64_MAX __INT_FAST64_MAX__

/* Maximum values of fastest minimum-width unsigned integer types. */
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
#define UINT_FAST64_MAX __UINT_FAST64_MAX__

/*
* ISO/IEC 9899:1999
* 7.18.2.4 Limits of integer types capable of holding object pointers
*/
#define INTPTR_MIN (-__INTPTR_MAX__-1)
#define INTPTR_MAX __INTPTR_MAX__
#define UINTPTR_MAX __UINTPTR_MAX__

/*
* ISO/IEC 9899:1999
* 7.18.2.5 Limits of greatest-width integer types
*/
#define INTMAX_MIN (-__INTMAX_MAX__-1)
#define INTMAX_MAX __INTMAX_MAX__
#define UINTMAX_MAX __UINTMAX_MAX__

/*
* ISO/IEC 9899:1999
* 7.18.3 Limits of other integer types
*/
#define PTRDIFF_MIN (-__PTRDIFF_MAX__-1)
#define PTRDIFF_MAX __PTRDIFF_MAX__

/* Limit of size_t. */
#define SIZE_MAX __SIZE_MAX__

/* Limits of sig_atomic_t. */
#define SIG_ATOMIC_MIN (-__SIG_ATOMIC_MAX-1)
#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__

/* Limits of wint_t. */
#define WINT_MIN (-__WINT_MAX__-1)
#define WINT_MAX __WINT_MAX__

#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */

#endif /* !_MACHINE__STDINT_H_ */

1 change: 1 addition & 0 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef __STRING_H__
#define __STRING_H__

#include <stddef.h>
#include "cdefs.h"
#include "mips.h"
#include "locale.h"
Expand Down
1 change: 1 addition & 0 deletions libcrt/libc/freebsd_ports/memchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* SUCH DAMAGE.
*/

#include <stddef.h>
#include "mips.h"

void *
Expand Down
1 change: 1 addition & 0 deletions libcrt/libc/freebsd_ports/strbprk.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* SUCH DAMAGE.
*/

#include <stddef.h>
#include "cheric.h"

/*
Expand Down
1 change: 1 addition & 0 deletions libcrt/libc/freebsd_ports/strrchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* SUCH DAMAGE.
*/

#include <stddef.h>
#include "cdefs.h"
#include "mips.h"

Expand Down
1 change: 1 addition & 0 deletions libcrt/libc/freebsd_ports/strtol.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <cdefs.h>
#include <ctype.h>
#include <stddef.h>
#include <stdint.h>
#include "cheric.h"

Expand Down
1 change: 1 addition & 0 deletions libcrt/libc/freebsd_ports/subr_prf.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "mips.h"
#include "stdarg.h"
#include "stddef.h"
#include "stdio.h"
#include "string.h"
#include "math.h"
Expand Down
2 changes: 1 addition & 1 deletion libuser/src/virtioblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
* SUCH DAMAGE.
*/

#include "mips.h"
#include <stddef.h>
void * vblk_ref = NULL;

0 comments on commit 35c1195

Please sign in to comment.