cosmopolitan/libc/integral/c.inc

693 lines
19 KiB
PHP
Raw Normal View History

2020-06-15 14:18:57 +00:00
#if __GNUC__ + 0 < 2
#define __attribute__(x)
#endif
#ifndef __cplusplus
#define COSMOPOLITAN_C_START_
#define COSMOPOLITAN_C_END_
#define COSMOPOLITAN_CXX_START_
#define COSMOPOLITAN_CXX_END_
#define COSMOPOLITAN_CXX_USING_
#endif
2020-06-15 14:18:57 +00:00
#ifndef __ia16__
#define __far
#endif
#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x)
2024-02-27 12:09:49 +00:00
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
2020-06-15 14:18:57 +00:00
#define typeof(x) __typeof(x)
#endif
#ifdef __cplusplus
#if __cplusplus >= 201103L
#define _Alignof(x) alignof(x)
#endif /* C++11 */
#else /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112
2024-02-27 12:09:49 +00:00
#if __GNUC__ + _MSC_VER + 0
2020-06-15 14:18:57 +00:00
#define _Alignof(x) __alignof(x)
#else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
#endif /* GNU/MSVC/!ANSI */
#endif /* C11 */
#endif /* __cplusplus */
#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
2024-02-27 12:09:49 +00:00
#if defined(__GNUC__) || defined(_MSC_VER)
2020-06-15 14:18:57 +00:00
#define inline __inline
#else
#define inline
#define __inline
#endif
#endif
#ifdef __chibicc__
#define __extension__
#endif
2020-06-15 14:18:57 +00:00
#if __STDC_VERSION__ + 0 < 201112
2024-02-27 12:09:49 +00:00
#ifdef __GNUC__
2020-06-15 14:18:57 +00:00
#define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x))
#endif
#endif
#ifdef _MSC_VER
#define __builtin_unreachable() __assume(false)
2024-02-27 12:09:49 +00:00
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
defined(__clang__) || defined(__INTEL_COMPILER) || \
__has_builtin(__builtin_unreachable))
2020-06-15 14:18:57 +00:00
#define __builtin_unreachable() \
for (;;) { \
}
#endif
2024-02-27 12:09:49 +00:00
#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
2020-06-15 14:18:57 +00:00
#define __builtin_assume(x) \
do { \
if (!(x)) __builtin_unreachable(); \
} while (0)
#endif
#if __STDC_VERSION__ + 0 < 201112
#define _Atomic(TYPE) TYPE volatile
2020-06-15 14:18:57 +00:00
#endif
#ifdef __llvm__
#define __gnu_printf__ __printf__
#define __gnu_scanf__ __scanf__
#endif
#if __cplusplus + 0 >= 201103L
#define NULL nullptr
#elif !defined(__cplusplus)
#define NULL ((void *)0)
#else
#define NULL 0
#endif
#ifndef __cplusplus
#if defined(__GNUC__) && !defined(__llvm__)
2023-06-18 12:39:31 +00:00
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
2020-06-15 14:18:57 +00:00
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#if defined(__GNUC__) && !defined(__llvm__)
2023-06-18 12:39:31 +00:00
#pragma GCC pop_options
#endif
2023-06-18 12:39:31 +00:00
#endif /* __cplusplus */
2020-06-15 14:18:57 +00:00
#ifndef __COSMOCC__
#include "libc/stdbool.h"
#endif
#define _LIBCPP_STDINT_H
2020-06-15 14:18:57 +00:00
typedef int errno_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
2020-06-15 14:18:57 +00:00
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;
2020-06-15 14:18:57 +00:00
#define __DEFINED_max_align_t
typedef long double max_align_t;
#ifdef _COSMO_SOURCE
2024-02-27 12:09:49 +00:00
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
2020-06-15 14:18:57 +00:00
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
#endif /* _COSMO_SOURCE */
2023-10-09 21:39:02 +00:00
#ifndef __AXDX_T
#define __AXDX_T
typedef struct {
intptr_t ax, dx;
} axdx_t;
2023-10-09 21:39:02 +00:00
#endif
#ifndef __chibicc__
2020-06-15 14:18:57 +00:00
#define va_list __builtin_va_list
#define va_arg(ap, type) __builtin_va_arg(ap, type)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#define va_end(ap) __builtin_va_end(ap)
#define va_start(ap, last) __builtin_va_start(ap, last)
2020-12-01 11:43:40 +00:00
#else
#include "libc/integral/lp64arg.inc"
#endif
2020-06-15 14:18:57 +00:00
#define libcesque dontthrow dontcallback
2020-06-15 14:18:57 +00:00
#define memcpyesque libcesque
#define strlenesque libcesque nosideeffect paramsnonnull()
#define vallocesque \
libcesque __wur returnsaligned((65536)) returnspointerwithnoaliases
#define reallocesque libcesque returnsaligned((16))
2020-06-15 14:18:57 +00:00
#define mallocesque reallocesque returnspointerwithnoaliases
#define interruptfn nocallersavedregisters forcealignargpointer
#ifndef pureconst
#define pureconst __attribute__((__const__))
#endif
#ifndef forcealign
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
2020-06-15 14:18:57 +00:00
#endif
#define thatispacked __attribute__((__packed__))
#define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n) __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))
#ifndef privileged
#define privileged \
_Section(".privileged") dontinline dontinstrument dontubsan dontasan
2020-06-15 14:18:57 +00:00
#endif
#ifndef wontreturn
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__noreturn__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__))
2020-06-15 14:18:57 +00:00
#else
#define wontreturn
2020-06-15 14:18:57 +00:00
#endif
#endif
#ifndef nosideeffect
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__pure__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
2020-06-15 14:18:57 +00:00
#define nosideeffect __attribute__((__pure__))
#else
#define nosideeffect
#endif
#endif
#ifndef dontinline
#ifdef _MSC_VER
#define dontinline __declspec(noinline)
2024-02-27 12:09:49 +00:00
#elif (__has_attribute(__noinline__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__))
2020-06-15 14:18:57 +00:00
#else
#define dontinline
2020-06-15 14:18:57 +00:00
#endif
#endif
#ifndef dontclone
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__noclone__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__))
#else
#define dontclone
#endif
#endif
2020-06-15 14:18:57 +00:00
#ifndef forceinline
#ifdef __cplusplus
#define forceinline inline
#else
2024-02-27 12:09:49 +00:00
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
!defined(__cplusplus) || \
(defined(__clang__) && \
2020-06-15 14:18:57 +00:00
(defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define forceinline \
static __inline __attribute__((__always_inline__, __gnu_inline__, \
__no_instrument_function__, __unused__))
#else
#define forceinline \
static __inline __attribute__((__always_inline__, \
__no_instrument_function__, __unused__))
2020-06-15 14:18:57 +00:00
#endif /* __GNUC_STDC_INLINE__ */
#endif /* GCC >= 4.3 */
#elif defined(_MSC_VER)
#define forceinline __forceinline
#else
2020-12-01 11:43:40 +00:00
#define forceinline static inline
2020-06-15 14:18:57 +00:00
#endif /* !ANSI && GCC >= 3.2 */
#endif /* __cplusplus */
#endif /* forceinline */
#ifndef __wur
2024-02-27 12:09:49 +00:00
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
__has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__))
2020-06-15 14:18:57 +00:00
#else
#define __wur
2020-06-15 14:18:57 +00:00
#endif
#endif
#ifndef nullterminated
2024-02-27 12:09:49 +00:00
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
2020-06-15 14:18:57 +00:00
#define nullterminated(x) __attribute__((__sentinel__ x))
#else
#define nullterminated(x)
#endif
#endif
#ifndef flattenout
#if __has_attribute(__flatten__) || \
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && !defined(__llvm__))
2020-06-15 14:18:57 +00:00
#define flattenout __attribute__((__flatten__))
#else
#define flattenout
#endif
#endif
#ifndef externinline
2024-02-27 12:09:49 +00:00
#if (!defined(__cplusplus) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
(defined(__clang__) && \
2020-06-15 14:18:57 +00:00
(defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define externinline extern __inline __attribute__((__gnu_inline__))
#else
#define externinline extern __inline __attribute__((__always_inline__))
#endif
#else
#define externinline inline
#endif
#endif
#ifndef relegated
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__cold__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
2020-06-15 14:18:57 +00:00
#define relegated __attribute__((__cold__))
#else
#define relegated
#endif
#endif
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__warning__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
2020-06-15 14:18:57 +00:00
#define warnifused(s) __attribute__((__warning__(s)))
#else
#define warnifused(s)
#endif
#ifndef firstclass
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__hot__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
2020-06-15 14:18:57 +00:00
#define firstclass __attribute__((__hot__))
#else
#define firstclass
#endif
#endif
#ifndef paramsnonnull
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__nonnull__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
2020-06-15 14:18:57 +00:00
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else
#define paramsnonnull(opt_1idxs)
#endif
#endif
#if __STDC_VERSION__ + 0 >= 199901L
#define hasatleast static
#else
#define hasatleast
#endif
#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
2024-02-27 12:09:49 +00:00
#if !defined(__cplusplus) && \
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
2020-06-15 14:18:57 +00:00
#define restrict __restrict__
#else
#define restrict
#define __restrict
#endif
#endif
#ifndef dontcallback
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__leaf__) || \
(!defined(__llvm__) && \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__))
2020-06-15 14:18:57 +00:00
#else
#define dontcallback
2020-06-15 14:18:57 +00:00
#endif
#endif
#ifndef dontthrow
2024-02-27 12:09:49 +00:00
#if defined(__cplusplus) && \
(__has_attribute(dontthrow) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__))
2020-06-15 14:18:57 +00:00
#elif defined(_MSC_VER)
#define dontthrow __declspec(nothrow)
2020-06-15 14:18:57 +00:00
#else
#define dontthrow
2020-06-15 14:18:57 +00:00
#endif
#endif
#ifndef returnstwice
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__returns_twice__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
2020-06-15 14:18:57 +00:00
#define returnstwice __attribute__((__returns_twice__))
#else
#define returnstwice
#endif
#endif
#ifndef nodebuginfo
2024-02-27 12:09:49 +00:00
#if __has_attribute(__nodebug__) || defined(__llvm__)
2020-06-15 14:18:57 +00:00
#define nodebuginfo __attribute__((__nodebug__))
#else
#define nodebuginfo
#endif
#endif
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
2020-06-15 14:18:57 +00:00
__has_attribute(__force_align_arg_pointer__)
#define forcealignargpointer __attribute__((__force_align_arg_pointer__))
#else
#define forcealignargpointer "need modern compiler"
#endif
#ifndef returnsnonnull
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__returns_nonnull__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
2020-06-15 14:18:57 +00:00
#define returnsnonnull __attribute__((__returns_nonnull__))
#else
#define returnsnonnull
#endif
#endif
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__assume_aligned__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
2020-06-15 14:18:57 +00:00
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else
#define returnsaligned(x)
#endif
#ifndef returnspointerwithnoaliases
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__malloc__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
2020-06-15 14:18:57 +00:00
#define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER)
#define returnspointerwithnoaliases __declspec(allocator)
#else
#define returnspointerwithnoaliases
#endif
#endif
#ifndef attributeallocsize
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__alloc_size__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
2020-06-15 14:18:57 +00:00
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else
#define attributeallocsize(x)
#endif
#endif
#ifndef attributeallocalign
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__alloc_align__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
2020-06-15 14:18:57 +00:00
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else
#define attributeallocalign(x)
#endif
#endif
#if __cplusplus + 0 >= 201103L
#define autotype(x) auto
#elif ((__has_builtin(__auto_type) || defined(__llvm__) || \
2020-12-09 12:00:48 +00:00
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) && \
!defined(__chibicc__))
2020-06-15 14:18:57 +00:00
#define autotype(x) __auto_type
#else
#define autotype(x) typeof(x)
#endif
#define offsetof(type, member) __builtin_offsetof(type, member)
#ifdef _COSMO_SOURCE
#ifndef dontinstrument
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__no_instrument_function__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
__has_attribute(__patchable_function_entry__)
#define dontinstrument \
__attribute__((__no_instrument_function__, \
__patchable_function_entry__(0, 0)))
#else
#define dontinstrument __attribute__((__no_instrument_function__))
#endif
#else
#define dontinstrument
#endif
#endif
#ifndef mayalias
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__may_alias__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__))
#else
#define mayalias
#endif
#endif
#ifndef dontoptimize
#if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0)))
#endif
#endif
#ifndef optimizesize
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__))
#endif
#endif
#ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */
2024-02-27 12:09:49 +00:00
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3)))
#else
#define optimizespeed
#endif
#endif
#ifndef unrollloops
2024-02-27 12:09:49 +00:00
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
__has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops")))
#else
#define unrollloops
#endif
#endif
#ifndef _Microarchitecture
2024-02-27 12:09:49 +00:00
#if (__has_attribute(__target__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define _Microarchitecture(march)
#endif
#endif
2023-05-02 02:43:59 +00:00
#ifdef __x86_64__
2020-06-15 14:18:57 +00:00
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
2023-05-02 02:43:59 +00:00
#else
#define nocallersavedregisters
#endif
2020-06-15 14:18:57 +00:00
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
2024-02-27 12:09:49 +00:00
__has_attribute(__no_sanitize_address__))
#define dontasan __attribute__((__no_sanitize_address__))
#else
#define dontasan
#endif
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
2024-02-27 12:09:49 +00:00
__has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__))
2021-05-16 18:16:28 +00:00
#else
#define dontubsan
2021-05-16 18:16:28 +00:00
#endif
2023-05-02 02:43:59 +00:00
#ifdef __x86_64__
#define notpossible \
do { \
2024-02-27 12:09:49 +00:00
__asm__("nop\n\t" \
"ud2\n\t" \
"nop"); \
__builtin_unreachable(); \
} while (0)
#elif defined(__aarch64__)
#define notpossible \
do { \
2024-02-27 12:09:49 +00:00
__asm__("udf\t#0\n\t" \
"nop"); \
__builtin_unreachable(); \
} while (0)
2023-05-02 02:43:59 +00:00
#else
#define notpossible __builtin_trap()
#endif
2020-06-15 14:18:57 +00:00
#define donothing \
do { \
} while (0)
#define textstartup _Section(".text.startup")
#define textexit _Section(".text.exit")
2020-06-15 14:18:57 +00:00
#define textreal _Section(".text.real")
#define texthead _Section(".text.head")
2020-06-15 14:18:57 +00:00
#define textwindows _Section(".text.windows")
#define antiquity _Section(".text.antiquity")
Make numerous improvements - Python static hello world now 1.8mb - Python static fully loaded now 10mb - Python HTTPS client now uses MbedTLS - Python REPL now completes import stmts - Increase stack size for Python for now - Begin synthesizing posixpath and ntpath - Restore Python \N{UNICODE NAME} support - Restore Python NFKD symbol normalization - Add optimized code path for Intel SHA-NI - Get more Python unit tests passing faster - Get Python help() pagination working on NT - Python hashlib now supports MbedTLS PBKDF2 - Make memcpy/memmove/memcmp/bcmp/etc. faster - Add Mersenne Twister and Vigna to LIBC_RAND - Provide privileged __printf() for error code - Fix zipos opendir() so that it reports ENOTDIR - Add basic chmod() implementation for Windows NT - Add Cosmo's best functions to Python cosmo module - Pin function trace indent depth to that of caller - Show memory diagram on invalid access in MODE=dbg - Differentiate stack overflow on crash in MODE=dbg - Add stb_truetype and tools for analyzing font files - Upgrade to UNICODE 13 and reduce its binary footprint - COMPILE.COM now logs resource usage of build commands - Start implementing basic poll() support on bare metal - Set getauxval(AT_EXECFN) to GetModuleFileName() on NT - Add descriptions to strerror() in non-TINY build modes - Add COUNTBRANCH() macro to help with micro-optimizations - Make error / backtrace / asan / memory code more unbreakable - Add fast perfect C implementation of μ-Law and a-Law audio codecs - Make strtol() functions consistent with other libc implementations - Improve Linenoise implementation (see also github.com/jart/bestline) - COMPILE.COM now suppresses stdout/stderr of successful build commands
2021-09-28 05:58:51 +00:00
#ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
#endif
2020-06-15 14:18:57 +00:00
#ifndef _Section
#define _Section(s) __attribute__((__section__(s)))
#endif
#ifndef __llvm__
#pragma GCC diagnostic ignored "-Wformat=0" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic warning "-Wunknown-pragmas"
#else
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wconstant-logical-operand" /* what */
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wstring-plus-int" /* features 4 losers */
#pragma GCC diagnostic ignored "-Wkeyword-compat" /* c++ upgrade */
#pragma GCC diagnostic ignored "-Wuser-defined-literals" /* reserved for me */
#endif
#pragma GCC diagnostic ignored "-Wformat-extra-args" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function" /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
2020-06-15 14:18:57 +00:00
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif
2020-06-15 14:18:57 +00:00
2023-05-02 02:43:59 +00:00
#ifdef __x86_64__
2024-02-27 12:09:49 +00:00
#define DebugBreak() __asm__("int3")
2021-02-04 01:14:17 +00:00
#else
2023-05-02 02:43:59 +00:00
#define DebugBreak() __builtin_trap()
#endif
2020-06-15 14:18:57 +00:00
#endif /* _COSMO_SOURCE */
2024-02-27 12:09:49 +00:00
#define __veil(CONSTRAINT, EXPRESSION) \
__extension__({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
__asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
VeiledValue; \
2020-06-15 14:18:57 +00:00
})
2024-02-27 12:09:49 +00:00
#define __conceal(CONSTRAINT, EXPRESSION) \
__extension__({ \
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
__asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
VeiledValue; \
2020-06-15 14:18:57 +00:00
})
2024-02-27 12:09:49 +00:00
#define __expropriate(EXPRESSION) \
__extension__({ \
__asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
0; \
2020-06-15 14:18:57 +00:00
})
2024-02-27 12:09:49 +00:00
#if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \
2024-02-27 12:09:49 +00:00
__asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
2023-05-10 08:10:28 +00:00
#elif defined(__aarch64__)
#define __yoink(SYMBOL) \
2024-02-27 12:09:49 +00:00
__asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
2021-02-04 01:14:17 +00:00
#else
#define __yoink(SYMBOL) (void)0
2021-02-04 01:14:17 +00:00
#endif
2020-06-15 14:18:57 +00:00
2024-02-27 12:09:49 +00:00
#if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \
2024-02-27 12:09:49 +00:00
__asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
2023-05-10 08:10:28 +00:00
#elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \
2024-02-27 12:09:49 +00:00
__asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
2021-02-04 01:14:17 +00:00
#else
#define __static_yoink(SYMBOLSTR)
2021-02-04 01:14:17 +00:00
#endif
2020-06-15 14:18:57 +00:00
2021-02-04 01:14:17 +00:00
#if !defined(IM_FEELING_NAUGHTY)
#define __static_yoink_source(PATH) __static_yoink(PATH)
#else
#define __static_yoink_source(PATH)
#endif
#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias) \
__asm__(".weak\t" #alias "\n\t" \
".equ\t" #alias ", " #sym "\n\t" \
".type\t" #alias ",@notype")
2023-05-15 23:32:10 +00:00
#ifndef __chibicc__
#define __strong_reference(sym, alias) \
extern __typeof(sym) alias __attribute__((__alias__(#sym)))
#else
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif
#if defined(__GNUC__) || defined(__llvm__)
2023-05-16 06:11:47 +00:00
#define __funline \
extern __inline \
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif
2023-05-16 06:11:47 +00:00
#if defined(__x86_64__) && (defined(__GNUC__) || defined(__llvm__)) && \
Release Cosmopolitan v3.3 This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker appears to have changed things so that only a single de-duplicated str table is present in the binary, and it gets placed wherever the linker wants, regardless of what the linker script says. To cope with that we need to stop using .ident to embed licenses. As such, this change does significant work to revamp how third party licenses are defined in the codebase, using `.section .notice,"aR",@progbits`. This new GCC 12.3 toolchain has support for GNU indirect functions. It lets us support __target_clones__ for the first time. This is used for optimizing the performance of libc string functions such as strlen and friends so far on x86, by ensuring AVX systems favor a second codepath that uses VEX encoding. It shaves some latency off certain operations. It's a useful feature to have for scientific computing for the reasons explained by the test/libcxx/openmp_test.cc example which compiles for fifteen different microarchitectures. Thanks to the upgrades, it's now also possible to use newer instruction sets, such as AVX512FP16, VNNI. Cosmo now uses the %gs register on x86 by default for TLS. Doing it is helpful for any program that links `cosmo_dlopen()`. Such programs had to recompile their binaries at startup to change the TLS instructions. That's not great, since it means every page in the executable needs to be faulted. The work of rewriting TLS-related x86 opcodes, is moved to fixupobj.com instead. This is great news for MacOS x86 users, since we previously needed to morph the binary every time for that platform but now that's no longer necessary. The only platforms where we need fixup of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the kernels do not allow us to specify a value for the %gs register. OpenBSD users are now required to use APE Loader to run Cosmo binaries and assimilation is no longer possible. OpenBSD kernel needs to change to allow programs to specify a value for the %gs register, or it needs to stop marking executable pages loaded by the kernel as mimmutable(). This release fixes __constructor__, .ctor, .init_array, and lastly the .preinit_array so they behave the exact same way as glibc. We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
!defined(__chibicc__) && defined(__OPTIMIZE__)
#define __target_clones(x) __attribute__((__target_clones__(x ",default")))
#else
#define __target_clones(x)
#endif
Release Cosmopolitan v3.3 This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker appears to have changed things so that only a single de-duplicated str table is present in the binary, and it gets placed wherever the linker wants, regardless of what the linker script says. To cope with that we need to stop using .ident to embed licenses. As such, this change does significant work to revamp how third party licenses are defined in the codebase, using `.section .notice,"aR",@progbits`. This new GCC 12.3 toolchain has support for GNU indirect functions. It lets us support __target_clones__ for the first time. This is used for optimizing the performance of libc string functions such as strlen and friends so far on x86, by ensuring AVX systems favor a second codepath that uses VEX encoding. It shaves some latency off certain operations. It's a useful feature to have for scientific computing for the reasons explained by the test/libcxx/openmp_test.cc example which compiles for fifteen different microarchitectures. Thanks to the upgrades, it's now also possible to use newer instruction sets, such as AVX512FP16, VNNI. Cosmo now uses the %gs register on x86 by default for TLS. Doing it is helpful for any program that links `cosmo_dlopen()`. Such programs had to recompile their binaries at startup to change the TLS instructions. That's not great, since it means every page in the executable needs to be faulted. The work of rewriting TLS-related x86 opcodes, is moved to fixupobj.com instead. This is great news for MacOS x86 users, since we previously needed to morph the binary every time for that platform but now that's no longer necessary. The only platforms where we need fixup of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the kernels do not allow us to specify a value for the %gs register. OpenBSD users are now required to use APE Loader to run Cosmo binaries and assimilation is no longer possible. OpenBSD kernel needs to change to allow programs to specify a value for the %gs register, or it needs to stop marking executable pages loaded by the kernel as mimmutable(). This release fixes __constructor__, .ctor, .init_array, and lastly the .preinit_array so they behave the exact same way as glibc. We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
#if !defined(TINY) && !defined(__AVX__)
#define __vex __target_clones("avx")
#else
#define __vex
#endif
Release Cosmopolitan v3.3 This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker appears to have changed things so that only a single de-duplicated str table is present in the binary, and it gets placed wherever the linker wants, regardless of what the linker script says. To cope with that we need to stop using .ident to embed licenses. As such, this change does significant work to revamp how third party licenses are defined in the codebase, using `.section .notice,"aR",@progbits`. This new GCC 12.3 toolchain has support for GNU indirect functions. It lets us support __target_clones__ for the first time. This is used for optimizing the performance of libc string functions such as strlen and friends so far on x86, by ensuring AVX systems favor a second codepath that uses VEX encoding. It shaves some latency off certain operations. It's a useful feature to have for scientific computing for the reasons explained by the test/libcxx/openmp_test.cc example which compiles for fifteen different microarchitectures. Thanks to the upgrades, it's now also possible to use newer instruction sets, such as AVX512FP16, VNNI. Cosmo now uses the %gs register on x86 by default for TLS. Doing it is helpful for any program that links `cosmo_dlopen()`. Such programs had to recompile their binaries at startup to change the TLS instructions. That's not great, since it means every page in the executable needs to be faulted. The work of rewriting TLS-related x86 opcodes, is moved to fixupobj.com instead. This is great news for MacOS x86 users, since we previously needed to morph the binary every time for that platform but now that's no longer necessary. The only platforms where we need fixup of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the kernels do not allow us to specify a value for the %gs register. OpenBSD users are now required to use APE Loader to run Cosmo binaries and assimilation is no longer possible. OpenBSD kernel needs to change to allow programs to specify a value for the %gs register, or it needs to stop marking executable pages loaded by the kernel as mimmutable(). This release fixes __constructor__, .ctor, .init_array, and lastly the .preinit_array so they behave the exact same way as glibc. We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
#define __notice(sym, str) \
__attribute__((__section__(".notice"), __aligned__(1))) const char sym[] = \
"\n\n" str
2020-06-15 14:18:57 +00:00
#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_