Exclude strace from MODE=tiny builds

This change gets o/tinylinux/examples/hello2.com back down to 8kb in
size which had been unintentionally bloated to 40kb in recent months

See #965
This commit is contained in:
Justine Tunney 2023-11-29 03:45:54 -08:00
parent b7e1dc81c2
commit 2b960bb249
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
18 changed files with 46 additions and 33 deletions

View file

@ -228,6 +228,27 @@ PYFLAGS += \
-O2 \ -O2 \
-B -B
endif endif
ifeq ($(MODE), x86_64-tiny)
CONFIG_CPPFLAGS += \
-DTINY \
-DNDEBUG \
-DTRUSTWORTHY
CONFIG_CCFLAGS += \
-Os \
-fno-align-functions \
-fno-align-jumps \
-fno-align-labels \
-fno-align-loops \
-fschedule-insns2 \
-momit-leaf-frame-pointer \
-foptimize-sibling-calls \
-DDWARFLESS
TARGET_ARCH ?= \
-msse3
PYFLAGS += \
-O2 \
-B
endif
ifeq ($(MODE), aarch64-tiny) ifeq ($(MODE), aarch64-tiny)
# TODO(jart): -mcmodel=tiny # TODO(jart): -mcmodel=tiny
CONFIG_CPPFLAGS += \ CONFIG_CPPFLAGS += \

View file

@ -136,7 +136,7 @@ int fcntl(int fd, int cmd, ...) {
rc = ebadf(); rc = ebadf();
} }
#ifdef SYSDEBUG #if SYSDEBUG
if (rc != -1 && cmd == F_GETFL) { if (rc != -1 && cmd == F_GETFL) {
STRACE("fcntl(%d, F_GETFL) → %s", fd, DescribeOpenFlags(rc)); STRACE("fcntl(%d, F_GETFL) → %s", fd, DescribeOpenFlags(rc));
} else if (cmd == F_SETFL) { } else if (cmd == F_SETFL) {

View file

@ -53,7 +53,7 @@ int prctl(int operation, ...) {
rc = enosys(); rc = enosys();
} }
#ifdef SYSDEBUG #if SYSDEBUG
if (operation == PR_CAPBSET_READ || operation == PR_CAPBSET_DROP) { if (operation == PR_CAPBSET_READ || operation == PR_CAPBSET_DROP) {
STRACE("prctl(%s, %s) → %d% m", DescribePrctlOperation(operation), STRACE("prctl(%s, %s) → %d% m", DescribePrctlOperation(operation),
DescribeCapability(a), rc); DescribeCapability(a), rc);

View file

@ -46,7 +46,7 @@ int sys_ptrace(int op, ...) {
data = va_arg(va, long *); data = va_arg(va, long *);
va_end(va); va_end(va);
rc = __sys_ptrace(op, pid, addr, data); rc = __sys_ptrace(op, pid, addr, data);
#ifdef SYSDEBUG #if SYSDEBUG
if (UNLIKELY(__strace > 0) && strace_enabled(0) > 0) { if (UNLIKELY(__strace > 0) && strace_enabled(0) > 0) {
if (rc != -1 && IsPeek(op) && data) { if (rc != -1 && IsPeek(op) && data) {
STRACE("sys_ptrace(%s, %d, %p, [%p]) → %p% m", DescribePtrace(op), pid, STRACE("sys_ptrace(%s, %d, %p, [%p]) → %p% m", DescribePtrace(op), pid,

View file

@ -2,7 +2,7 @@
#define COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_ #define COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_
#ifndef SYSDEBUG #ifndef SYSDEBUG
#define SYSDEBUG 1 #define SYSDEBUG 0
#endif #endif
#define _NTTRACE 0 /* not configurable w/ flag yet */ #define _NTTRACE 0 /* not configurable w/ flag yet */

View file

@ -61,7 +61,7 @@
void WipeKeystrokes(void); void WipeKeystrokes(void);
static textwindows wontreturn void AbortFork(const char *func) { static textwindows wontreturn void AbortFork(const char *func) {
#ifdef SYSDEBUG #if SYSDEBUG
kprintf("fork() %s() failed with win32 error %d\n", func, GetLastError()); kprintf("fork() %s() failed with win32 error %d\n", func, GetLastError());
#endif #endif
TerminateThisProcess(SIGSTKFLT); TerminateThisProcess(SIGSTKFLT);
@ -104,7 +104,7 @@ static dontinline textwindows bool WriteAll(int64_t h, void *buf, size_t n) {
#ifndef NDEBUG #ifndef NDEBUG
if (ok) ok = ForkIo2(h, &n, sizeof(n), WriteFile, "WriteFile", false); if (ok) ok = ForkIo2(h, &n, sizeof(n), WriteFile, "WriteFile", false);
#endif #endif
#ifdef SYSDEBUG #if SYSDEBUG
if (!ok) { if (!ok) {
kprintf("failed to write %zu bytes to forked child: %d\n", n, kprintf("failed to write %zu bytes to forked child: %d\n", n,
GetLastError()); GetLastError());
@ -194,7 +194,7 @@ textwindows void WinMainForked(void) {
if (!varlen || varlen >= ARRAYLEN(fvar)) return; if (!varlen || varlen >= ARRAYLEN(fvar)) return;
NTTRACE("WinMainForked()"); NTTRACE("WinMainForked()");
SetEnvironmentVariable(u"_FORK", NULL); SetEnvironmentVariable(u"_FORK", NULL);
#ifdef SYSDEBUG #if SYSDEBUG
int64_t oncrash = AddVectoredExceptionHandler(1, (void *)OnForkCrash); int64_t oncrash = AddVectoredExceptionHandler(1, (void *)OnForkCrash);
#endif #endif
ParseInt(fvar, &reader); ParseInt(fvar, &reader);
@ -271,7 +271,7 @@ textwindows void WinMainForked(void) {
fds->p[2].handle = GetStdHandle(kNtStdErrorHandle); fds->p[2].handle = GetStdHandle(kNtStdErrorHandle);
// restore the crash reporting stuff // restore the crash reporting stuff
#ifdef SYSDEBUG #if SYSDEBUG
RemoveVectoredExceptionHandler(oncrash); RemoveVectoredExceptionHandler(oncrash);
#endif #endif
if (_weaken(__sig_init)) { if (_weaken(__sig_init)) {
@ -314,7 +314,7 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
startinfo.hStdOutput = g_fds.p[1].handle; startinfo.hStdOutput = g_fds.p[1].handle;
startinfo.hStdError = g_fds.p[2].handle; startinfo.hStdError = g_fds.p[2].handle;
args = __argv; args = __argv;
#ifdef SYSDEBUG #if SYSDEBUG
// If --strace was passed to this program, then propagate it the // If --strace was passed to this program, then propagate it the
// forked process since the flag was removed by __intercept_flag // forked process since the flag was removed by __intercept_flag
if (strace_enabled(0) > 0) { if (strace_enabled(0) > 0) {

View file

@ -55,7 +55,7 @@ vfork:
#if !IsTiny() #if !IsTiny()
push %rbp push %rbp
mov %rsp,%rbp mov %rsp,%rbp
#ifdef SYSDEBUG #if SYSDEBUG
ezlea .Llog,di ezlea .Llog,di
call __stracef call __stracef
#endif #endif
@ -93,7 +93,7 @@ vfork:
b fork // which doesn't support vfork() b fork // which doesn't support vfork()
1: 1:
#ifdef SYSDEBUG #if SYSDEBUG
stp x29,x30,[sp,-16]! stp x29,x30,[sp,-16]!
adrp x0,.Llog adrp x0,.Llog
add x0,x0,:lo12:.Llog add x0,x0,:lo12:.Llog
@ -130,7 +130,7 @@ vfork:
#endif #endif
.endfn vfork,globl .endfn vfork,globl
#ifdef SYSDEBUG #if SYSDEBUG
.rodata.str1.1 .rodata.str1.1
.Llog: .ascii STRACE_PROLOGUE .Llog: .ascii STRACE_PROLOGUE
.asciz "vfork()\n" .asciz "vfork()\n"

View file

@ -40,7 +40,7 @@ cosmo: push %rbp
mov %rdx,%r14 mov %rdx,%r14
mov %rcx,%r15 mov %rcx,%r15
#ifdef SYSDEBUG #if SYSDEBUG
call __strace_init call __strace_init
mov %eax,%r12d mov %eax,%r12d
#endif /* SYSDEBUG */ #endif /* SYSDEBUG */

View file

@ -163,7 +163,7 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1) {
_init(); _init();
// initialize program // initialize program
#ifdef SYSDEBUG #if SYSDEBUG
argc = __strace_init(argc, argv, envp, auxv); argc = __strace_init(argc, argv, envp, auxv);
#endif #endif
for (init_f **fp = __init_array_end; fp-- > __init_array_start;) { for (init_f **fp = __init_array_end; fp-- > __init_array_start;) {

View file

@ -57,7 +57,7 @@ int __untrack_memory(struct MemoryIntervals *, int, int,
void (*)(struct MemoryIntervals *, int, int)); void (*)(struct MemoryIntervals *, int, int));
void __release_memory_nt(struct MemoryIntervals *, int, int); void __release_memory_nt(struct MemoryIntervals *, int, int);
int __untrack_memories(void *, size_t); int __untrack_memories(void *, size_t);
size_t __get_memtrack_size(struct MemoryIntervals *); size_t __get_memtrack_size(struct MemoryIntervals *) nosideeffect;
#ifdef __x86_64__ #ifdef __x86_64__
/* /*

View file

@ -466,7 +466,7 @@ inline void *__mmap_unlocked(void *addr, size_t size, int prot, int flags,
*/ */
void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) { void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) {
void *res; void *res;
#ifdef SYSDEBUG #if SYSDEBUG
size_t toto = 0; size_t toto = 0;
#if _KERNTRACE || _NTTRACE #if _KERNTRACE || _NTTRACE
if (IsWindows()) { if (IsWindows()) {
@ -487,9 +487,11 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) {
toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0; toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0;
#endif #endif
__mmi_unlock(); __mmi_unlock();
#if SYSDEBUG
STRACE("mmap(%p, %'zu, %s, %s, %d, %'ld) → %p% m (%'zu bytes total)", addr, STRACE("mmap(%p, %'zu, %s, %s, %d, %'ld) → %p% m (%'zu bytes total)", addr,
size, DescribeProtFlags(prot), DescribeMapFlags(flags), fd, off, res, size, DescribeProtFlags(prot), DescribeMapFlags(flags), fd, off, res,
toto); toto);
#endif
return res; return res;
} }

View file

@ -153,9 +153,7 @@ int munmap(void *p, size_t n) {
int rc; int rc;
__mmi_lock(); __mmi_lock();
rc = __munmap_unlocked(p, n); rc = __munmap_unlocked(p, n);
#if SYSDEBUG
size_t toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0; size_t toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0;
#endif
__mmi_unlock(); __mmi_unlock();
STRACE("munmap(%.12p, %'zu) → %d% m (%'zu bytes total)", p, n, rc, toto); STRACE("munmap(%.12p, %'zu) → %d% m (%'zu bytes total)", p, n, rc, toto);
return rc; return rc;

View file

@ -19,7 +19,6 @@
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/serialize.h"
#include "libc/intrin/nomultics.internal.h" #include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/weaken.h" #include "libc/intrin/weaken.h"
#include "libc/limits.h" #include "libc/limits.h"
@ -41,6 +40,7 @@
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h" #include "libc/runtime/stack.h"
#include "libc/runtime/winargs.internal.h" #include "libc/runtime/winargs.internal.h"
#include "libc/serialize.h"
#include "libc/sock/internal.h" #include "libc/sock/internal.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/prot.h"
@ -271,7 +271,7 @@ abi int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
__umask = 077; __umask = 077;
__pid = __imp_GetCurrentProcessId(); __pid = __imp_GetCurrentProcessId();
cmdline = MyCommandLine(); cmdline = MyCommandLine();
#ifdef SYSDEBUG #if SYSDEBUG
// sloppy flag-only check for early initialization // sloppy flag-only check for early initialization
if (StrStr(cmdline, u"--strace")) ++__strace; if (StrStr(cmdline, u"--strace")) ++__strace;
#endif #endif

View file

@ -64,7 +64,7 @@ int getsockopt(int fd, int level, int optname, void *out_opt_optval,
rc = enotsock(); rc = enotsock();
} }
#ifdef SYSDEBUG #if SYSDEBUG
if (out_opt_optval && out_optlen && rc != -1) { if (out_opt_optval && out_optlen && rc != -1) {
STRACE("getsockopt(%d, %s, %s, [%#.*hhs], [%d]) → %d% lm", fd, STRACE("getsockopt(%d, %s, %s, [%#.*hhs], [%d]) → %d% lm", fd,
DescribeSockLevel(level), DescribeSockOptname(level, optname), DescribeSockLevel(level), DescribeSockOptname(level, optname),

View file

@ -67,14 +67,12 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
size_t n; size_t n;
} ss; } ss;
#ifdef SYSDEBUG
fd_set old_readfds; fd_set old_readfds;
fd_set *old_readfds_ptr = 0; fd_set *old_readfds_ptr = 0;
fd_set old_writefds; fd_set old_writefds;
fd_set *old_writefds_ptr = 0; fd_set *old_writefds_ptr = 0;
fd_set old_exceptfds; fd_set old_exceptfds;
fd_set *old_exceptfds_ptr = 0; fd_set *old_exceptfds_ptr = 0;
#endif
BEGIN_CANCELATION_POINT; BEGIN_CANCELATION_POINT;
if (nfds < 0) { if (nfds < 0) {
@ -87,7 +85,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
(sigmask && !__asan_is_valid(sigmask, sizeof(*sigmask))))) { (sigmask && !__asan_is_valid(sigmask, sizeof(*sigmask))))) {
rc = efault(); rc = efault();
} else { } else {
#ifdef SYSDEBUG
if (readfds) { if (readfds) {
old_readfds = *readfds; old_readfds = *readfds;
old_readfds_ptr = &old_readfds; old_readfds_ptr = &old_readfds;
@ -100,7 +97,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
old_exceptfds = *exceptfds; old_exceptfds = *exceptfds;
old_exceptfds_ptr = &old_exceptfds; old_exceptfds_ptr = &old_exceptfds;
} }
#endif
if (IsLinux()) { if (IsLinux()) {
if (timeout) { if (timeout) {
ts = *timeout; ts = *timeout;

View file

@ -48,7 +48,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout) { struct timeval *timeout) {
int rc; int rc;
#ifdef SYSDEBUG
fd_set old_readfds; fd_set old_readfds;
fd_set *old_readfds_ptr = 0; fd_set *old_readfds_ptr = 0;
fd_set old_writefds; fd_set old_writefds;
@ -57,7 +56,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
fd_set *old_exceptfds_ptr = 0; fd_set *old_exceptfds_ptr = 0;
struct timeval old_timeout; struct timeval old_timeout;
struct timeval *old_timeout_ptr = 0; struct timeval *old_timeout_ptr = 0;
#endif
POLLTRACE("select(%d, %p, %p, %p, %s) → ...", nfds, readfds, writefds, POLLTRACE("select(%d, %p, %p, %p, %s) → ...", nfds, readfds, writefds,
exceptfds, DescribeTimeval(0, timeout)); exceptfds, DescribeTimeval(0, timeout));
@ -72,7 +70,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
(timeout && !__asan_is_valid(timeout, sizeof(*timeout))))) { (timeout && !__asan_is_valid(timeout, sizeof(*timeout))))) {
rc = efault(); rc = efault();
} else { } else {
#ifdef SYSDEBUG
if (readfds) { if (readfds) {
old_readfds = *readfds; old_readfds = *readfds;
old_readfds_ptr = &old_readfds; old_readfds_ptr = &old_readfds;
@ -89,7 +86,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
old_timeout = *timeout; old_timeout = *timeout;
old_timeout_ptr = &old_timeout; old_timeout_ptr = &old_timeout;
} }
#endif
if (!IsWindows()) { if (!IsWindows()) {
#ifdef __aarch64__ #ifdef __aarch64__
struct timespec ts, *tsp; struct timespec ts, *tsp;

View file

@ -86,7 +86,7 @@ int setsockopt(int fd, int level, int optname, const void *optval,
rc = enotsock(); rc = enotsock();
} }
#ifdef SYSDEBUG #if SYSDEBUG
if (!(rc == -1 && errno == EFAULT)) { if (!(rc == -1 && errno == EFAULT)) {
STRACE("setsockopt(%d, %s, %s, %#.*hhs, %'u) → %d% lm", fd, STRACE("setsockopt(%d, %s, %s, %#.*hhs, %'u) → %d% lm", fd,
DescribeSockLevel(level), DescribeSockOptname(level, optname), DescribeSockLevel(level), DescribeSockOptname(level, optname),

View file

@ -379,12 +379,12 @@ _init_systemfive_magnums:
jnz 3b jnz 3b
xchg %rbx,%rax xchg %rbx,%rax
stosq stosq
#ifdef SYSDEBUG #if SYSDEBUG
inc %r8d inc %r8d
#endif #endif
jmp 2b jmp 2b
5: nop 5: nop
#ifdef SYSDEBUG #if SYSDEBUG
push %rdi push %rdi
push %rsi push %rsi
push %r8 push %r8
@ -449,7 +449,7 @@ _init_systemfive_done:
nop nop
.init.end 300,_init_systemfive,globl,hidden .init.end 300,_init_systemfive,globl,hidden
#ifdef SYSDEBUG #if SYSDEBUG
.rodata.str1.1 .rodata.str1.1
.Llog: .ascii STRACE_PROLOGUE .Llog: .ascii STRACE_PROLOGUE
.ascii "bell system five system call support" .ascii "bell system five system call support"