mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 20:28:30 +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
|
@ -82,7 +82,7 @@ struct Header {
|
|||
static void MakeHeader(struct Header *h, const char *name, int ref, int mode,
|
||||
int size) {
|
||||
size_t n;
|
||||
char buf[21];
|
||||
char buf[24];
|
||||
memset(h, ' ', sizeof(*h));
|
||||
n = strlen(name);
|
||||
memcpy(h->name, name, n);
|
||||
|
|
|
@ -37,8 +37,7 @@ OVERVIEW\n\
|
|||
\n\
|
||||
DESCRIPTION\n\
|
||||
\n\
|
||||
This launches gcc or clang while filtering out\n\
|
||||
flags they whine about.\n\
|
||||
This launches gcc or clang after scrubbing flags.\n\
|
||||
\n\
|
||||
EXAMPLE\n\
|
||||
\n\
|
||||
|
@ -77,6 +76,87 @@ int ccversion;
|
|||
struct Flags flags;
|
||||
struct Command command;
|
||||
|
||||
const char *const kGccOnlyFlags[] = {
|
||||
"--nocompress-debug-sections",
|
||||
"--noexecstack",
|
||||
"-Wa,--nocompress-debug-sections",
|
||||
"-Wa,--noexecstack",
|
||||
"-Wno-unused-but-set-variable",
|
||||
"-Wunsafe-loop-optimizations",
|
||||
"-fbranch-target-load-optimize",
|
||||
"-fcx-limited-range",
|
||||
"-fdelete-dead-exceptions",
|
||||
"-femit-struct-debug-baseonly",
|
||||
"-fipa-pta",
|
||||
"-fivopts",
|
||||
"-flimit-function-alignment",
|
||||
"-fmerge-constants",
|
||||
"-fmodulo-sched",
|
||||
"-fmodulo-sched-allow-regmoves",
|
||||
"-fno-align-jumps",
|
||||
"-fno-align-labels",
|
||||
"-fno-align-loops",
|
||||
"-fno-fp-int-builtin-inexact",
|
||||
"-fno-gnu-unique",
|
||||
"-fno-gnu-unique",
|
||||
"-fno-instrument-functions",
|
||||
"-fno-whole-program",
|
||||
"-fopt-info-vec",
|
||||
"-fopt-info-vec-missed",
|
||||
"-freg-struct-return",
|
||||
"-freschedule-modulo-scheduled-loops",
|
||||
"-frounding-math",
|
||||
"-fsched2-use-superblocks",
|
||||
"-fschedule-insns",
|
||||
"-fschedule-insns2",
|
||||
"-fshrink-wrap",
|
||||
"-fshrink-wrap-separate",
|
||||
"-fsignaling-nans",
|
||||
"-fstack-clash-protection",
|
||||
"-ftracer",
|
||||
"-ftrapv",
|
||||
"-ftree-loop-im",
|
||||
"-ftree-loop-vectorize",
|
||||
"-funsafe-loop-optimizations",
|
||||
"-fversion-loops-for-strides",
|
||||
"-fwhole-program",
|
||||
"-gdescribe-dies",
|
||||
"-gstabs",
|
||||
"-mcall-ms2sysv-xlogues",
|
||||
"-mdispatch-scheduler",
|
||||
"-mfpmath=sse+387",
|
||||
"-mmitigate-rop",
|
||||
"-mno-fentry",
|
||||
};
|
||||
|
||||
bool IsGccOnlyFlag(const char *s) {
|
||||
int m, l, r, x;
|
||||
l = 0;
|
||||
r = ARRAYLEN(kGccOnlyFlags) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
x = strcmp(s, kGccOnlyFlags[m]);
|
||||
if (x < 0) {
|
||||
r = m - 1;
|
||||
} else if (x > 0) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (startswith(s, "-ffixed-")) return true;
|
||||
if (startswith(s, "-fcall-saved")) return true;
|
||||
if (startswith(s, "-fcall-used")) return true;
|
||||
if (startswith(s, "-fgcse-")) return true;
|
||||
if (startswith(s, "-fvect-cost-model=")) return true;
|
||||
if (startswith(s, "-fsimd-cost-model=")) return true;
|
||||
if (startswith(s, "-fopt-info")) return true;
|
||||
if (startswith(s, "-mstringop-strategy=")) return true;
|
||||
if (startswith(s, "-mpreferred-stack-boundary=")) return true;
|
||||
if (startswith(s, "-Wframe-larger-than=")) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void AddFlag(char *s) {
|
||||
size_t n;
|
||||
flags.p = realloc(flags.p, ++flags.n * sizeof(*flags.p));
|
||||
|
@ -123,8 +203,8 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
ccversion = atoi(firstnonnull(emptytonull(getenv("CCVERSION")), "4"));
|
||||
isgcc = strstr(basename(cc), "gcc");
|
||||
isclang = strstr(basename(cc), "clang");
|
||||
isgcc = !!strstr(basename(cc), "gcc");
|
||||
isclang = !!strstr(basename(cc), "clang");
|
||||
iscc = isgcc | isclang;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
|
@ -137,10 +217,13 @@ int main(int argc, char *argv[]) {
|
|||
AddFlag((outpath = argv[++i]));
|
||||
continue;
|
||||
}
|
||||
if (iscc) {
|
||||
if (!iscc) {
|
||||
AddFlag(argv[i]);
|
||||
continue;
|
||||
}
|
||||
if (isclang && IsGccOnlyFlag(argv[i])) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(argv[i], "-w")) {
|
||||
AddFlag(argv[i]);
|
||||
AddFlag("-D__W__");
|
||||
|
@ -207,64 +290,9 @@ int main(int argc, char *argv[]) {
|
|||
} else if (startswith(argv[i], "-R") ||
|
||||
!strcmp(argv[i], "-fsave-optimization-record")) {
|
||||
if (isclang) AddFlag(argv[i]);
|
||||
} else if (isclang &&
|
||||
(!strcmp(argv[i], "-gstabs") || !strcmp(argv[i], "-ftrapv") ||
|
||||
!strcmp(argv[i], "-fsignaling-nans") ||
|
||||
!strcmp(argv[i], "-fcx-limited-range") ||
|
||||
!strcmp(argv[i], "-fno-fp-int-builtin-inexact") ||
|
||||
!strcmp(argv[i], "-Wno-unused-but-set-variable") ||
|
||||
!strcmp(argv[i], "-Wunsafe-loop-optimizations") ||
|
||||
!strcmp(argv[i], "-mdispatch-scheduler") ||
|
||||
!strcmp(argv[i], "-ftracer") ||
|
||||
!strcmp(argv[i], "-frounding-math") ||
|
||||
!strcmp(argv[i], "-fmerge-constants") ||
|
||||
!strcmp(argv[i], "-fmodulo-sched") ||
|
||||
!strcmp(argv[i], "-fopt-info-vec") ||
|
||||
!strcmp(argv[i], "-fopt-info-vec-missed") ||
|
||||
!strcmp(argv[i], "-fmodulo-sched-allow-regmoves") ||
|
||||
!strcmp(argv[i], "-freschedule-modulo-scheduled-loops") ||
|
||||
!strcmp(argv[i], "-fipa-pta") ||
|
||||
!strcmp(argv[i], "-fsched2-use-superblocks") ||
|
||||
!strcmp(argv[i], "-fbranch-target-load-optimize") ||
|
||||
!strcmp(argv[i], "-fdelete-dead-exceptions") ||
|
||||
!strcmp(argv[i], "-funsafe-loop-optimizations") ||
|
||||
!strcmp(argv[i], "-mmitigate-rop") ||
|
||||
!strcmp(argv[i], "-fno-align-jumps") ||
|
||||
!strcmp(argv[i], "-fno-align-labels") ||
|
||||
!strcmp(argv[i], "-fno-align-loops") ||
|
||||
!strcmp(argv[i], "-fivopts") ||
|
||||
!strcmp(argv[i], "-fschedule-insns") ||
|
||||
!strcmp(argv[i], "-fno-semantic-interposition") ||
|
||||
!strcmp(argv[i], "-mno-fentry") ||
|
||||
!strcmp(argv[i], "-fversion-loops-for-strides") ||
|
||||
!strcmp(argv[i], "-femit-struct-debug-baseonly") ||
|
||||
!strcmp(argv[i], "-ftree-loop-vectorize") ||
|
||||
!strcmp(argv[i], "-gdescribe-dies") ||
|
||||
!strcmp(argv[i], "-flimit-function-alignment") ||
|
||||
!strcmp(argv[i], "-ftree-loop-im") ||
|
||||
!strcmp(argv[i], "-fno-instrument-functions") ||
|
||||
!strcmp(argv[i], "-fstack-clash-protection") ||
|
||||
!strcmp(argv[i], "-mfpmath=sse+387") ||
|
||||
!strcmp(argv[i], "-Wa,--noexecstack") ||
|
||||
!strcmp(argv[i], "-freg-struct-return") ||
|
||||
!strcmp(argv[i], "-mcall-ms2sysv-xlogues") ||
|
||||
startswith(argv[i], "-ffixed-") ||
|
||||
startswith(argv[i], "-fcall-saved") ||
|
||||
startswith(argv[i], "-fcall-used") ||
|
||||
startswith(argv[i], "-fgcse-") ||
|
||||
strstr(argv[i], "shrink-wrap") ||
|
||||
strstr(argv[i], "schedule-insns2") ||
|
||||
startswith(argv[i], "-fvect-cost-model=") ||
|
||||
startswith(argv[i], "-fsimd-cost-model=") ||
|
||||
startswith(argv[i], "-fopt-info") ||
|
||||
startswith(argv[i], "-mstringop-strategy=") ||
|
||||
startswith(argv[i], "-mpreferred-stack-boundary=") ||
|
||||
strstr(argv[i], "gnu-unique") ||
|
||||
startswith(argv[i], "-Wframe-larger-than=") ||
|
||||
strstr(argv[i], "whole-program") ||
|
||||
startswith(argv[i], "-Wa,--size-check=") ||
|
||||
startswith(argv[i], "-Wa,--listing"))) {
|
||||
/* ignore flag so clang won't whine */
|
||||
} else if (isclang && startswith(argv[i], "--debug-prefix-map")) {
|
||||
/* llvm doesn't provide a gas interface so simulate w/ clang */
|
||||
AddFlag(xasprintf("-f%s", argv[i] + 2));
|
||||
} else {
|
||||
AddFlag(argv[i]);
|
||||
}
|
||||
|
@ -272,7 +300,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
if (iscc) {
|
||||
if (isclang) {
|
||||
AddFlag("-fno-integrated-as");
|
||||
/* AddFlag("-fno-integrated-as"); */
|
||||
AddFlag("-Wno-unused-command-line-argument");
|
||||
AddFlag("-Wno-incompatible-pointer-types-discards-qualifiers");
|
||||
}
|
||||
|
@ -304,6 +332,9 @@ int main(int argc, char *argv[]) {
|
|||
AddFlag("-fsanitize=undefined");
|
||||
AddFlag("-fno-data-sections");
|
||||
}
|
||||
if (wantframe) {
|
||||
AddFlag("-fno-omit-frame-pointer");
|
||||
}
|
||||
}
|
||||
|
||||
AddFlag(NULL);
|
||||
|
|
|
@ -94,10 +94,11 @@ static char *DisError(struct Dis *d, char *p) {
|
|||
}
|
||||
|
||||
static char *DisAddr(struct Dis *d, char *p) {
|
||||
if (-0x80000000 <= d->addr && d->addr <= 0x7fffffff) {
|
||||
return p + uint64toarray_fixed16(d->addr, p, 32);
|
||||
int64_t x = d->addr;
|
||||
if (-2147483648 <= x && x <= 2147483647) {
|
||||
return p + uint64toarray_fixed16(x, p, 32);
|
||||
} else {
|
||||
return p + uint64toarray_fixed16(d->addr, p, 48);
|
||||
return p + uint64toarray_fixed16(x, p, 48);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
.long \linux
|
||||
.endm
|
||||
|
||||
/ Lookup table translating errnos between systems.
|
||||
/
|
||||
/ @see libc/sysv/systemfive.S
|
||||
// Lookup table translating errnos between systems.
|
||||
//
|
||||
// @see libc/sysv/systemfive.S
|
||||
.rodata
|
||||
.align 8
|
||||
kLinuxErrnos:
|
||||
|
|
|
@ -65,7 +65,11 @@ static unsigned GetSpacePrefixLen(const char *p, size_t n) {
|
|||
static unsigned GetSpaceStarPrefixLen(const char *p, size_t n) {
|
||||
int i;
|
||||
i = GetSpacePrefixLen(p, n);
|
||||
return i < n && (p[i] == '*' || p[i] == '/') ? i + 1 : 0;
|
||||
if (i < n && (p[i] == '*' || p[i] == '/')) {
|
||||
return p[i + 1] == '/' ? i + 2 : i + 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned GetTagLen(const char *p, size_t n) {
|
||||
|
|
|
@ -356,7 +356,8 @@ void OpenObject(struct Package *pkg, struct Object *obj, int mode, int prot,
|
|||
CHECK_NE(-1, close(fd));
|
||||
CHECK(IsElf64Binary(obj->elf, obj->size), "path=%`'s",
|
||||
&pkg->strings.p[obj->path]);
|
||||
CHECK_NOTNULL((obj->strs = GetElfStringTable(obj->elf, obj->size)));
|
||||
CHECK_NOTNULL((obj->strs = GetElfStringTable(obj->elf, obj->size)), "on %s",
|
||||
&pkg->strings.p[obj->path]);
|
||||
CHECK_NOTNULL(
|
||||
(obj->syms = GetElfSymbolTable(obj->elf, obj->size, &obj->symcount)));
|
||||
CHECK_NE(0, obj->symcount);
|
||||
|
|
|
@ -145,12 +145,12 @@ void CheckExists(const char *path) {
|
|||
|
||||
nodiscard char *MakeDeployScript(struct addrinfo *remotenic, size_t combytes) {
|
||||
const char *ip4 = (const char *)&remotenic->ai_addr4->sin_addr;
|
||||
return xasprintf("mkdir -p o/ &&\n"
|
||||
"dd bs=%zu count=%zu of=o/runitd.$$.com 2>/dev/null &&\n"
|
||||
"exec <&- &&\n"
|
||||
"chmod +x o/runitd.$$.com &&\n"
|
||||
"o/runitd.$$.com -rdl%hhu.%hhu.%hhu.%hhu -p %hu &&\n"
|
||||
"rm -f o/runitd.$$.com\n",
|
||||
return xasprintf("mkdir -p o/ && "
|
||||
"dd bs=%zu count=%zu of=o/runitd.$$.com 2>/dev/null && "
|
||||
"exec <&- && "
|
||||
"chmod +x o/runitd.$$.com && "
|
||||
"o/runitd.$$.com -rdl%hhu.%hhu.%hhu.%hhu -p %hu && "
|
||||
"rm -f o/runitd.$$.com",
|
||||
GreatestTwoDivisor(combytes),
|
||||
combytes ? combytes / GreatestTwoDivisor(combytes) : 0,
|
||||
ip4[0], ip4[1], ip4[2], ip4[3], g_runitdport);
|
||||
|
|
|
@ -317,7 +317,6 @@ void HandleClient(void) {
|
|||
CHECK_LE(wrote, got);
|
||||
} while ((got -= wrote));
|
||||
}
|
||||
LOGIFNEG1(shutdown(g_clifd, SHUT_RD));
|
||||
LOGIFNEG1(close(g_exefd));
|
||||
|
||||
/* run program, tee'ing stderr to both log and client */
|
||||
|
@ -376,7 +375,6 @@ void HandleClient(void) {
|
|||
/* let client know how it went */
|
||||
LOGIFNEG1(unlink(g_exepath));
|
||||
SendExitMessage(g_clifd, exitcode);
|
||||
LOGIFNEG1(shutdown(g_clifd, SHUT_RDWR));
|
||||
LOGIFNEG1(close(g_clifd));
|
||||
_exit(0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue