Skip to content

Commit

Permalink
Exclude strace from MODE=tiny builds
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jart committed Nov 29, 2023
1 parent b7e1dc8 commit 2b960bb
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 33 deletions.
21 changes: 21 additions & 0 deletions build/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,27 @@ PYFLAGS += \
-O2 \
-B
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)
# TODO(jart): -mcmodel=tiny
CONFIG_CPPFLAGS += \
Expand Down
2 changes: 1 addition & 1 deletion libc/calls/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ int fcntl(int fd, int cmd, ...) {
rc = ebadf();
}

#ifdef SYSDEBUG
#if SYSDEBUG
if (rc != -1 && cmd == F_GETFL) {
STRACE("fcntl(%d, F_GETFL) → %s", fd, DescribeOpenFlags(rc));
} else if (cmd == F_SETFL) {
Expand Down
2 changes: 1 addition & 1 deletion libc/calls/prctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int prctl(int operation, ...) {
rc = enosys();
}

#ifdef SYSDEBUG
#if SYSDEBUG
if (operation == PR_CAPBSET_READ || operation == PR_CAPBSET_DROP) {
STRACE("prctl(%s, %s) → %d% m", DescribePrctlOperation(operation),
DescribeCapability(a), rc);
Expand Down
2 changes: 1 addition & 1 deletion libc/calls/sys_ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int sys_ptrace(int op, ...) {
data = va_arg(va, long *);
va_end(va);
rc = __sys_ptrace(op, pid, addr, data);
#ifdef SYSDEBUG
#if SYSDEBUG
if (UNLIKELY(__strace > 0) && strace_enabled(0) > 0) {
if (rc != -1 && IsPeek(op) && data) {
STRACE("sys_ptrace(%s, %d, %p, [%p]) → %p% m", DescribePtrace(op), pid,
Expand Down
2 changes: 1 addition & 1 deletion libc/intrin/strace.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_

#ifndef SYSDEBUG
#define SYSDEBUG 1
#define SYSDEBUG 0
#endif

#define _NTTRACE 0 /* not configurable w/ flag yet */
Expand Down
10 changes: 5 additions & 5 deletions libc/proc/fork-nt.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
void WipeKeystrokes(void);

static textwindows wontreturn void AbortFork(const char *func) {
#ifdef SYSDEBUG
#if SYSDEBUG
kprintf("fork() %s() failed with win32 error %d\n", func, GetLastError());
#endif
TerminateThisProcess(SIGSTKFLT);
Expand Down Expand Up @@ -104,7 +104,7 @@ static dontinline textwindows bool WriteAll(int64_t h, void *buf, size_t n) {
#ifndef NDEBUG
if (ok) ok = ForkIo2(h, &n, sizeof(n), WriteFile, "WriteFile", false);
#endif
#ifdef SYSDEBUG
#if SYSDEBUG
if (!ok) {
kprintf("failed to write %zu bytes to forked child: %d\n", n,
GetLastError());
Expand Down Expand Up @@ -194,7 +194,7 @@ textwindows void WinMainForked(void) {
if (!varlen || varlen >= ARRAYLEN(fvar)) return;
NTTRACE("WinMainForked()");
SetEnvironmentVariable(u"_FORK", NULL);
#ifdef SYSDEBUG
#if SYSDEBUG
int64_t oncrash = AddVectoredExceptionHandler(1, (void *)OnForkCrash);
#endif
ParseInt(fvar, &reader);
Expand Down Expand Up @@ -271,7 +271,7 @@ textwindows void WinMainForked(void) {
fds->p[2].handle = GetStdHandle(kNtStdErrorHandle);

// restore the crash reporting stuff
#ifdef SYSDEBUG
#if SYSDEBUG
RemoveVectoredExceptionHandler(oncrash);
#endif
if (_weaken(__sig_init)) {
Expand Down Expand Up @@ -314,7 +314,7 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
startinfo.hStdOutput = g_fds.p[1].handle;
startinfo.hStdError = g_fds.p[2].handle;
args = __argv;
#ifdef SYSDEBUG
#if SYSDEBUG
// If --strace was passed to this program, then propagate it the
// forked process since the flag was removed by __intercept_flag
if (strace_enabled(0) > 0) {
Expand Down
6 changes: 3 additions & 3 deletions libc/proc/vfork.S
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ vfork:
#if !IsTiny()
push %rbp
mov %rsp,%rbp
#ifdef SYSDEBUG
#if SYSDEBUG
ezlea .Llog,di
call __stracef
#endif
Expand Down Expand Up @@ -93,7 +93,7 @@ vfork:
b fork // which doesn't support vfork()
1:

#ifdef SYSDEBUG
#if SYSDEBUG
stp x29,x30,[sp,-16]!
adrp x0,.Llog
add x0,x0,:lo12:.Llog
Expand Down Expand Up @@ -130,7 +130,7 @@ vfork:
#endif
.endfn vfork,globl

#ifdef SYSDEBUG
#if SYSDEBUG
.rodata.str1.1
.Llog: .ascii STRACE_PROLOGUE
.asciz "vfork()\n"
Expand Down
2 changes: 1 addition & 1 deletion libc/runtime/cosmo.S
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cosmo: push %rbp
mov %rdx,%r14
mov %rcx,%r15

#ifdef SYSDEBUG
#if SYSDEBUG
call __strace_init
mov %eax,%r12d
#endif /* SYSDEBUG */
Expand Down
2 changes: 1 addition & 1 deletion libc/runtime/cosmo2.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1) {

_init();
// initialize program
#ifdef SYSDEBUG
#if SYSDEBUG
argc = __strace_init(argc, argv, envp, auxv);
#endif
for (init_f **fp = __init_array_end; fp-- > __init_array_start;) {
Expand Down
2 changes: 1 addition & 1 deletion libc/runtime/memtrack.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int __untrack_memory(struct MemoryIntervals *, int, int,
void (*)(struct MemoryIntervals *, int, int));
void __release_memory_nt(struct MemoryIntervals *, int, int);
int __untrack_memories(void *, size_t);
size_t __get_memtrack_size(struct MemoryIntervals *);
size_t __get_memtrack_size(struct MemoryIntervals *) nosideeffect;

#ifdef __x86_64__
/*
Expand Down
4 changes: 3 additions & 1 deletion libc/runtime/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *res;
#ifdef SYSDEBUG
#if SYSDEBUG
size_t toto = 0;
#if _KERNTRACE || _NTTRACE
if (IsWindows()) {
Expand All @@ -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;
#endif
__mmi_unlock();
#if SYSDEBUG
STRACE("mmap(%p, %'zu, %s, %s, %d, %'ld) → %p% m (%'zu bytes total)", addr,
size, DescribeProtFlags(prot), DescribeMapFlags(flags), fd, off, res,
toto);
#endif
return res;
}

Expand Down
2 changes: 0 additions & 2 deletions libc/runtime/munmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ int munmap(void *p, size_t n) {
int rc;
__mmi_lock();
rc = __munmap_unlocked(p, n);
#if SYSDEBUG
size_t toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0;
#endif
__mmi_unlock();
STRACE("munmap(%.12p, %'zu) → %d% m (%'zu bytes total)", p, n, rc, toto);
return rc;
Expand Down
4 changes: 2 additions & 2 deletions libc/runtime/winmain.greg.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "libc/assert.h"
#include "libc/calls/internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/serialize.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/limits.h"
Expand All @@ -41,6 +40,7 @@
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/runtime/winargs.internal.h"
#include "libc/serialize.h"
#include "libc/sock/internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/prot.h"
Expand Down Expand Up @@ -271,7 +271,7 @@ abi int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
__umask = 077;
__pid = __imp_GetCurrentProcessId();
cmdline = MyCommandLine();
#ifdef SYSDEBUG
#if SYSDEBUG
// sloppy flag-only check for early initialization
if (StrStr(cmdline, u"--strace")) ++__strace;
#endif
Expand Down
2 changes: 1 addition & 1 deletion libc/sock/getsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int getsockopt(int fd, int level, int optname, void *out_opt_optval,
rc = enotsock();
}

#ifdef SYSDEBUG
#if SYSDEBUG
if (out_opt_optval && out_optlen && rc != -1) {
STRACE("getsockopt(%d, %s, %s, [%#.*hhs], [%d]) → %d% lm", fd,
DescribeSockLevel(level), DescribeSockOptname(level, optname),
Expand Down
4 changes: 0 additions & 4 deletions libc/sock/pselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
size_t n;
} ss;

#ifdef SYSDEBUG
fd_set old_readfds;
fd_set *old_readfds_ptr = 0;
fd_set old_writefds;
fd_set *old_writefds_ptr = 0;
fd_set old_exceptfds;
fd_set *old_exceptfds_ptr = 0;
#endif

BEGIN_CANCELATION_POINT;
if (nfds < 0) {
Expand All @@ -87,7 +85,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
(sigmask && !__asan_is_valid(sigmask, sizeof(*sigmask))))) {
rc = efault();
} else {
#ifdef SYSDEBUG
if (readfds) {
old_readfds = *readfds;
old_readfds_ptr = &old_readfds;
Expand All @@ -100,7 +97,6 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
old_exceptfds = *exceptfds;
old_exceptfds_ptr = &old_exceptfds;
}
#endif
if (IsLinux()) {
if (timeout) {
ts = *timeout;
Expand Down
4 changes: 0 additions & 4 deletions libc/sock/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout) {

int rc;
#ifdef SYSDEBUG
fd_set old_readfds;
fd_set *old_readfds_ptr = 0;
fd_set old_writefds;
Expand All @@ -57,7 +56,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
fd_set *old_exceptfds_ptr = 0;
struct timeval old_timeout;
struct timeval *old_timeout_ptr = 0;
#endif

POLLTRACE("select(%d, %p, %p, %p, %s) → ...", nfds, readfds, writefds,
exceptfds, DescribeTimeval(0, timeout));
Expand All @@ -72,7 +70,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
(timeout && !__asan_is_valid(timeout, sizeof(*timeout))))) {
rc = efault();
} else {
#ifdef SYSDEBUG
if (readfds) {
old_readfds = *readfds;
old_readfds_ptr = &old_readfds;
Expand All @@ -89,7 +86,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
old_timeout = *timeout;
old_timeout_ptr = &old_timeout;
}
#endif
if (!IsWindows()) {
#ifdef __aarch64__
struct timespec ts, *tsp;
Expand Down
2 changes: 1 addition & 1 deletion libc/sock/setsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int setsockopt(int fd, int level, int optname, const void *optval,
rc = enotsock();
}

#ifdef SYSDEBUG
#if SYSDEBUG
if (!(rc == -1 && errno == EFAULT)) {
STRACE("setsockopt(%d, %s, %s, %#.*hhs, %'u) → %d% lm", fd,
DescribeSockLevel(level), DescribeSockOptname(level, optname),
Expand Down
6 changes: 3 additions & 3 deletions libc/sysv/systemfive.S
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ _init_systemfive_magnums:
jnz 3b
xchg %rbx,%rax
stosq
#ifdef SYSDEBUG
#if SYSDEBUG
inc %r8d
#endif
jmp 2b
5: nop
#ifdef SYSDEBUG
#if SYSDEBUG
push %rdi
push %rsi
push %r8
Expand Down Expand Up @@ -449,7 +449,7 @@ _init_systemfive_done:
nop
.init.end 300,_init_systemfive,globl,hidden

#ifdef SYSDEBUG
#if SYSDEBUG
.rodata.str1.1
.Llog: .ascii STRACE_PROLOGUE
.ascii "bell system five system call support"
Expand Down

0 comments on commit 2b960bb

Please sign in to comment.