mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 10:48:29 +00:00
Add chibicc
This program popped up on Hacker News recently. It's the only modern compiler I've ever seen that doesn't have dependencies and is easily modified. So I added all of the missing GNU extensions I like to use which means it might be possible soon to build on non-Linux and have third party not vendor gcc binaries.
This commit is contained in:
parent
e44a0cf6f8
commit
8da931a7f6
298 changed files with 19493 additions and 11950 deletions
|
@ -25,7 +25,7 @@ COSMOPOLITAN_C_START_
|
|||
/**
|
||||
* Same as longjmp() but runs gc() / defer() destructors.
|
||||
*/
|
||||
void gclongjmp(jmp_buf, int) nothrow noreturn paramsnonnull();
|
||||
void gclongjmp(jmp_buf, int) nothrow wontreturn paramsnonnull();
|
||||
|
||||
/**
|
||||
* Calls FN(ARG) when function returns.
|
||||
|
|
|
@ -19,10 +19,10 @@ extern hidden void *g_stacktop;
|
|||
void _init(void) hidden;
|
||||
void _piro(int) hidden;
|
||||
void *__cxa_finalize(void *) hidden;
|
||||
void _executive(int, char **, char **, long (*)[2]) hidden noreturn;
|
||||
void __stack_chk_fail(void) noreturn relegated;
|
||||
void __stack_chk_fail_local(void) noreturn relegated hidden;
|
||||
void _jmpstack(void *, void *, ...) hidden noreturn;
|
||||
void _executive(int, char **, char **, long (*)[2]) hidden wontreturn;
|
||||
void __stack_chk_fail(void) wontreturn relegated;
|
||||
void __stack_chk_fail_local(void) wontreturn relegated hidden;
|
||||
void _jmpstack(void *, void *, ...) hidden wontreturn;
|
||||
long _setstack(void *, void *, ...) hidden;
|
||||
int GetDosArgv(const char16_t *, char *, size_t, char **, size_t) hidden;
|
||||
Elf64_Ehdr *MapElfRead(const char *, struct MappedFile *) hidden;
|
||||
|
|
|
@ -29,7 +29,7 @@ STATIC_YOINK("_init_onntconsoleevent");
|
|||
|
||||
static struct InterruptibleCall *g_interruptiblecall;
|
||||
|
||||
noreturn static void interruptcall(int sig) {
|
||||
wontreturn static void interruptcall(int sig) {
|
||||
longjmp(g_interruptiblecall->jb, 1);
|
||||
unreachable;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
static privileged void __print$nt(const void *data, size_t len) {
|
||||
int64_t hand;
|
||||
uint32_t wrote;
|
||||
char xmm[256] aligned(16);
|
||||
char xmm[256] forcealign(16);
|
||||
savexmm(&xmm[128]);
|
||||
hand = __imp_GetStdHandle(kNtStdErrorHandle);
|
||||
__imp_WriteFile(hand, data, len, &wrote, NULL);
|
||||
|
|
|
@ -6,45 +6,45 @@ COSMOPOLITAN_C_START_
|
|||
│ cosmopolitan § runtime ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
typedef long jmp_buf[8] aligned(CACHELINE);
|
||||
typedef long jmp_buf[8] forcealign(CACHELINE);
|
||||
|
||||
extern int g_argc; /* CRT */
|
||||
extern char **g_argv; /* CRT */
|
||||
extern char **environ; /* CRT */
|
||||
extern unsigned long *g_auxv; /* CRT */
|
||||
extern char *program_invocation_name; /* RII */
|
||||
extern char *program_invocation_short_name; /* RII */
|
||||
extern uint64_t g_syscount; /* RII */
|
||||
extern const uint64_t kStartTsc; /* RII */
|
||||
extern const char kTmpPath[]; /* RII */
|
||||
extern const char kNtSystemDirectory[]; /* RII */
|
||||
extern const char kNtWindowsDirectory[]; /* RII */
|
||||
extern unsigned char _base[] aligned(PAGESIZE); /* αpε */
|
||||
extern unsigned char _ehead[] aligned(PAGESIZE); /* αpε */
|
||||
extern unsigned char _etext[] aligned(PAGESIZE); /* αpε */
|
||||
extern unsigned char _edata[] aligned(PAGESIZE); /* αpε */
|
||||
extern unsigned char _end[] aligned(PAGESIZE); /* αpε */
|
||||
extern unsigned char _ereal; /* αpε */
|
||||
extern unsigned char __privileged_start; /* αpε */
|
||||
extern unsigned char __test_start; /* αpε */
|
||||
extern unsigned char __ro; /* αpε */
|
||||
extern unsigned char *__relo_start[]; /* αpε */
|
||||
extern unsigned char *__relo_end[]; /* αpε */
|
||||
extern uint8_t __zip_start[]; /* αpε */
|
||||
extern uint8_t __zip_end[]; /* αpε */
|
||||
extern int g_argc; /* CRT */
|
||||
extern char **g_argv; /* CRT */
|
||||
extern char **environ; /* CRT */
|
||||
extern unsigned long *g_auxv; /* CRT */
|
||||
extern char *program_invocation_name; /* RII */
|
||||
extern char *program_invocation_short_name; /* RII */
|
||||
extern uint64_t g_syscount; /* RII */
|
||||
extern const uint64_t kStartTsc; /* RII */
|
||||
extern const char kTmpPath[]; /* RII */
|
||||
extern const char kNtSystemDirectory[]; /* RII */
|
||||
extern const char kNtWindowsDirectory[]; /* RII */
|
||||
extern unsigned char _base[] forcealign(PAGESIZE); /* αpε */
|
||||
extern unsigned char _ehead[] forcealign(PAGESIZE); /* αpε */
|
||||
extern unsigned char _etext[] forcealign(PAGESIZE); /* αpε */
|
||||
extern unsigned char _edata[] forcealign(PAGESIZE); /* αpε */
|
||||
extern unsigned char _end[] forcealign(PAGESIZE); /* αpε */
|
||||
extern unsigned char _ereal; /* αpε */
|
||||
extern unsigned char __privileged_start; /* αpε */
|
||||
extern unsigned char __test_start; /* αpε */
|
||||
extern unsigned char __ro; /* αpε */
|
||||
extern unsigned char *__relo_start[]; /* αpε */
|
||||
extern unsigned char *__relo_end[]; /* αpε */
|
||||
extern uint8_t __zip_start[]; /* αpε */
|
||||
extern uint8_t __zip_end[]; /* αpε */
|
||||
|
||||
long missingno();
|
||||
void mcount(void);
|
||||
unsigned long getauxval(unsigned long);
|
||||
void *mapanon(size_t) vallocesque attributeallocsize((1));
|
||||
int setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
|
||||
void longjmp(jmp_buf, int) libcesque noreturn paramsnonnull();
|
||||
void exit(int) noreturn;
|
||||
void _exit(int) libcesque noreturn;
|
||||
void _Exit(int) libcesque noreturn;
|
||||
void abort(void) noreturn noinstrument;
|
||||
void panic(void) noreturn noinstrument privileged;
|
||||
void triplf(void) noreturn noinstrument privileged;
|
||||
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||
void exit(int) wontreturn;
|
||||
void _exit(int) libcesque wontreturn;
|
||||
void _Exit(int) libcesque wontreturn;
|
||||
void abort(void) wontreturn noinstrument;
|
||||
void panic(void) wontreturn noinstrument privileged;
|
||||
void triplf(void) wontreturn noinstrument privileged;
|
||||
int __cxa_atexit(void *, void *, void *) libcesque;
|
||||
int atfork(void *, void *) libcesque;
|
||||
int atexit(void (*)(void)) libcesque;
|
||||
|
|
51
libc/runtime/valist.c
Normal file
51
libc/runtime/valist.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/valist.h"
|
||||
|
||||
static void *__va_arg_mem(struct __va *ap, unsigned long sz, unsigned align) {
|
||||
void *r = ap->overflow_arg_area;
|
||||
if (align > 8) r = (void *)(((unsigned long)r + 15) / 16 * 16);
|
||||
ap->overflow_arg_area = (void *)(((unsigned long)r + sz + 7) / 8 * 8);
|
||||
return r;
|
||||
}
|
||||
|
||||
void *__va_arg(struct __va *ap, unsigned long sz, unsigned align, unsigned k) {
|
||||
void *r;
|
||||
switch (k) {
|
||||
case 0:
|
||||
if (ap->gp_offset < 48) {
|
||||
r = (char *)ap->reg_save_area + ap->gp_offset;
|
||||
ap->gp_offset += 8;
|
||||
return r;
|
||||
} else {
|
||||
return __va_arg_mem(ap, sz, align);
|
||||
}
|
||||
case 1:
|
||||
if (ap->fp_offset < 112) {
|
||||
r = (char *)ap->reg_save_area + ap->fp_offset;
|
||||
ap->fp_offset += 8;
|
||||
return r;
|
||||
} else {
|
||||
return __va_arg_mem(ap, sz, align);
|
||||
}
|
||||
default:
|
||||
return __va_arg_mem(ap, sz, align);
|
||||
}
|
||||
}
|
17
libc/runtime/valist.h
Normal file
17
libc/runtime/valist.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_RUNTIME_VALIST_H_
|
||||
#define COSMOPOLITAN_LIBC_RUNTIME_VALIST_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct __va {
|
||||
unsigned int gp_offset;
|
||||
unsigned int fp_offset;
|
||||
void *overflow_arg_area;
|
||||
void *reg_save_area;
|
||||
};
|
||||
|
||||
void *__va_arg(struct __va *, unsigned long, unsigned, unsigned);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_RUNTIME_VALIST_H_ */
|
|
@ -119,7 +119,7 @@ static textwindows char *AllocateMemory(void *addr, size_t size, int64_t *h) {
|
|||
kNtNumaNoPreferredNode);
|
||||
}
|
||||
|
||||
static textwindows noreturn void WinMainNew(void) {
|
||||
static textwindows wontreturn void WinMainNew(void) {
|
||||
int64_t h;
|
||||
size_t size;
|
||||
int i, count;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue