Walk back most uses of __STRICT_ANSI__

This commit is contained in:
Justine Tunney 2024-02-27 04:09:49 -08:00
parent 7c7bf4bb90
commit 0ef36489c8
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 109 additions and 193 deletions

View file

@ -6,14 +6,14 @@ if [ -n "$OBJDUMP" ]; then
fi fi
find_objdump() { find_objdump() {
if [ -x .cosmocc/3.3/bin/$1-linux-cosmo-objdump ]; then if [ -x .cosmocc/3.3.1/bin/$1-linux-cosmo-objdump ]; then
OBJDUMP=.cosmocc/3.3/bin/$1-linux-cosmo-objdump OBJDUMP=.cosmocc/3.3.1/bin/$1-linux-cosmo-objdump
elif [ -x .cosmocc/3.3/bin/$1-linux-musl-objdump ]; then elif [ -x .cosmocc/3.3.1/bin/$1-linux-musl-objdump ]; then
OBJDUMP=.cosmocc/3.3/bin/$1-linux-musl-objdump OBJDUMP=.cosmocc/3.3.1/bin/$1-linux-musl-objdump
elif [ -x "$COSMO/.cosmocc/3.3/bin/$1-linux-cosmo-objdump" ]; then elif [ -x "$COSMO/.cosmocc/3.3.1/bin/$1-linux-cosmo-objdump" ]; then
OBJDUMP="$COSMO/.cosmocc/3.3/bin/$1-linux-cosmo-objdump" OBJDUMP="$COSMO/.cosmocc/3.3.1/bin/$1-linux-cosmo-objdump"
elif [ -x "$COSMO/.cosmocc/3.3/bin/$1-linux-musl-objdump" ]; then elif [ -x "$COSMO/.cosmocc/3.3.1/bin/$1-linux-musl-objdump" ]; then
OBJDUMP="$COSMO/.cosmocc/3.3/bin/$1-linux-musl-objdump" OBJDUMP="$COSMO/.cosmocc/3.3.1/bin/$1-linux-musl-objdump"
else else
echo "error: toolchain not found (try running 'cosmocc --update' or 'make' in the cosmo monorepo)" >&2 echo "error: toolchain not found (try running 'cosmocc --update' or 'make' in the cosmo monorepo)" >&2
exit 1 exit 1

View file

@ -22,16 +22,15 @@ COSMOPOLITAN_C_START_
* @see libc/sysv/dos2errno.sh for multimapped numbers * @see libc/sysv/dos2errno.sh for multimapped numbers
*/ */
#if defined(__GNUC__) && defined(__aarch64__) && !defined(__STRICT_ANSI__) && \ #if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
!defined(__cplusplus)
/* this header is included by 700+ files; therefore we */ /* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */ /* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */ /* cosmopolitan uses x28 as the tls register b/c apple */
#define errno \ #define errno \
(*({ \ (*__extension__({ \
errno_t *__ep; \ errno_t *__ep; \
asm("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \ __asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
__ep; \ __ep; \
})) }))
#else #else
#define errno (*__errno_location()) #define errno (*__errno_location())

View file

@ -2,8 +2,7 @@
#define COSMOPOLITAN_LIBC_FMT_DIVMOD10_H_ #define COSMOPOLITAN_LIBC_FMT_DIVMOD10_H_
forceinline uint64_t __divmod10(uint64_t __x, unsigned *__r) { forceinline uint64_t __divmod10(uint64_t __x, unsigned *__r) {
#if defined(__STRICT_ANSI__) || !defined(__GNUC__) || \ #if !defined(__GNUC__) || (defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__))
(defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__))
*__r = __x % 10; *__r = __x % 10;
return __x / 10; return __x / 10;
#else #else

View file

@ -16,8 +16,7 @@
#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L #if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x) #define typeof(x) decltype(x)
#elif (defined(__STRICT_ANSI__) || !defined(__GNUC__)) && \ #elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
__STDC_VERSION__ + 0 < 201112
#define typeof(x) __typeof(x) #define typeof(x) __typeof(x)
#endif #endif
@ -27,7 +26,7 @@
#endif /* C++11 */ #endif /* C++11 */
#else /* __cplusplus */ #else /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112 #if __STDC_VERSION__ + 0 < 201112
#if __GNUC__ + _MSC_VER + 0 && !defined(__STRICT_ANSI__) #if __GNUC__ + _MSC_VER + 0
#define _Alignof(x) __alignof(x) #define _Alignof(x) __alignof(x)
#else #else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x) #define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
@ -36,7 +35,7 @@
#endif /* __cplusplus */ #endif /* __cplusplus */
#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901 #if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
#if !defined(__STRICT_ANSI__) && (defined(__GNUC__) || defined(_MSC_VER)) #if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline #define inline __inline
#else #else
#define inline #define inline
@ -49,7 +48,7 @@
#endif #endif
#if __STDC_VERSION__ + 0 < 201112 #if __STDC_VERSION__ + 0 < 201112
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) #ifdef __GNUC__
#define _Alignas(x) __attribute__((__aligned__(x))) #define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x)) #define _Alignas(x) __declspec(align(x))
@ -58,17 +57,15 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#define __builtin_unreachable() __assume(false) #define __builtin_unreachable() __assume(false)
#elif defined(__STRICT_ANSI__) || \ #elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
!((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \ defined(__clang__) || defined(__INTEL_COMPILER) || \
defined(__clang__) || defined(__INTEL_COMPILER) || \ __has_builtin(__builtin_unreachable))
__has_builtin(__builtin_unreachable))
#define __builtin_unreachable() \ #define __builtin_unreachable() \
for (;;) { \ for (;;) { \
} }
#endif #endif
#if defined(__STRICT_ANSI__) || \ #if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
(!defined(__llvm__) && !__has_builtin(__builtin_assume))
#define __builtin_assume(x) \ #define __builtin_assume(x) \
do { \ do { \
if (!(x)) __builtin_unreachable(); \ if (!(x)) __builtin_unreachable(); \
@ -134,9 +131,7 @@ typedef __UINTMAX_TYPE__ uintmax_t;
typedef long double max_align_t; typedef long double max_align_t;
#ifdef _COSMO_SOURCE #ifdef _COSMO_SOURCE
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || \ #if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
defined(__llvm__)) && \
!defined(__STRICT_ANSI__)
typedef signed __int128 int128_t; typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t; typedef unsigned __int128 uint128_t;
#endif #endif
@ -169,11 +164,7 @@ typedef struct {
#define interruptfn nocallersavedregisters forcealignargpointer #define interruptfn nocallersavedregisters forcealignargpointer
#ifndef pureconst #ifndef pureconst
#ifndef __STRICT_ANSI__
#define pureconst __attribute__((__const__)) #define pureconst __attribute__((__const__))
#else
#define pureconst
#endif
#endif #endif
#ifndef forcealign #ifndef forcealign
@ -181,15 +172,9 @@ typedef struct {
#endif #endif
#define thatispacked __attribute__((__packed__)) #define thatispacked __attribute__((__packed__))
#ifndef __STRICT_ANSI__
#define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1))) #define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n) __attribute__((__format__(__gnu_scanf__, n, n + 1))) #define scanfesque(n) __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0))) #define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))
#else
#define printfesque(n)
#define scanfesque(n)
#define strftimeesque(n)
#endif
#ifndef privileged #ifndef privileged
#define privileged \ #define privileged \
@ -197,8 +182,7 @@ typedef struct {
#endif #endif
#ifndef wontreturn #ifndef wontreturn
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__noreturn__) || \
(__has_attribute(__noreturn__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__)) #define wontreturn __attribute__((__noreturn__))
#else #else
@ -207,8 +191,7 @@ typedef struct {
#endif #endif
#ifndef nosideeffect #ifndef nosideeffect
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__pure__) || \
(__has_attribute(__pure__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
#define nosideeffect __attribute__((__pure__)) #define nosideeffect __attribute__((__pure__))
#else #else
@ -219,9 +202,8 @@ typedef struct {
#ifndef dontinline #ifndef dontinline
#ifdef _MSC_VER #ifdef _MSC_VER
#define dontinline __declspec(noinline) #define dontinline __declspec(noinline)
#elif !defined(__STRICT_ANSI__) && \ #elif (__has_attribute(__noinline__) || \
(__has_attribute(__noinline__) || \ (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__)) #define dontinline __attribute__((__noinline__))
#else #else
#define dontinline #define dontinline
@ -229,8 +211,7 @@ typedef struct {
#endif #endif
#ifndef dontclone #ifndef dontclone
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__noclone__) || \
(__has_attribute(__noclone__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__)) #define dontclone __attribute__((__noclone__))
#else #else
@ -242,8 +223,7 @@ typedef struct {
#ifdef __cplusplus #ifdef __cplusplus
#define forceinline inline #define forceinline inline
#else #else
#if !defined(__STRICT_ANSI__) && \ #if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \ #if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
!defined(__cplusplus) || \ !defined(__cplusplus) || \
(defined(__clang__) && \ (defined(__clang__) && \
@ -267,8 +247,7 @@ typedef struct {
#endif /* forceinline */ #endif /* forceinline */
#ifndef __wur #ifndef __wur
#if !defined(__STRICT_ANSI__) && \ #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
__has_attribute(__warn_unused_result__)) __has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__)) #define __wur __attribute__((__warn_unused_result__))
#else #else
@ -277,8 +256,7 @@ typedef struct {
#endif #endif
#ifndef nullterminated #ifndef nullterminated
#if !defined(__STRICT_ANSI__) && \ #if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
(__has_attribute(__sentinel__) || __GNUC__ + 0 >= 4)
#define nullterminated(x) __attribute__((__sentinel__ x)) #define nullterminated(x) __attribute__((__sentinel__ x))
#else #else
#define nullterminated(x) #define nullterminated(x)
@ -295,8 +273,7 @@ typedef struct {
#endif #endif
#ifndef externinline #ifndef externinline
#if !defined(__STRICT_ANSI__) && \ #if (!defined(__cplusplus) || \
(!defined(__cplusplus) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \ (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
(defined(__clang__) && \ (defined(__clang__) && \
(defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))) (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
@ -311,8 +288,7 @@ typedef struct {
#endif #endif
#ifndef relegated #ifndef relegated
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__cold__) || \
(__has_attribute(__cold__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define relegated __attribute__((__cold__)) #define relegated __attribute__((__cold__))
#else #else
@ -320,8 +296,7 @@ typedef struct {
#endif #endif
#endif #endif
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__warning__) || \
(__has_attribute(__warning__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define warnifused(s) __attribute__((__warning__(s))) #define warnifused(s) __attribute__((__warning__(s)))
#else #else
@ -329,8 +304,7 @@ typedef struct {
#endif #endif
#ifndef firstclass #ifndef firstclass
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__hot__) || \
(__has_attribute(__hot__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define firstclass __attribute__((__hot__)) #define firstclass __attribute__((__hot__))
#else #else
@ -339,8 +313,7 @@ typedef struct {
#endif #endif
#ifndef paramsnonnull #ifndef paramsnonnull
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__nonnull__) || \
(__has_attribute(__nonnull__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs)) #define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else #else
@ -355,7 +328,7 @@ typedef struct {
#endif #endif
#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict) #if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
#if !defined(__STRICT_ANSI__) && !defined(__cplusplus) && \ #if !defined(__cplusplus) && \
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER)) ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
#define restrict __restrict__ #define restrict __restrict__
#else #else
@ -365,8 +338,7 @@ typedef struct {
#endif #endif
#ifndef dontcallback #ifndef dontcallback
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__leaf__) || \
(__has_attribute(__leaf__) || \
(!defined(__llvm__) && \ (!defined(__llvm__) && \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406)) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__)) #define dontcallback __attribute__((__leaf__))
@ -376,8 +348,8 @@ typedef struct {
#endif #endif
#ifndef dontthrow #ifndef dontthrow
#if defined(__cplusplus) && !defined(__STRICT_ANSI__) && \ #if defined(__cplusplus) && \
(__has_attribute(dontthrow) || \ (__has_attribute(dontthrow) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__)) #define dontthrow __attribute__((__nothrow__))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@ -388,8 +360,7 @@ typedef struct {
#endif #endif
#ifndef returnstwice #ifndef returnstwice
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__returns_twice__) || \
(__has_attribute(__returns_twice__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
#define returnstwice __attribute__((__returns_twice__)) #define returnstwice __attribute__((__returns_twice__))
#else #else
@ -398,8 +369,7 @@ typedef struct {
#endif #endif
#ifndef nodebuginfo #ifndef nodebuginfo
#if !defined(__STRICT_ANSI__) && \ #if __has_attribute(__nodebug__) || defined(__llvm__)
(__has_attribute(__nodebug__) || defined(__llvm__))
#define nodebuginfo __attribute__((__nodebug__)) #define nodebuginfo __attribute__((__nodebug__))
#else #else
#define nodebuginfo #define nodebuginfo
@ -414,8 +384,7 @@ typedef struct {
#endif #endif
#ifndef returnsnonnull #ifndef returnsnonnull
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__returns_nonnull__) || \
(__has_attribute(__returns_nonnull__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsnonnull __attribute__((__returns_nonnull__)) #define returnsnonnull __attribute__((__returns_nonnull__))
#else #else
@ -423,8 +392,7 @@ typedef struct {
#endif #endif
#endif #endif
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__assume_aligned__) || \
(__has_attribute(__assume_aligned__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsaligned(x) __attribute__((__assume_aligned__ x)) #define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else #else
@ -432,8 +400,7 @@ typedef struct {
#endif #endif
#ifndef returnspointerwithnoaliases #ifndef returnspointerwithnoaliases
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__malloc__) || \
(__has_attribute(__malloc__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnspointerwithnoaliases __attribute__((__malloc__)) #define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@ -444,8 +411,7 @@ typedef struct {
#endif #endif
#ifndef attributeallocsize #ifndef attributeallocsize
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__alloc_size__) || \
(__has_attribute(__alloc_size__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocsize(x) __attribute__((__alloc_size__ x)) #define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else #else
@ -454,8 +420,7 @@ typedef struct {
#endif #endif
#ifndef attributeallocalign #ifndef attributeallocalign
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__alloc_align__) || \
(__has_attribute(__alloc_align__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocalign(x) __attribute__((__alloc_align__ x)) #define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else #else
@ -478,8 +443,7 @@ typedef struct {
#ifdef _COSMO_SOURCE #ifdef _COSMO_SOURCE
#ifndef dontinstrument #ifndef dontinstrument
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__no_instrument_function__) || \
(__has_attribute(__no_instrument_function__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \ #if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
__has_attribute(__patchable_function_entry__) __has_attribute(__patchable_function_entry__)
@ -495,8 +459,7 @@ typedef struct {
#endif #endif
#ifndef mayalias #ifndef mayalias
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__may_alias__) || \
(__has_attribute(__may_alias__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__)) #define mayalias __attribute__((__may_alias__))
#else #else
@ -505,35 +468,26 @@ typedef struct {
#endif #endif
#ifndef dontoptimize #ifndef dontoptimize
#ifndef __STRICT_ANSI__
#if defined(__llvm__) || __has_attribute(__optnone__) #if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__)) #define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \ #elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__) __has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0))) #define dontoptimize __attribute__((__optimize__(0)))
#endif #endif
#else
#define dontoptimize
#endif
#endif #endif
#ifndef optimizesize #ifndef optimizesize
#ifndef __STRICT_ANSI__
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \ #if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__) __has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s"))) #define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__) #elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__)) #define optimizesize __attribute__((__optnone__))
#endif #endif
#else
#define optimizesize
#endif
#endif #endif
#ifndef optimizespeed #ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */ /* warning: corrupts frame pointer; only use on leaf functions */
#if !defined(__STRICT_ANSI__) && \ #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__)) __has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3))) #define optimizespeed __attribute__((__optimize__(3)))
#else #else
@ -542,8 +496,7 @@ typedef struct {
#endif #endif
#ifndef unrollloops #ifndef unrollloops
#if !defined(__STRICT_ANSI__) && \ #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__)) __has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops"))) #define unrollloops __attribute__((__optimize__("unroll-loops")))
#else #else
@ -552,8 +505,7 @@ typedef struct {
#endif #endif
#ifndef _Microarchitecture #ifndef _Microarchitecture
#if !defined(__STRICT_ANSI__) && \ #if (__has_attribute(__target__) || \
(__has_attribute(__target__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404) (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march))) #define _Microarchitecture(march) __attribute__((__target__(march)))
#else #else
@ -572,64 +524,48 @@ typedef struct {
#endif #endif
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \ #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
__has_attribute(__no_sanitize_address__)) && \ __has_attribute(__no_sanitize_address__))
!defined(__STRICT_ANSI__)
#define dontasan __attribute__((__no_sanitize_address__)) #define dontasan __attribute__((__no_sanitize_address__))
#else #else
#define dontasan #define dontasan
#endif #endif
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \ #if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
__has_attribute(__no_sanitize_undefined__)) && \ __has_attribute(__no_sanitize_undefined__))
!defined(__STRICT_ANSI__)
#define dontubsan __attribute__((__no_sanitize_undefined__)) #define dontubsan __attribute__((__no_sanitize_undefined__))
#else #else
#define dontubsan #define dontubsan
#endif #endif
#ifdef __STRICT_ANSI__
void abort(void) wontreturn;
#define notpossible abort()
#else
#ifdef __x86_64__ #ifdef __x86_64__
#define notpossible \ #define notpossible \
do { \ do { \
asm("nop\n\t" \ __asm__("nop\n\t" \
"ud2\n\t" \ "ud2\n\t" \
"nop"); \ "nop"); \
__builtin_unreachable(); \ __builtin_unreachable(); \
} while (0) } while (0)
#elif defined(__aarch64__) #elif defined(__aarch64__)
#define notpossible \ #define notpossible \
do { \ do { \
asm("udf\t#0\n\t" \ __asm__("udf\t#0\n\t" \
"nop"); \ "nop"); \
__builtin_unreachable(); \ __builtin_unreachable(); \
} while (0) } while (0)
#else #else
#define notpossible __builtin_trap() #define notpossible __builtin_trap()
#endif #endif
#endif
#define donothing \ #define donothing \
do { \ do { \
} while (0) } while (0)
#ifndef __STRICT_ANSI__
#define textstartup _Section(".text.startup") #define textstartup _Section(".text.startup")
#define textexit _Section(".text.exit") #define textexit _Section(".text.exit")
#define textreal _Section(".text.real") #define textreal _Section(".text.real")
#define texthead _Section(".text.head") #define texthead _Section(".text.head")
#define textwindows _Section(".text.windows") #define textwindows _Section(".text.windows")
#define antiquity _Section(".text.antiquity") #define antiquity _Section(".text.antiquity")
#else
#define textstartup
#define textexit
#define textreal
#define texthead
#define textwindows
#define antiquity
#endif
#ifdef __llvm__ #ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y)) #define __builtin_ia32_movntdq(x, y) (*(x) = (y))
@ -660,66 +596,50 @@ void abort(void) wontreturn;
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */ #pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif #endif
#ifndef __STRICT_ANSI__
#ifdef __x86_64__ #ifdef __x86_64__
#define DebugBreak() asm("int3") #define DebugBreak() __asm__("int3")
#else #else
#define DebugBreak() __builtin_trap() #define DebugBreak() __builtin_trap()
#endif #endif
#else
#define DebugBreak() (void)0
#endif
#endif /* _COSMO_SOURCE */ #endif /* _COSMO_SOURCE */
#ifndef __STRICT_ANSI__ #define __veil(CONSTRAINT, EXPRESSION) \
#define __veil(CONSTRAINT, EXPRESSION) \ __extension__({ \
({ \ autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \ __asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
asm("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \ VeiledValue; \
VeiledValue; \
}) })
#else
#define __veil(CONSTRAINT, EXPRESSION) (EXPRESSION)
#endif
#ifndef __STRICT_ANSI__ #define __conceal(CONSTRAINT, EXPRESSION) \
#define __conceal(CONSTRAINT, EXPRESSION) \ __extension__({ \
({ \ autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \ __asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
asm volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \ VeiledValue; \
VeiledValue; \
}) })
#else
#define __conceal(CONSTRAINT, EXPRESSION) (EXPRESSION)
#endif
#ifndef __STRICT_ANSI__ #define __expropriate(EXPRESSION) \
#define __expropriate(EXPRESSION) \ __extension__({ \
({ \ __asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
asm volatile("" ::"g"(EXPRESSION) : "memory"); \ 0; \
0; \
}) })
#else
#define __expropriate(EXPRESSION) (EXPRESSION)
#endif
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__) #if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \ #define __yoink(SYMBOL) \
asm(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL)) __asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
#elif defined(__aarch64__) #elif defined(__aarch64__)
#define __yoink(SYMBOL) \ #define __yoink(SYMBOL) \
asm(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL)) __asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
#else #else
#define __yoink(SYMBOL) (void)0 #define __yoink(SYMBOL) (void)0
#endif #endif
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__) #if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \ #define __static_yoink(SYMBOLSTR) \
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous") __asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#elif defined(__aarch64__) #elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \ #define __static_yoink(SYMBOLSTR) \
asm(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous") __asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
#else #else
#define __static_yoink(SYMBOLSTR) #define __static_yoink(SYMBOLSTR)
#endif #endif

View file

@ -10,8 +10,7 @@
#endif #endif
#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && \ #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && \
!defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && \ !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && !defined(_BSD_SOURCE)
!defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__)
#define _BSD_SOURCE 1 #define _BSD_SOURCE 1
#define _XOPEN_SOURCE 700 #define _XOPEN_SOURCE 700
#endif #endif

View file

@ -25,33 +25,33 @@ forceinline char *__stpcpy(char *d, const char *s) {
} }
forceinline void *__repstosb(void *di, char al, size_t cx) { forceinline void *__repstosb(void *di, char al, size_t cx) {
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) #if defined(__x86__) && defined(__GNUC__)
asm("rep stosb" __asm__("rep stosb"
: "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di) : "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di)
: "0"(di), "1"(cx), "a"(al)); : "0"(di), "1"(cx), "a"(al));
return di; return di;
#else #else
char *d = di; char *d = di;
while (cx--) { while (cx--) {
*d++ = al; *d++ = al;
asm volatile("" ::: "memory"); __asm__ volatile("" ::: "memory");
} }
return (void *)d; return (void *)d;
#endif #endif
} }
forceinline void *__repmovsb(void *di, const void *si, size_t cx) { forceinline void *__repmovsb(void *di, const void *si, size_t cx) {
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__) #if defined(__x86__) && defined(__GNUC__)
asm("rep movsb" __asm__("rep movsb"
: "=D"(di), "=S"(si), "=c"(cx), "=m"(*(char(*)[cx])di) : "=D"(di), "=S"(si), "=c"(cx), "=m"(*(char(*)[cx])di)
: "0"(di), "1"(si), "2"(cx), "m"(*(char(*)[cx])si)); : "0"(di), "1"(si), "2"(cx), "m"(*(char(*)[cx])si));
return di; return di;
#else #else
char *d = di; char *d = di;
const char *s = si; const char *s = si;
while (cx--) { while (cx--) {
*d++ = *s++; *d++ = *s++;
asm volatile("" ::: "memory"); __asm__ volatile("" ::: "memory");
} }
return (void *)d; return (void *)d;
#endif #endif
@ -61,7 +61,7 @@ forceinline void *__mempcpy(void *d, const void *s, size_t n) {
size_t i; size_t i;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
((char *)d)[i] = ((const char *)s)[i]; ((char *)d)[i] = ((const char *)s)[i];
asm volatile("" ::: "memory"); __asm__ volatile("" ::: "memory");
} }
return (char *)d + n; return (char *)d + n;
} }

View file

@ -1,7 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_NT_TEB_H_ #ifndef COSMOPOLITAN_LIBC_NT_TEB_H_
#define COSMOPOLITAN_LIBC_NT_TEB_H_ #define COSMOPOLITAN_LIBC_NT_TEB_H_
#include "libc/nt/struct/peb.h" #include "libc/nt/struct/peb.h"
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) #ifdef __GNUC__
/* /*
* These macros address directly into NT's TEB a.k.a. TIB * These macros address directly into NT's TEB a.k.a. TIB
@ -21,5 +21,5 @@
#define _NtGetRpc() ((void *)*(__seg_gs uintptr_t *)0x50) #define _NtGetRpc() ((void *)*(__seg_gs uintptr_t *)0x50)
#define _NtGetTls() ((void *)*(__seg_gs uintptr_t *)0x58) #define _NtGetTls() ((void *)*(__seg_gs uintptr_t *)0x58)
#endif /* __GNUC__ && !__STRICT_ANSI__ */ #endif /* __GNUC__ */
#endif /* COSMOPOLITAN_LIBC_NT_TEB_H_ */ #endif /* COSMOPOLITAN_LIBC_NT_TEB_H_ */

View file

@ -2,8 +2,7 @@
#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_ #define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
#ifdef __x86_64__ #ifdef __x86_64__
#if !defined(__STRICT_ANSI__) && \ #if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
(__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
(__has_attribute(__ms_abi__) || defined(__llvm__))) (__has_attribute(__ms_abi__) || defined(__llvm__)))
/** /**
* Defines function as using Microsoft x64 calling convention. * Defines function as using Microsoft x64 calling convention.

View file

@ -8,13 +8,13 @@ bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__) #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10) #define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
#define GetNtMajorVersion() \ #define GetNtMajorVersion() \
({ \ __extension__({ \
uintptr_t __x; \ uintptr_t __x; \
asm("mov\t%%gs:96,%q0\r\n" \ __asm__("mov\t%%gs:96,%q0\r\n" \
"mov\t280(%q0),%b0" \ "mov\t280(%q0),%b0" \
: "=q"(__x)); \ : "=q"(__x)); \
(unsigned char)__x; \ (unsigned char)__x; \
}) })
#endif #endif

View file

@ -56,7 +56,7 @@
#define _STACK_EXTRA "" #define _STACK_EXTRA ""
#endif #endif
#if defined(__GNUC__) && defined(__ELF__) && !defined(__STRICT_ANSI__) #if defined(__GNUC__) && defined(__ELF__)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
extern char ape_stack_prot[] __attribute__((__weak__)); extern char ape_stack_prot[] __attribute__((__weak__));

View file

@ -3,7 +3,7 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/thread/tls.h" #include "libc/thread/tls.h"
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__) #if defined(__GNUC__) && defined(__x86_64__)
/** /**
* Returns location of thread information block. * Returns location of thread information block.
@ -14,9 +14,9 @@ COSMOPOLITAN_C_START_
forceinline struct CosmoTib *__get_tls_privileged(void) { forceinline struct CosmoTib *__get_tls_privileged(void) {
char *tib, *lin = (char *)0x30; char *tib, *lin = (char *)0x30;
if (IsNetbsd() || IsOpenbsd()) { if (IsNetbsd() || IsOpenbsd()) {
asm("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory"); __asm__("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
} else { } else {
asm("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory"); __asm__("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
if (IsWindows()) { if (IsWindows()) {
tib = *(char **)(tib + 0x1480 + __tls_index * 8); tib = *(char **)(tib + 0x1480 + __tls_index * 8);
} }
@ -26,13 +26,13 @@ forceinline struct CosmoTib *__get_tls_privileged(void) {
forceinline struct CosmoTib *__get_tls_win32(void) { forceinline struct CosmoTib *__get_tls_win32(void) {
char *tib, *lin = (char *)0x30; char *tib, *lin = (char *)0x30;
asm("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory"); __asm__("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
tib = *(char **)(tib + 0x1480 + __tls_index * 8); tib = *(char **)(tib + 0x1480 + __tls_index * 8);
return (struct CosmoTib *)tib; return (struct CosmoTib *)tib;
} }
forceinline void __set_tls_win32(void *tls) { forceinline void __set_tls_win32(void *tls) {
asm("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tls)); __asm__("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tls));
} }
#elif defined(__aarch64__) #elif defined(__aarch64__)