mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Get monorepo fully building on Windows again
The mkdeps tool was failing, because it used a clever mmap() hack that's no longer supported. I've also removed tinymalloc.inc from build tooling because Windows doesn't like the way it uses overcommit memory. Sadly it means our build tool binaries will be larger. It's less of an issue, now that we are no longer putting build tool binaries in the git repository.
This commit is contained in:
parent
acd6c32184
commit
5469202ea8
15 changed files with 40 additions and 93 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdalign.h"
|
||||
#include "libc/stdckdint.h"
|
||||
|
@ -50,6 +51,10 @@ static void tinymalloc_init(void) {
|
|||
heap.once = 1;
|
||||
}
|
||||
|
||||
__attribute__((__destructor__)) static void destroy(void) {
|
||||
kprintf("used = %'zu\n", heap.used);
|
||||
}
|
||||
|
||||
static inline int isheap(char *mem) {
|
||||
return heap.memory <= mem && mem < heap.memory + heap.used;
|
||||
}
|
||||
|
|
|
@ -260,8 +260,6 @@ static Elf64_Xword notesize;
|
|||
|
||||
static char *r_off32_e_lfanew;
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static wontreturn void Die(const char *thing, const char *reason) {
|
||||
tinyprint(2, thing, ": ", reason, "\n", NULL);
|
||||
exit(1);
|
||||
|
|
|
@ -67,8 +67,6 @@
|
|||
#define FORMAT_MACHO 2
|
||||
#define FORMAT_PE 3
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static int g_arch;
|
||||
static int g_format;
|
||||
static bool g_force;
|
||||
|
|
|
@ -229,8 +229,6 @@ const char *const kSafeEnv[] = {
|
|||
"TMPDIR", // needed by compiler
|
||||
};
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
void OnAlrm(int sig) {
|
||||
++gotalrm;
|
||||
}
|
||||
|
|
|
@ -69,8 +69,6 @@ char linkbuf[PATH_MAX];
|
|||
|
||||
void Cp(char *, char *);
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
bool IsDirectory(const char *path) {
|
||||
int e;
|
||||
bool res;
|
||||
|
|
|
@ -159,9 +159,6 @@ static const char *stubpath;
|
|||
static long FLAG_SizeOfStackCommit = 64 * 1024;
|
||||
static long FLAG_SizeOfStackReserve = 8 * 1024 * 1024;
|
||||
|
||||
#define TINYMALLOC_MAX_ALIGN MAX_ALIGN
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static wontreturn void Die(const char *thing, const char *reason) {
|
||||
tinyprint(2, thing, ": ", reason, "\n", NULL);
|
||||
exit(1);
|
||||
|
|
|
@ -67,8 +67,6 @@ static Elf64_Ehdr *elf;
|
|||
static const char *epath;
|
||||
static Elf64_Xword symcount;
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static wontreturn void Die(const char *reason) {
|
||||
tinyprint(2, epath, ": ", reason, "\n", NULL);
|
||||
exit(1);
|
||||
|
|
|
@ -71,8 +71,6 @@ const char *prog;
|
|||
char databuf[32768];
|
||||
char pathbuf[PATH_MAX];
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fputs("usage: ", f);
|
||||
fputs(prog, f);
|
||||
|
|
|
@ -51,8 +51,6 @@ static const char *prog;
|
|||
static char16_t **filters;
|
||||
static uint32_t pids[10000];
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static wontreturn void PrintUsage(int rc, FILE *f) {
|
||||
fprintf(f,
|
||||
"Usage: %s [-nshv] NAME...\n"
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/fmt/libgen.h"
|
||||
#include "libc/fmt/magnumstrs.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/leaks.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
@ -146,8 +146,6 @@ static const char *buildroot;
|
|||
static const char *genroot;
|
||||
static const char *outpath;
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static inline bool IsBlank(int c) {
|
||||
return c == ' ' || c == '\t';
|
||||
}
|
||||
|
@ -345,9 +343,8 @@ static const char *FindIncludePath(const char *map, size_t mapsize,
|
|||
|
||||
// scan backwards for hash character
|
||||
for (;;) {
|
||||
if (q == map) {
|
||||
if (q == map)
|
||||
return 0;
|
||||
}
|
||||
if (IsBlank(q[-1])) {
|
||||
--q;
|
||||
continue;
|
||||
|
@ -414,17 +411,15 @@ static void LoadRelationships(int argc, char *argv[]) {
|
|||
static char srcdirbuf[PATH_MAX];
|
||||
const char *p, *pe, *src, *path, *pathend, *srcdir, *final;
|
||||
getargs_init(&ga, argv + optind);
|
||||
while ((src = getargs_next(&ga))) {
|
||||
while ((src = getargs_next(&ga)))
|
||||
CreateSourceId(src);
|
||||
}
|
||||
getargs_destroy(&ga);
|
||||
getargs_init(&ga, argv + optind);
|
||||
while ((src = getargs_next(&ga))) {
|
||||
is_assembly = endswith(src, ".s");
|
||||
srcid = GetSourceId(src);
|
||||
if (strlcpy(srcdirbuf, src, PATH_MAX) >= PATH_MAX) {
|
||||
if (strlcpy(srcdirbuf, src, PATH_MAX) >= PATH_MAX)
|
||||
DiePathTooLong(src);
|
||||
}
|
||||
srcdir = dirname(srcdirbuf);
|
||||
if ((fd = open(src, O_RDONLY)) == -1) {
|
||||
if (errno == ENOENT && ga.path) {
|
||||
|
@ -438,17 +433,14 @@ static void LoadRelationships(int argc, char *argv[]) {
|
|||
}
|
||||
DieSys(src);
|
||||
}
|
||||
if ((rc = lseek(fd, 0, SEEK_END)) == -1) {
|
||||
if ((rc = lseek(fd, 0, SEEK_END)) == -1)
|
||||
DieSys(src);
|
||||
}
|
||||
if ((size = rc)) {
|
||||
// repeatedly map to same fixed address so in order to weasel out
|
||||
// of incurring the additional overhead of all these munmap calls
|
||||
map = mmap((void *)0x311987030000, size, PROT_READ,
|
||||
MAP_SHARED | MAP_FIXED, fd, 0);
|
||||
if (map == MAP_FAILED) {
|
||||
map = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (map == MAP_FAILED)
|
||||
DieSys(src);
|
||||
}
|
||||
for (p = map, pe = map + size; p < pe; ++p) {
|
||||
if (!(p = memmem(p, pe - p, "include ", 8)))
|
||||
break;
|
||||
|
@ -477,13 +469,11 @@ static void LoadRelationships(int argc, char *argv[]) {
|
|||
dependency = -1;
|
||||
for (long i = 0; i < systempaths.n; ++i) {
|
||||
if (!(final =
|
||||
__join_paths(juf, PATH_MAX, systempaths.p[i], incpath))) {
|
||||
__join_paths(juf, PATH_MAX, systempaths.p[i], incpath)))
|
||||
DiePathTooLong(incpath);
|
||||
}
|
||||
if ((dependency = GetSourceId(final)) != -1) {
|
||||
if ((dependency = GetSourceId(final)) != -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dependency != -1) {
|
||||
AppendEdge(&edges, dependency, srcid);
|
||||
p = pathend + 1;
|
||||
|
@ -506,9 +496,8 @@ static void LoadRelationships(int argc, char *argv[]) {
|
|||
dependency = GetSourceId((final = incpath));
|
||||
// let foo/bar.c say `#include "hdr.h"`
|
||||
if (dependency == -1 && !strchr(final, '/')) {
|
||||
if (!(final = __join_paths(juf, PATH_MAX, srcdir, final))) {
|
||||
if (!(final = __join_paths(juf, PATH_MAX, srcdir, final)))
|
||||
DiePathTooLong(incpath);
|
||||
}
|
||||
dependency = GetSourceId(final);
|
||||
}
|
||||
if (dependency == -1) {
|
||||
|
@ -526,10 +515,11 @@ static void LoadRelationships(int argc, char *argv[]) {
|
|||
p = pathend + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (close(fd)) {
|
||||
if (munmap(map, size))
|
||||
DieSys(src);
|
||||
}
|
||||
if (close(fd))
|
||||
DieSys(src);
|
||||
}
|
||||
getargs_destroy(&ga);
|
||||
}
|
||||
|
@ -540,9 +530,8 @@ static wontreturn void ShowUsage(int rc, int fd) {
|
|||
}
|
||||
|
||||
static void AddPath(struct Paths *paths, const char *path) {
|
||||
if (paths->n == ARRAYLEN(paths->p)) {
|
||||
if (paths->n == ARRAYLEN(paths->p))
|
||||
Die("too many path arguments");
|
||||
}
|
||||
paths->p[paths->n++] = path;
|
||||
}
|
||||
|
||||
|
@ -557,21 +546,18 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
AddPath(&systempaths, optarg);
|
||||
break;
|
||||
case 'o':
|
||||
if (outpath) {
|
||||
if (outpath)
|
||||
Die("multiple output paths specified");
|
||||
}
|
||||
outpath = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
if (buildroot) {
|
||||
if (buildroot)
|
||||
Die("multiple build roots specified");
|
||||
}
|
||||
buildroot = optarg;
|
||||
break;
|
||||
case 'g':
|
||||
if (genroot) {
|
||||
if (genroot)
|
||||
Die("multiple generated roots specified");
|
||||
}
|
||||
genroot = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
|
@ -582,31 +568,24 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
ShowUsage(1, 2);
|
||||
}
|
||||
}
|
||||
if (optind == argc) {
|
||||
if (optind == argc)
|
||||
Die("missing input argument");
|
||||
}
|
||||
if (!genroot) {
|
||||
if (!genroot)
|
||||
genroot = "o/";
|
||||
}
|
||||
if (!endswith(genroot, "/")) {
|
||||
if (!endswith(genroot, "/"))
|
||||
Die("generated output path must end with slash");
|
||||
}
|
||||
if (!buildroot) {
|
||||
if (!buildroot)
|
||||
Die("need build output path");
|
||||
}
|
||||
if (!endswith(buildroot, "/")) {
|
||||
if (!endswith(buildroot, "/"))
|
||||
Die("build output path must end with slash");
|
||||
}
|
||||
if (!startswith(buildroot, genroot)) {
|
||||
if (!startswith(buildroot, genroot))
|
||||
Die("build output path must start with generated output path");
|
||||
}
|
||||
if (!systempaths.n && hermetic) {
|
||||
AddPath(&systempaths, "third_party/libcxx/include/");
|
||||
AddPath(&systempaths, "libc/isystem/");
|
||||
}
|
||||
if (systempaths.n && !hermetic) {
|
||||
if (systempaths.n && !hermetic)
|
||||
Die("system path can only be specified in hermetic mode");
|
||||
}
|
||||
long j = 0;
|
||||
for (long i = 0; i < systempaths.n; ++i) {
|
||||
size_t n;
|
||||
|
@ -619,21 +598,18 @@ static void GetOpts(int argc, char *argv[]) {
|
|||
DieSys(path);
|
||||
}
|
||||
}
|
||||
if ((n = strlen(path)) >= PATH_MAX) {
|
||||
if ((n = strlen(path)) >= PATH_MAX)
|
||||
DiePathTooLong(path);
|
||||
}
|
||||
if (!n || path[n - 1] != '/') {
|
||||
if (!n || path[n - 1] != '/')
|
||||
Die("system path must end with slash");
|
||||
}
|
||||
}
|
||||
systempaths.n = j;
|
||||
}
|
||||
|
||||
static const char *StripExt(char pathbuf[hasatleast PATH_MAX], const char *s) {
|
||||
static char *dot;
|
||||
if (strlcpy(pathbuf, s, PATH_MAX) >= PATH_MAX) {
|
||||
if (strlcpy(pathbuf, s, PATH_MAX) >= PATH_MAX)
|
||||
DiePathTooLong(s);
|
||||
}
|
||||
dot = strrchr(pathbuf, '.');
|
||||
if (dot)
|
||||
*dot = '\0';
|
||||
|
@ -661,13 +637,10 @@ static uint32_t GetFileExtension(const char *s) {
|
|||
static bool IsObjectSource(const char *name) {
|
||||
int i;
|
||||
uint32_t ext;
|
||||
if ((ext = GetFileExtension(name))) {
|
||||
for (i = 0; i < ARRAYLEN(kSourceExts); ++i) {
|
||||
if (ext == kSourceExts[i]) {
|
||||
if ((ext = GetFileExtension(name)))
|
||||
for (i = 0; i < ARRAYLEN(kSourceExts); ++i)
|
||||
if (ext == kSourceExts[i])
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -736,22 +709,18 @@ int main(int argc, char *argv[]) {
|
|||
LoadRelationships(argc, argv);
|
||||
Crunch();
|
||||
makefile = Explore();
|
||||
if (outpath &&
|
||||
(fd = open(outpath, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) {
|
||||
if (outpath && (fd = open(outpath, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1)
|
||||
DieSys(outpath);
|
||||
}
|
||||
n = appendz(makefile).i;
|
||||
for (i = 0; i < n; i += (size_t)rc) {
|
||||
if ((rc = write(fd, makefile + i, n - i)) == -1) {
|
||||
for (i = 0; i < n; i += (size_t)rc)
|
||||
if ((rc = write(fd, makefile + i, n - i)) == -1)
|
||||
DieSys(outpath);
|
||||
}
|
||||
}
|
||||
if (outpath && close(fd)) {
|
||||
if (outpath && close(fd))
|
||||
DieSys(outpath);
|
||||
}
|
||||
free(makefile);
|
||||
free(edges.p);
|
||||
free(sauces);
|
||||
free(names);
|
||||
CheckForMemoryLeaks();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -62,8 +62,6 @@ char linkbuf[PATH_MAX];
|
|||
|
||||
void Mv(char *, char *);
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
wontreturn void Die(const char *path, const char *reason) {
|
||||
tinyprint(2, path, ": ", reason, "\n", NULL);
|
||||
exit(1);
|
||||
|
|
|
@ -151,8 +151,6 @@ struct Relas {
|
|||
} *p;
|
||||
} prtu;
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static wontreturn void Die(const char *path, const char *reason) {
|
||||
tinyprint(2, path, ": ", reason, "\n", NULL);
|
||||
exit(1);
|
||||
|
|
|
@ -33,8 +33,6 @@ const char *FLAG_prefix;
|
|||
const char *FLAG_suffix;
|
||||
const char *path;
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
wontreturn void PrintUsage(int fd, int exitcode) {
|
||||
tinyprint(fd, "\n\
|
||||
NAME\n\
|
||||
|
|
|
@ -48,8 +48,6 @@ static bool recursive;
|
|||
static bool doemptydirs;
|
||||
static const char *prog;
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
static wontreturn void PrintUsage(int rc, int fd) {
|
||||
tinyprint(fd, "USAGE\n\n ", prog, USAGE, NULL);
|
||||
exit(rc);
|
||||
|
|
|
@ -30,8 +30,6 @@
|
|||
* @fileoverview elf to symbol table file dump tool
|
||||
*/
|
||||
|
||||
#include "libc/mem/tinymalloc.inc"
|
||||
|
||||
void PrintUsage(FILE *f) {
|
||||
fprintf(f, "%s%s%s\n", "usage: ", program_invocation_name,
|
||||
" [-?h] -o PATH COMDBG");
|
||||
|
|
Loading…
Reference in a new issue