mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Get codebase completely working with LLVM
You can now build Cosmopolitan with Clang: make -j8 MODE=llvm o/llvm/examples/hello.com The assembler and linker code is now friendly to LLVM too. So it's not needed to configure Clang to use binutils under the hood. If you love LLVM then you can now use pure LLVM.
This commit is contained in:
parent
0e36cb3ac4
commit
e75ffde09e
4528 changed files with 7776 additions and 11640 deletions
|
@ -17,7 +17,6 @@ COSMOPOLITAN_C_START_
|
|||
int abs(int) libcesque pureconst;
|
||||
long labs(long) libcesque pureconst;
|
||||
long long llabs(long long) libcesque pureconst;
|
||||
char *ltpcpy(char *, long) paramsnonnull() libcesque nocallback;
|
||||
int llog10(unsigned long) libcesque pureconst;
|
||||
int atoi(const char *) paramsnonnull() libcesque;
|
||||
long atol(const char *) paramsnonnull() libcesque;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* @param a needs at least 21 bytes
|
||||
* @return bytes written w/o nul
|
||||
*/
|
||||
noinline size_t uint64toarray_radix10(uint64_t i, char *a) {
|
||||
noinline size_t uint64toarray_radix10(uint64_t i, char a[hasatleast 21]) {
|
||||
size_t j;
|
||||
j = 0;
|
||||
do {
|
||||
|
@ -43,7 +43,7 @@ noinline size_t uint64toarray_radix10(uint64_t i, char *a) {
|
|||
* @param a needs at least 21 bytes
|
||||
* @return bytes written w/o nul
|
||||
*/
|
||||
size_t int64toarray_radix10(int64_t i, char *a) {
|
||||
size_t int64toarray_radix10(int64_t i, char a[hasatleast 21]) {
|
||||
if (i >= 0) return uint64toarray_radix10(i, a);
|
||||
*a++ = '-';
|
||||
return 1 + uint64toarray_radix10(-i, a);
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*-*- mode:c; indent-tabs-mode:nil; tab-width:2; coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
|
||||
char *ltpcpy(char *dst, long x) {
|
||||
unsigned len = llog10(abs(x)) + 1;
|
||||
if (x < 0) *dst++ = '-';
|
||||
unsigned i = len;
|
||||
do {
|
||||
dst[--i] = '0' + x % 10;
|
||||
x /= 10;
|
||||
} while (i);
|
||||
return dst + len;
|
||||
}
|
|
@ -129,7 +129,7 @@ hidden int palandprintf(void *fn, void *arg, const char *format, va_list va) {
|
|||
int w, flags, width, lasterr, precision;
|
||||
|
||||
lasterr = errno;
|
||||
out = fn ? fn : (int (*)(int, void *))missingno;
|
||||
out = fn ? fn : (void *)missingno;
|
||||
|
||||
while (*format) {
|
||||
/* %[flags][width][.precision][length] */
|
||||
|
@ -267,9 +267,8 @@ hidden int palandprintf(void *fn, void *arg, const char *format, va_list va) {
|
|||
case 'u': {
|
||||
flags &= ~FLAGS_HASH; /* no hash for dec format */
|
||||
DoNumber:
|
||||
if (!weaken(ntoa) ||
|
||||
weaken(ntoa)(out, arg, va, signbit, log2base, precision, width,
|
||||
flags, alphabet) == -1) {
|
||||
if (ntoa(out, arg, va, signbit, log2base, precision, width, flags,
|
||||
alphabet) == -1) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
@ -282,8 +281,7 @@ hidden int palandprintf(void *fn, void *arg, const char *format, va_list va) {
|
|||
} else {
|
||||
ldbl = va_arg(va, double);
|
||||
}
|
||||
if (!weaken(ftoa) ||
|
||||
weaken(ftoa)(out, arg, ldbl, precision, width, flags) == -1) {
|
||||
if (ftoa(out, arg, ldbl, precision, width, flags) == -1) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
@ -312,8 +310,7 @@ hidden int palandprintf(void *fn, void *arg, const char *format, va_list va) {
|
|||
case 's':
|
||||
p = va_arg(va, void *);
|
||||
showstr:
|
||||
if (!weaken(stoa) || weaken(stoa)(out, arg, p, flags, precision, width,
|
||||
signbit, qchar) == -1) {
|
||||
if (stoa(out, arg, p, flags, precision, width, signbit, qchar) == -1) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -17,22 +17,19 @@
|
|||
* format strings are constexprs that only contain directives.
|
||||
*/
|
||||
|
||||
#define PFLINK(FMT) \
|
||||
({ \
|
||||
if (___PFLINK(FMT, strpbrk, "bxdinupo")) STATIC_YOINK("ntoa"); \
|
||||
if (___PFLINK(FMT, strpbrk, "fFgGaA")) STATIC_YOINK("ftoa"); \
|
||||
if (___PFLINK(FMT, strpbrk, "cmrqs")) { \
|
||||
STATIC_YOINK("stoa"); \
|
||||
if (___PFLINK(FMT, strchr, '#')) STATIC_YOINK("kCp437"); \
|
||||
if (___PFLINK(FMT, strstr, "%m")) STATIC_YOINK("strerror"); \
|
||||
if (!IsTiny() && (___PFLINK(FMT, strstr, "%*") || \
|
||||
___PFLINK(FMT, strpbrk, "0123456789"))) { \
|
||||
STATIC_YOINK("strnwidth"); \
|
||||
STATIC_YOINK("strnwidth16"); \
|
||||
STATIC_YOINK("wcsnwidth"); \
|
||||
} \
|
||||
} \
|
||||
FMT; \
|
||||
#define PFLINK(FMT) \
|
||||
({ \
|
||||
if (___PFLINK(FMT, strpbrk, "cmrqs")) { \
|
||||
if (___PFLINK(FMT, strchr, '#')) STATIC_YOINK("kCp437"); \
|
||||
if (___PFLINK(FMT, strstr, "%m")) STATIC_YOINK("strerror"); \
|
||||
if (!IsTiny() && (___PFLINK(FMT, strstr, "%*") || \
|
||||
___PFLINK(FMT, strpbrk, "0123456789"))) { \
|
||||
STATIC_YOINK("strnwidth"); \
|
||||
STATIC_YOINK("strnwidth16"); \
|
||||
STATIC_YOINK("wcsnwidth"); \
|
||||
} \
|
||||
} \
|
||||
FMT; \
|
||||
})
|
||||
|
||||
#define SFLINK(FMT) \
|
||||
|
@ -40,7 +37,7 @@
|
|||
if (___PFLINK(FMT, strchr, 'm')) { \
|
||||
STATIC_YOINK("malloc"); \
|
||||
STATIC_YOINK("calloc"); \
|
||||
STATIC_YOINK("free_s"); \
|
||||
STATIC_YOINK("free"); \
|
||||
STATIC_YOINK("__grow"); \
|
||||
} \
|
||||
FMT; \
|
||||
|
@ -70,8 +67,6 @@
|
|||
#define SFLINK(FMT) FMT
|
||||
#ifdef __GNUC__
|
||||
__asm__(".section .yoink\n\t"
|
||||
"nopl\tntoa(%rip)\n\t"
|
||||
"nopl\tftoa(%rip)\n\t"
|
||||
"nopl\tkCp437(%rip)\n\t"
|
||||
"nopl\tstrerror(%rip)\n\t"
|
||||
"nopl\tstrnwidth(%rip)\n\t"
|
||||
|
@ -79,14 +74,11 @@ __asm__(".section .yoink\n\t"
|
|||
"nopl\twcsnwidth(%rip)\n\t"
|
||||
"nopl\tmalloc(%rip)\n\t"
|
||||
"nopl\tcalloc(%rip)\n\t"
|
||||
"nopl\tfree_s(%rip)\n\t"
|
||||
"nopl\t__grow(%rip)\n\t"
|
||||
".previous");
|
||||
#else
|
||||
static long __pflink(long x) {
|
||||
x |= kCp437[0];
|
||||
x |= ntoa(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
x |= ftoa(0, 0, 0, 0, 0, 0);
|
||||
x |= strnwidth(0, 0, 0);
|
||||
x |= strnwidth16(0, 0, 0);
|
||||
x |= wcsnwidth(0, 0, 0);
|
||||
|
@ -94,7 +86,6 @@ static long __pflink(long x) {
|
|||
x |= __grow(0, 0, 0, 0);
|
||||
x |= (intptr_t)strerror(0);
|
||||
x |= (intptr_t)calloc(0, 0);
|
||||
free_s(0);
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include "libc/nt/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
STATIC_YOINK("ntoa");
|
||||
STATIC_YOINK("stoa");
|
||||
|
||||
STATIC_YOINK("E2BIG");
|
||||
STATIC_YOINK("EACCES");
|
||||
STATIC_YOINK("EADDRINUSE");
|
||||
|
@ -321,7 +324,7 @@ int strerror_r(int err, char *buf, size_t size) {
|
|||
s = firstnonnull(geterrname(err), "?");
|
||||
}
|
||||
if (!SupportsWindows()) {
|
||||
snprintf(buf, size, "E%s[%d]", s, err);
|
||||
(snprintf)(buf, size, "E%s[%d]", s, err);
|
||||
} else {
|
||||
winstate = GetLastError();
|
||||
sysvstate = errno;
|
||||
|
@ -332,8 +335,8 @@ int strerror_r(int err, char *buf, size_t size) {
|
|||
} else {
|
||||
buf16[0] = u'\0';
|
||||
}
|
||||
snprintf(buf, size, "E%s/err=%d/errno:%d/GetLastError:%d%s%hs", s, err,
|
||||
sysvstate, winstate, buf16[0] ? " " : "", buf16);
|
||||
(snprintf)(buf, size, "E%s/err=%d/errno:%d/GetLastError:%d%s%hs", s, err,
|
||||
sysvstate, winstate, buf16[0] ? " " : "", buf16);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -286,13 +286,11 @@ int vcscanf(int callback(void *), int unget(int, void *), void *arg,
|
|||
}
|
||||
}
|
||||
Done:
|
||||
while (freeme) {
|
||||
while (freeme && weaken(free)) {
|
||||
struct FreeMe *entry = freeme;
|
||||
freeme = entry->next;
|
||||
if (items == -1) {
|
||||
weaken(free_s)((void **)&entry->ptr);
|
||||
}
|
||||
weaken(free_s)((void **)&entry);
|
||||
if (items == -1) weaken(free)(entry->ptr);
|
||||
weaken(free)(entry);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue