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:
Justine Tunney 2020-12-05 12:20:41 -08:00
parent e44a0cf6f8
commit 8da931a7f6
298 changed files with 19493 additions and 11950 deletions

View file

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
@ -33,12 +34,18 @@
* function. The stat() function may be used to differentiate them.
*/
bool fileexists(const char *path) {
/* TODO(jart): Use fast path on NT? */
int rc, olderr;
struct stat st;
int olderr = errno;
int rc = stat(path, &st);
if (rc == -1 && (errno == ENOENT || errno == ENOTDIR)) {
errno = olderr;
uint16_t path16[PATH_MAX];
if (!IsWindows()) {
olderr = errno;
rc = stat(path, &st);
if (rc == -1 && (errno == ENOENT || errno == ENOTDIR)) {
errno = olderr;
}
return rc != -1;
} else {
if (__mkntpath(path, path16) == -1) return -1;
return GetFileAttributes(path16) != -1u;
}
return rc != -1;
}

View file

@ -34,8 +34,8 @@
textwindows int fstat$nt(int64_t handle, struct stat *st) {
int filetype;
uint64_t actualsize;
struct NtByHandleFileInformation wst;
struct NtFileCompressionInfo fci;
struct NtByHandleFileInformation wst;
if (GetFileInformationByHandle(handle, &wst)) {
memset(st, 0, sizeof(*st));
filetype = GetFileType(handle);

View file

@ -198,12 +198,12 @@ i32 tunefd$sysv(i32, i32, i32, i32) hidden;
u32 fprot2nt(i32, i32) hidden;
u32 prot2nt(i32, i32) privileged;
void __restore_rt() hidden;
void __sigenter$xnu(void *, i32, i32, void *, void *) hidden noreturn;
void __sigenter$xnu(void *, i32, i32, void *, void *) hidden wontreturn;
int utimensat$xnu(int, const char *, const struct timespec *, int) hidden;
int nanosleep$xnu(const struct timespec *, struct timespec *) hidden;
void stat2linux(void *) hidden;
void xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
const struct __darwin_ucontext *) hidden noreturn;
const struct __darwin_ucontext *) hidden wontreturn;
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § syscalls » windows nt » veneers

View file

@ -27,7 +27,7 @@
* @asyncsignalsafe
*/
bool32 isatty(int fd) {
char buf[sizeof(uint16_t) * 4] aligned(2);
char buf[sizeof(uint16_t) * 4] forcealign(2);
if (!IsWindows()) {
return ioctl$sysv(fd, TIOCGWINSZ, &buf) != -1;
} else {

View file

@ -14,7 +14,7 @@ struct sigaction { /* cosmo abi */
void (*sa_restorer)(void);
struct sigset sa_mask;
int64_t __pad;
} aligned(8);
} forcealign(8);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_ */

View file

@ -49,7 +49,7 @@ struct siginfo {
};
char __ignoreme[128 - 2 * sizeof(int32_t) - sizeof(int64_t)];
};
} aligned(8);
} forcealign(8);
typedef struct siginfo siginfo_t;

View file

@ -425,9 +425,9 @@ static void xnussefpustate2linux(struct FpuState *fs,
memcpy(fs->st, &xnufs->__fpu_stmm0, (8 + 16) * sizeof(uint128_t));
}
noreturn void xnutrampoline(void *fn, int infostyle, int sig,
const struct __darwin_siginfo *xnuinfo,
const struct __darwin_ucontext *xnuctx) {
wontreturn void xnutrampoline(void *fn, int infostyle, int sig,
const struct __darwin_siginfo *xnuinfo,
const struct __darwin_ucontext *xnuctx) {
/* note: this function impl can't access static memory */
intptr_t ax;
struct Goodies {