Unbloat build config

- 10.5% reduction of o//depend dependency graph
- 8.8% reduction in latency of make command
- Fix issue with temporary file cleanup

There's a new -w option in compile.com that turns off the recent
Landlock output path workaround for "good commands" which do not
unlink() the output file like GNU tooling does.

Our new GNU Make unveil sandboxing appears to have zero overhead
in the grand scheme of things. Full builds are pretty fast since
the only thing that's actually slowed us down is probably libcxx

    make -j16 MODE=rel
    RL: took 85,732,063µs wall time
    RL: ballooned to 323,612kb in size
    RL: needed 828,560,521µs cpu (11% kernel)
    RL: caused 39,080,670 page faults (99% memcpy)
    RL: 350,073 context switches (72% consensual)
    RL: performed 0 reads and 11,494,960 write i/o operations

pledge() and unveil() no longer consider ENOSYS to be an error.
These functions have also been added to Python's cosmo module.

This change also removes some WIN32 APIs and System Five magnums
which we're not using and it's doubtful anyone else would be too
This commit is contained in:
Justine Tunney 2022-08-10 01:32:17 -07:00
parent 133c693650
commit ae5d06dc53
1423 changed files with 2213 additions and 5560 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/alg/alg.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
@ -41,6 +42,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/kcpuids.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/stdio/append.internal.h"
@ -49,6 +51,7 @@
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/itimer.h"
#include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/consts/s.h"
@ -109,6 +112,7 @@ FLAGS\n\
-s decrement verbosity [default 4]\n\
-v increments verbosity [default 4]\n\
-n do nothing (prime ape executable)\n\
-w disable landlock tmp workaround\n\
-h print help\n\
\n\
ENVIRONMENT\n\
@ -144,6 +148,7 @@ bool wantfentry;
bool wantrecord;
bool fulloutput;
bool touchtarget;
bool noworkaround;
bool wantnoredzone;
bool stdoutmustclose;
bool no_sanitize_null;
@ -711,6 +716,8 @@ void ReportResources(void) {
bool MovePreservingDestinationInode(const char *from, const char *to) {
bool res;
ssize_t rc;
size_t remain;
struct stat st;
int fdin, fdout;
if ((fdin = open(from, O_RDONLY)) == -1) {
@ -721,7 +728,30 @@ bool MovePreservingDestinationInode(const char *from, const char *to) {
close(fdin);
return false;
}
res = _copyfd(fdin, fdout, -1) != -1;
fadvise(fdin, 0, st.st_size, MADV_SEQUENTIAL);
ftruncate(fdout, st.st_size);
for (res = true, remain = st.st_size; remain;) {
rc = copy_file_range(fdin, 0, fdout, 0, remain, 0);
if (rc != -1) {
remain -= rc;
} else if (errno == EXDEV) {
if (lseek(fdin, 0, SEEK_SET) == -1) {
kprintf("%s: failed to lseek after exdev\n", from);
res = false;
break;
}
if (lseek(fdout, 0, SEEK_SET) == -1) {
kprintf("%s: failed to lseek after exdev\n", to);
res = false;
break;
}
res = _copyfd(fdin, fdout, -1) != -1;
break;
} else {
res = false;
break;
}
}
close(fdin);
close(fdout);
return res;
@ -747,6 +777,23 @@ bool IsNativeExecutable(const char *path) {
return res;
}
char *MakeTmpOut(const char *path) {
int c;
char *p = tmpout;
char *e = tmpout + sizeof(tmpout) - 1;
p = stpcpy(p, kTmpPath);
while ((c = *path++)) {
if (c == '/') c = '_';
if (p == e) {
kprintf("MakeTmpOut path too long: %s\n", tmpout);
exit(1);
}
*p++ = c;
}
*p = 0;
return tmpout;
}
int main(int argc, char *argv[]) {
int columns;
uint64_t us;
@ -757,7 +804,6 @@ int main(int argc, char *argv[]) {
char *s, *p, *q, **envp;
mode = firstnonnull(getenv("MODE"), MODE);
ksnprintf(tmpout, sizeof(tmpout), "%scompile.%d", kTmpPath, getpid());
/*
* parse prefix arguments
@ -769,7 +815,7 @@ int main(int argc, char *argv[]) {
fszquota = 256 * 1000 * 1000; /* bytes */
memquota = 512 * 1024 * 1024; /* bytes */
if ((s = getenv("V"))) verbose = atoi(s);
while ((opt = getopt(argc, argv, "hnstvA:C:F:L:M:O:P:T:V:")) != -1) {
while ((opt = getopt(argc, argv, "hnstvwA:C:F:L:M:O:P:T:V:")) != -1) {
switch (opt) {
case 'n':
exit(0);
@ -788,6 +834,9 @@ int main(int argc, char *argv[]) {
case 't':
touchtarget = true;
break;
case 'w':
noworkaround = true;
break;
case 'L':
timeout = atoi(optarg);
break;
@ -856,17 +905,37 @@ int main(int argc, char *argv[]) {
* ingest arguments
*/
for (i = optind; i < argc; ++i) {
if (!movepath && !outpath && target && !strcmp(target, argv[i])) {
outpath = argv[i];
AddArg(tmpout);
/*
* replace output filename argument
*
* some commands (e.g. ar) don't use the `-o PATH` notation. in that
* case we assume the output path was passed to compile.com -TTARGET
* which means we can replace the appropriate command line argument.
*/
if (!noworkaround && //
!movepath && //
!outpath && //
target && //
!strcmp(target, argv[i])) {
AddArg(MakeTmpOut(argv[i]));
outpath = target;
movepath = target;
MovePreservingDestinationInode(target, tmpout);
continue;
}
/*
* capture arguments
*/
if (argv[i][0] != '-') {
AddArg(argv[i]);
continue;
}
/*
* capture flags
*/
if (startswith(argv[i], "-o")) {
if (!strcmp(argv[i], "-o")) {
outpath = argv[++i];
@ -874,8 +943,12 @@ int main(int argc, char *argv[]) {
outpath = argv[i] + 2;
}
AddArg("-o");
AddArg(tmpout);
movepath = outpath;
if (noworkaround) {
AddArg(outpath);
} else {
movepath = outpath;
AddArg(MakeTmpOut(outpath));
}
continue;
}
if (!iscc) {