From ff784825d687487160a9bda66ef27ac0d5865881 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sat, 6 Jun 2020 01:30:00 +0000 Subject: [PATCH] C std: remove stddef, make stdint a shadow of its former self This requires appealing to the compiler's builtin headers, which means we have to disable -nostdinc. Apparently there's an -ibuiltininc coming soon, which we probably want to adopt as soon as our compiler has it. --- CMakeLists.txt | 14 ++- elf/include/elf.h | 1 + include/mips.h | 11 -- include/stddef.h | 43 ------- include/stdint.h | 177 ++------------------------- include/string.h | 1 + libcrt/libc/freebsd_ports/memchr.c | 1 + libcrt/libc/freebsd_ports/strbprk.c | 1 + libcrt/libc/freebsd_ports/strrchr.c | 1 + libcrt/libc/freebsd_ports/strtol.c | 1 + libcrt/libc/freebsd_ports/subr_prf.c | 1 + libuser/src/virtioblk.c | 2 +- 12 files changed, 28 insertions(+), 226 deletions(-) delete mode 100755 include/stddef.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 73d5300e..1b0ac4f4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,7 +251,19 @@ set(ASM_COMPILER_FLAGS set(C_COMPILER_FLAGS ${ASMC_COMPILER_FLAGS} -ftls-model=local-exec - -nostdinc + + # TODO + # + # Presently we depend on some compiler-provided headers, but there's no way + # to get those if we disable the standard includes; so, no -nostdinc for + # us. + # + # There's an upstream LLVM (Darwin-only, which seems odd) flag -ibuiltininc + # that restores the compiler-provided headers even if -nostdinc is used. + # We should pass both of those when we can. In the interim, behold what + # Jess calls 'our usual "hack"': + --sysroot=/no/such/path + -fomit-frame-pointer -ffreestanding -O${O_LVL} # TODO: make this depend on the configuration diff --git a/elf/include/elf.h b/elf/include/elf.h index f3a75a17..7d588c6b 100644 --- a/elf/include/elf.h +++ b/elf/include/elf.h @@ -58,6 +58,7 @@ #ifndef __ASSEMBLY__ +#include #include "mips.h" #include "stdarg.h" #include "nano/nanotypes.h" diff --git a/include/mips.h b/include/mips.h index 68704395..0d28867a 100755 --- a/include/mips.h +++ b/include/mips.h @@ -81,12 +81,6 @@ #include -/* - * Provide more convenient names for useful qualifiers from gcc/clang. - */ -#define __aligned__(x) __attribute__ ((aligned(x))) -#define __packed__ __attribute__ ((packed)) - /* * 64-bit MIPS types. */ @@ -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. diff --git a/include/stddef.h b/include/stddef.h deleted file mode 100755 index 09965ce8..00000000 --- a/include/stddef.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 2016 Lawrence Esswood - * All rights reserved. - * - * This software was developed by SRI International and the University of - * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) - * ("CTSRD"), as part of the DARPA CRASH research programme. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef STDDEF_H -#define STDDEF_H - -#include "mips.h" - -// Apparently this is a built-in type in C++ but not C =/ -#if !defined(__cplusplus) -typedef int wchar_t; -#endif - -#define offsetof(X, Y) __builtin_offsetof(X, Y) - -#endif diff --git a/include/stdint.h b/include/stdint.h index 3b5370a0..6fa8d1e5 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -41,38 +41,18 @@ #ifndef _MACHINE__STDINT_H_ #define _MACHINE__STDINT_H_ +#include_next + /* - * 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. @@ -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_ */ diff --git a/include/string.h b/include/string.h index 3e33d627..de093df5 100755 --- a/include/string.h +++ b/include/string.h @@ -31,6 +31,7 @@ #ifndef __STRING_H__ #define __STRING_H__ +#include #include "cdefs.h" #include "mips.h" #include "locale.h" diff --git a/libcrt/libc/freebsd_ports/memchr.c b/libcrt/libc/freebsd_ports/memchr.c index 4abc91e1..cd083c61 100644 --- a/libcrt/libc/freebsd_ports/memchr.c +++ b/libcrt/libc/freebsd_ports/memchr.c @@ -30,6 +30,7 @@ * SUCH DAMAGE. */ +#include #include "mips.h" void * diff --git a/libcrt/libc/freebsd_ports/strbprk.c b/libcrt/libc/freebsd_ports/strbprk.c index a95f4641..48407a34 100644 --- a/libcrt/libc/freebsd_ports/strbprk.c +++ b/libcrt/libc/freebsd_ports/strbprk.c @@ -29,6 +29,7 @@ * SUCH DAMAGE. */ +#include #include "cheric.h" /* diff --git a/libcrt/libc/freebsd_ports/strrchr.c b/libcrt/libc/freebsd_ports/strrchr.c index 8c8d959a..be4834b5 100644 --- a/libcrt/libc/freebsd_ports/strrchr.c +++ b/libcrt/libc/freebsd_ports/strrchr.c @@ -29,6 +29,7 @@ * SUCH DAMAGE. */ +#include #include "cdefs.h" #include "mips.h" diff --git a/libcrt/libc/freebsd_ports/strtol.c b/libcrt/libc/freebsd_ports/strtol.c index a0d555db..3b608e45 100644 --- a/libcrt/libc/freebsd_ports/strtol.c +++ b/libcrt/libc/freebsd_ports/strtol.c @@ -36,6 +36,7 @@ #include #include +#include #include #include "cheric.h" diff --git a/libcrt/libc/freebsd_ports/subr_prf.c b/libcrt/libc/freebsd_ports/subr_prf.c index 51cd8162..3af99336 100644 --- a/libcrt/libc/freebsd_ports/subr_prf.c +++ b/libcrt/libc/freebsd_ports/subr_prf.c @@ -38,6 +38,7 @@ #include "mips.h" #include "stdarg.h" +#include "stddef.h" #include "stdio.h" #include "string.h" #include "math.h" diff --git a/libuser/src/virtioblk.c b/libuser/src/virtioblk.c index 6fab3cc5..fcdfd0fb 100644 --- a/libuser/src/virtioblk.c +++ b/libuser/src/virtioblk.c @@ -28,5 +28,5 @@ * SUCH DAMAGE. */ -#include "mips.h" +#include void * vblk_ref = NULL;