Get GCC to mostly build with Cosmo

This commit is contained in:
Justine Tunney 2023-06-09 06:41:34 -07:00
parent 2eb7148474
commit 9b55dbe417
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
54 changed files with 113 additions and 132 deletions

View file

@ -7,12 +7,11 @@ COSMOPOLITAN_C_START_
int dprintf(int, const char *, ...) printfesque(2) paramsnonnull((2));
int vdprintf(int, const char *, va_list) paramsnonnull();
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(COSMO) && !defined(__cplusplus)
#define dprintf(FD, FMT, ...) (dprintf)(FD, PFLINK(FMT), ##__VA_ARGS__)
#define vdprintf(FD, FMT, VA) (vdprintf)(FD, PFLINK(FMT), VA)
#endif /* GNU && !ANSI */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_ */

View file

@ -47,7 +47,7 @@ __msabi extern typeof(WaitForSingleObject) *const __imp_WaitForSingleObject;
__msabi extern typeof(GetExitCodeProcess) *const __imp_GetExitCodeProcess;
__msabi extern typeof(UnmapViewOfFile) *const __imp_UnmapViewOfFile;
static noinstrument __msabi bool32
static dontinstrument __msabi bool32
BlockExecveConsoleEvent(uint32_t dwCtrlType) {
// block SIGINT and SIGQUIT in execve() parent process
return true;

View file

@ -67,7 +67,7 @@ getcontext:
.end
////////////////////////////////////////////////////////////////////////////////
noasan noubsan noinstrument int getcontext(ucontext_t *uc) {
noasan noubsan dontinstrument int getcontext(ucontext_t *uc) {
asm volatile("movaps\t%%xmm0,%0" : /* no outputs */ : "m"(uc->__fpustate.xmm[0]));
asm volatile("movaps\t%%xmm1,%0" : /* no outputs */ : "m"(uc->__fpustate.xmm[1]));
asm volatile("movaps\t%%xmm2,%0" : /* no outputs */ : "m"(uc->__fpustate.xmm[2]));

View file

@ -78,10 +78,12 @@ libcesque nosideeffect;
cosmopolitan § conversion » manipulation
*/
#ifdef COSMO
char *dirname(char *);
char *basename(char *);
char *stripext(char *);
char *stripexts(char *);
#endif
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § conversion » computation

View file

@ -35,7 +35,7 @@ char *gcvt(double, int, char *);
cosmopolitan § string formatting » optimizations
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
#if defined(COSMO) && !defined(__cplusplus)
#define sprintf(BUF, FMT, ...) (sprintf)(BUF, PFLINK(FMT), ##__VA_ARGS__)
#define vsprintf(BUF, FMT, VA) (vsprintf)(BUF, PFLINK(FMT), VA)
#define snprintf(B, Z, F, ...) (snprintf)(B, Z, PFLINK(F), ##__VA_ARGS__)

View file

@ -1,6 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_FMT_PFLINK_H_
#define COSMOPOLITAN_LIBC_FMT_PFLINK_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef COSMO
/**
* @fileoverview builtin+preprocessor+linker tricks for printf/scanf.
@ -59,5 +60,12 @@
#pragma GCC diagnostic ignored "-Wformat-security"
#endif /* __GNUC__ + 0 < 6 */
#else
STATIC_YOINK("strerror");
STATIC_YOINK("strnwidth");
STATIC_YOINK("__fmt_dtoa");
STATIC_YOINK("strnwidth16");
STATIC_YOINK("wcsnwidth");
#endif /* COSMO */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_PFLINK_H_ */

View file

@ -208,13 +208,13 @@ typedef struct {
#endif
#endif
#ifndef noinstrument
#ifndef dontinstrument
#if !defined(__STRICT_ANSI__) && \
(__has_attribute(__no_instrument_function__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#define noinstrument __attribute__((__no_instrument_function__))
#define dontinstrument __attribute__((__no_instrument_function__))
#else
#define noinstrument
#define dontinstrument
#endif
#endif
@ -485,32 +485,13 @@ typedef struct {
#endif
#endif
#ifndef artificial
#if !defined(__STRICT_ANSI__) && \
(__has_attribute(__artificial__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define artificial __attribute__((__artificial__))
#else
#define artificial
#endif
#endif
#ifndef microarchitecture
#ifndef _Microarchitecture
#if !defined(__STRICT_ANSI__) && \
(__has_attribute(__target__) || \
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define microarchitecture(march) __attribute__((__target__(march)))
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define microarchitecture(march)
#endif
#endif
#ifndef targetclones
#if !defined(__STRICT_ANSI__) && \
(__has_attribute(__target_clones__) || __GNUC__ >= 6)
#define targetclones(archs) __attribute__((__target_clones__(archs)))
#else
#define targetclones(archs)
#define _Microarchitecture(march)
#endif
#endif
@ -629,8 +610,8 @@ void abort(void) wontreturn;
} while (0)
#ifndef __STRICT_ANSI__
#define textstartup _Section(".text.startup") noinstrument
#define textexit _Section(".text.exit") noinstrument
#define textstartup _Section(".text.startup") dontinstrument
#define textexit _Section(".text.exit") dontinstrument
#define textreal _Section(".text.real")
#define texthead _Section(".text.head")
#define textwindows _Section(".text.windows")

View file

@ -44,7 +44,7 @@ static void bzero128(char *p, size_t n) {
}
#ifdef __x86_64__
microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
_Microarchitecture("avx") static void bzero_avx(char *p, size_t n) {
xmm_t v = {0};
if (IsAsan()) __asan_verify(p, n);
if (n <= 32) {

View file

@ -57,9 +57,9 @@ static dontinline antiquity int memcmp_sse(const unsigned char *p,
}
}
microarchitecture("avx") static int memcmp_avx(const unsigned char *p,
const unsigned char *q,
size_t n) {
_Microarchitecture("avx") static int memcmp_avx(const unsigned char *p,
const unsigned char *q,
size_t n) {
uint64_t w;
unsigned u;
if (n > 32) {

View file

@ -46,7 +46,7 @@ static void *memset_sse(char *p, char c, size_t n) {
}
#ifdef __x86_64__
microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
_Microarchitecture("avx") static void *memset_avx(char *p, char c, size_t n) {
char *t;
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
if (IsAsan()) __asan_verify(p, n);

View file

@ -35,7 +35,7 @@ const unsigned char kConsoleHandles[3] = {
};
// Puts cmd.exe gui back the way it was.
privileged noinstrument void _restorewintty(void) {
privileged dontinstrument void _restorewintty(void) {
if (!IsWindows()) return;
if (__imp_GetCurrentProcessId() != __pid_exec) return;
for (int i = 0; i < 3; ++i) {

View file

@ -45,9 +45,8 @@
* @param st is open symbol table for current executable
* @return -1 w/ errno if error happened
*/
noinstrument noasan int PrintBacktraceUsingSymbols(int fd,
const struct StackFrame *bp,
struct SymbolTable *st) {
dontinstrument noasan int PrintBacktraceUsingSymbols(
int fd, const struct StackFrame *bp, struct SymbolTable *st) {
bool ok;
size_t gi;
intptr_t addr;

View file

@ -19,6 +19,6 @@
#include "libc/errno.h"
#include "libc/log/log.h"
noinstrument int _log_get_errno(void) {
dontinstrument int _log_get_errno(void) {
return errno;
}

View file

@ -19,6 +19,6 @@
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
noinstrument void _log_retrace(void) {
dontinstrument void _log_retrace(void) {
ftrace_enabled(+1);
}

View file

@ -19,6 +19,6 @@
#include "libc/errno.h"
#include "libc/log/log.h"
noinstrument void _log_set_errno(int e) {
dontinstrument void _log_set_errno(int e) {
errno = e;
}

View file

@ -19,6 +19,6 @@
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
noinstrument void _log_untrace(void) {
dontinstrument void _log_untrace(void) {
ftrace_enabled(-1);
}

View file

@ -22,6 +22,6 @@
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
noinstrument void _log_errno(const char *file, int line, const char *form) {
dontinstrument void _log_errno(const char *file, int line, const char *form) {
flogf(kLogWarn, file, line, NULL, PFLINK("%s → %s"), form, strerror(errno));
}

View file

@ -254,10 +254,10 @@ relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
kprintf("\n");
}
static wontreturn relegated noinstrument void __minicrash(int sig,
struct siginfo *si,
ucontext_t *ctx,
const char *kind) {
static wontreturn relegated dontinstrument void __minicrash(int sig,
struct siginfo *si,
ucontext_t *ctx,
const char *kind) {
kprintf("\n"
"\n"
"CRASHED %s WITH %G\n"

View file

@ -33,14 +33,14 @@ static char __watch_last[4096];
void __watch_hook(void);
static noinstrument inline void Copy(char *p, char *q, size_t n) {
static dontinstrument inline void Copy(char *p, char *q, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
p[i] = q[i];
}
}
static noinstrument inline int Cmp(char *p, char *q, size_t n) {
static dontinstrument inline int Cmp(char *p, char *q, size_t n) {
int c;
if (n == 8) return READ64LE(p) != READ64LE(q);
if (n == 4) return READ32LE(p) != READ32LE(q);
@ -52,7 +52,7 @@ static noinstrument inline int Cmp(char *p, char *q, size_t n) {
return 0;
}
noinstrument void __watcher(void) {
dontinstrument void __watcher(void) {
if (__watch_busy) return;
__watch_busy = true;
if (Cmp(__watch_last, __watch_addr, __watch_size)) {

View file

@ -8,7 +8,7 @@ int asprintf(char **, const char *, ...) printfesque(2)
paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(COSMO) && !defined(__cplusplus)
#define asprintf(SP, FMT, ...) (asprintf)(SP, PFLINK(FMT), ##__VA_ARGS__)
#define vasprintf(SP, FMT, VA) (vasprintf)(SP, PFLINK(FMT), VA)
#endif

View file

@ -111,11 +111,11 @@ int WinThreadLaunch(void *arg, // rdi
// 2. windows owns the stack memory right now
// we need win32 raw imports because:
// 1. generated thunks are function logged
noasan noinstrument static textwindows wontreturn void //
WinThreadEntry(int rdi, // rcx
int rsi, // rdx
int rdx, // r8
struct CloneArgs *wt) { // r9
noasan dontinstrument static textwindows wontreturn void //
WinThreadEntry(int rdi, // rcx
int rsi, // rdx
int rdx, // r8
struct CloneArgs *wt) { // r9
int rc;
if (wt->tls) __set_tls_win32(wt->tls);
*wt->ctid = wt->tid;

View file

@ -37,9 +37,8 @@ forceinline char *MemChr(const char *s, unsigned char c, unsigned long n) {
return 0;
}
static textwindows noasan noinstrument axdx_t Recode16to8(char *dst,
size_t dstsize,
const char16_t *src) {
static textwindows noasan dontinstrument axdx_t
Recode16to8(char *dst, size_t dstsize, const char16_t *src) {
bool v;
axdx_t r;
uint64_t w;
@ -72,7 +71,7 @@ static textwindows noasan noinstrument axdx_t Recode16to8(char *dst,
return r;
}
textwindows noinstrument noasan void FixPath(char *path) {
textwindows dontinstrument noasan void FixPath(char *path) {
char *p;
size_t i;
@ -112,9 +111,9 @@ textwindows noinstrument noasan void FixPath(char *path) {
// @param envp stores NULL-terminated string pointer list (optional)
// @param max is the pointer count capacity of envp
// @return number of variables decoded, excluding NULL-terminator
textwindows noasan noinstrument int GetDosEnviron(const char16_t *env,
char *buf, size_t size,
char **envp, size_t max) {
textwindows noasan dontinstrument int GetDosEnviron(const char16_t *env,
char *buf, size_t size,
char **envp, size_t max) {
int i;
char *p;
axdx_t r;

View file

@ -27,7 +27,7 @@ extern _Hide struct SymbolTable *__symtab;
* @param t if null will be auto-populated only if already open
* @return index or -1 if nothing found
*/
noinstrument privileged int __get_symbol(struct SymbolTable *t, intptr_t a) {
dontinstrument privileged int __get_symbol(struct SymbolTable *t, intptr_t a) {
// we need privileged because:
// kprintf is privileged and it depends on this
// we don't want function tracing because:

View file

@ -18,7 +18,7 @@
*/
#include "libc/runtime/symbols.internal.h"
privileged noinstrument noasan noubsan char *__get_symbol_name(
privileged dontinstrument noasan noubsan char *__get_symbol_name(
struct SymbolTable *t, int s) {
/* asan runtime depends on this function */
if (t && s != -1) {

View file

@ -106,7 +106,8 @@ static privileged void HookFunction(code_t *func, void *dest) {
* @param st can be obtained using `GetSymbolTable()`
* @see ape/ape.lds
*/
privileged noinstrument noasan int __hook(void *dest, struct SymbolTable *st) {
privileged dontinstrument noasan int __hook(void *dest,
struct SymbolTable *st) {
long i;
sigset_t mask;
code_t *p, *pe;

View file

@ -18,7 +18,7 @@
*/
#include "libc/intrin/kprintf.h"
privileged noasan noinstrument void __stack_chk_fail(void) {
void __stack_chk_fail(void) {
kprintf("stack smashed\n");
__builtin_trap();
}

View file

@ -166,7 +166,7 @@ int vfprintf_unlocked(FILE *, const char *, va_list)
cosmopolitan § standard i/o » optimizations
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(COSMO) && !defined(__cplusplus)
/* clang-format off */
#define printf(FMT, ...) (printf)(PFLINK(FMT), ##__VA_ARGS__)
#define vprintf(FMT, VA) (vprintf)(PFLINK(FMT), VA)

View file

@ -38,8 +38,8 @@ static int bcmp_sse(const char *p, const char *q, size_t n) {
}
#ifdef __x86_64__
microarchitecture("avx") static int bcmp_avx(const char *p, const char *q,
size_t n) {
_Microarchitecture("avx") static int bcmp_avx(const char *p, const char *q,
size_t n) {
xmm_t a, b, c, d;
if (n > 32) {
if (n >= 16 + 64) {

View file

@ -41,9 +41,9 @@ noasan static unsigned timingsafe_bcmp_sse(const char *p, const char *q,
}
#ifdef __x86_64__
noasan static microarchitecture("avx") int timingsafe_bcmp_avx(const char *p,
const char *q,
size_t n) {
noasan static _Microarchitecture("avx") int timingsafe_bcmp_avx(const char *p,
const char *q,
size_t n) {
uint64_t w;
xmm_t a = {0};
if (n > 32) {

View file

@ -60,7 +60,7 @@ C1 = 0x155553e1053a42.0p-57, /* 0.0416666233237390631894 */
C2 = -0x16c087e80f1e27.0p-62, /* -0.00138867637746099294692 */
C3 = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */
noinstrument float __cosdf(double x)
dontinstrument float __cosdf(double x)
{
double_t r, w, z;

View file

@ -60,7 +60,7 @@ S2 = 0x111110896efbb2.0p-59, /* 0.0083333293858894631756 */
S3 = -0x1a00f9e2cae774.0p-65, /* -0.000198393348360966317347 */
S4 = 0x16cd878c3b46a7.0p-71; /* 0.0000027183114939898219064 */
noinstrument float __sindf(double x)
dontinstrument float __sindf(double x)
{
double_t r, s, w, z;

View file

@ -9,7 +9,7 @@ char *xasprintf(const char *, ...) printfesque(1) paramsnonnull((1))
char *xvasprintf(const char *, va_list) paramsnonnull()
returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#if defined(COSMO) && !defined(__cplusplus)
#define xasprintf(FMT, ...) (xasprintf)(PFLINK(FMT), ##__VA_ARGS__)
#define xvasprintf(FMT, VA) (xvasprintf)(PFLINK(FMT), VA)
#endif