mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 22:38:30 +00:00
Introduce cosmocc flags -mdbg -mtiny -moptlinux
The cosmocc.zip toolchain will now include four builds of the libcosmo.a runtime libraries. You can pass the -mdbg flag if you want to debug your cosmopolitan runtime. You can pass the -moptlinux flag if you don't want windows code lurking in your binary. See tool/cosmocc/README.md for more details on how these flags may be used and their important implications.
This commit is contained in:
parent
59692b0882
commit
642e9cb91a
22 changed files with 404 additions and 56 deletions
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/intrin/fds.h"
|
||||
#include "libc/calls/syscall-nt.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
|
@ -25,6 +24,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/fds.h"
|
||||
#include "libc/intrin/strace.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/nt/comms.h"
|
||||
|
@ -52,6 +52,7 @@ static const char *DescribeFlush(char buf[12], int action) {
|
|||
}
|
||||
|
||||
static dontinline textwindows int sys_tcflush_nt(int fd, int queue) {
|
||||
#ifdef __x86_64__
|
||||
if (!sys_isatty(fd)) {
|
||||
return -1; // ebadf, enotty
|
||||
}
|
||||
|
@ -59,6 +60,9 @@ static dontinline textwindows int sys_tcflush_nt(int fd, int queue) {
|
|||
return 0; // windows console output is never buffered
|
||||
}
|
||||
return FlushConsoleInputBytes();
|
||||
#else
|
||||
return enosys();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -557,7 +557,9 @@ static void *foreign_thunk_nt(void *func) {
|
|||
// movabs $tramp,%r10
|
||||
code[14] = 0x49;
|
||||
code[15] = 0xba;
|
||||
#ifdef __x86_64__
|
||||
WRITE64LE(code + 16, (uintptr_t)__sysv2nt14);
|
||||
#endif
|
||||
// jmp *%r10
|
||||
code[24] = 0x41;
|
||||
code[25] = 0xff;
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/blockcancel.internal.h"
|
||||
#include "libc/calls/cp.internal.h"
|
||||
#include "libc/intrin/describebacktrace.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
|
@ -46,7 +49,11 @@ void end_cancelation_point(int state) {
|
|||
}
|
||||
}
|
||||
|
||||
void report_cancelation_point(void) {
|
||||
void report_cancelation_point(int sysv_ordinal, int xnu_ordinal) {
|
||||
char bt[160];
|
||||
struct StackFrame *bp = __builtin_frame_address(0);
|
||||
kprintf("error: report_cancelation_point(%#x, %#x) %s\n", sysv_ordinal,
|
||||
xnu_ordinal, (DescribeBacktrace)(bt, bp));
|
||||
__builtin_trap();
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,8 @@ static relegated void __oncrash_impl(int sig, siginfo_t *si, ucontext_t *ctx) {
|
|||
if (j)
|
||||
Append(b, " ");
|
||||
Append(b, "%s%016lx%s x%d%s", ColorRegister(r),
|
||||
ctx->uc_mcontext.regs[r], reset, r, r == 8 || r == 9 ? " " : "");
|
||||
((uint64_t *)ctx->uc_mcontext.regs)[r], reset, r,
|
||||
r == 8 || r == 9 ? " " : "");
|
||||
}
|
||||
Append(b, "\n");
|
||||
}
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
*
|
||||
* This macro should be used when specifying callbacks in the WIN32 API.
|
||||
*/
|
||||
#ifdef __x86_64__
|
||||
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)
|
||||
#else
|
||||
#define NT2SYSV(FUNCTION) FUNCTION
|
||||
#endif
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_ */
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/intrin/fds.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/rlimit.internal.h"
|
||||
#include "libc/calls/struct/rusage.internal.h"
|
||||
|
@ -39,6 +38,7 @@
|
|||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/describeflags.h"
|
||||
#include "libc/intrin/dll.h"
|
||||
#include "libc/intrin/fds.h"
|
||||
#include "libc/intrin/strace.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
|
@ -95,6 +95,10 @@
|
|||
|
||||
#define CLOSER_CONTAINER(e) DLL_CONTAINER(struct Closer, elem, e)
|
||||
|
||||
static atomic_bool has_vfork; // i.e. not qemu/wsl/xnu/openbsd
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
struct Closer {
|
||||
int64_t handle;
|
||||
struct Dll elem;
|
||||
|
@ -106,8 +110,6 @@ struct SpawnFds {
|
|||
struct Dll *closers;
|
||||
};
|
||||
|
||||
static atomic_bool has_vfork; // i.e. not qemu/wsl/xnu/openbsd
|
||||
|
||||
static textwindows int64_t spawnfds_handle(struct SpawnFds *fds, int fd) {
|
||||
if (__is_cloexec(fds->p + fd))
|
||||
return -1;
|
||||
|
@ -429,6 +431,8 @@ static textwindows dontinline errno_t posix_spawn_nt(
|
|||
return err;
|
||||
}
|
||||
|
||||
#endif // __x86_64__
|
||||
|
||||
/**
|
||||
* Spawns process, the POSIX way, e.g.
|
||||
*
|
||||
|
@ -482,8 +486,10 @@ errno_t posix_spawn(int *pid, const char *path,
|
|||
const posix_spawn_file_actions_t *file_actions,
|
||||
const posix_spawnattr_t *attrp, char *const argv[],
|
||||
char *const envp[]) {
|
||||
#ifdef __x86_64__
|
||||
if (IsWindows())
|
||||
return posix_spawn_nt(pid, path, file_actions, attrp, argv, envp);
|
||||
#endif
|
||||
int pfds[2];
|
||||
bool use_pipe;
|
||||
volatile int status = 0;
|
||||
|
|
|
@ -589,7 +589,9 @@ int sys_clone_linux(int flags, // rdi
|
|||
|
||||
static int LinuxThreadEntry(void *arg, int tid) {
|
||||
struct LinuxCloneArgs *wt = arg;
|
||||
#if defined(__x86_64__)
|
||||
sys_set_tls(ARCH_SET_GS, wt->tls);
|
||||
#endif
|
||||
return wt->func(wt->arg, tid);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
/**
|
||||
* Returns preferred size and alignment of thread stack.
|
||||
*/
|
||||
#ifndef MODE_DBG
|
||||
#define GetStackSize() 81920
|
||||
#else
|
||||
#define GetStackSize() 163840
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns preferred stack guard size.
|
||||
|
|
|
@ -88,7 +88,7 @@ o/$(MODE)/libc/sysv/sysret.o: private \
|
|||
|
||||
ifeq ($(ARCH),aarch64)
|
||||
o/$(MODE)/libc/sysv/sysv.o: private \
|
||||
CFLAGS += \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-ffixed-x0 \
|
||||
-ffixed-x1 \
|
||||
-ffixed-x2 \
|
||||
|
|
|
@ -37,7 +37,7 @@ register long freebsd_ordinal asm("x9");
|
|||
register long xnu_ordinal asm("x16");
|
||||
register long cosmo_tls_register asm("x28");
|
||||
|
||||
void report_cancelation_point(void);
|
||||
void report_cancelation_point(int, int);
|
||||
|
||||
dontinline long systemfive_cancel(void) {
|
||||
return _weaken(_pthread_cancel_ack)();
|
||||
|
@ -58,9 +58,9 @@ dontinline long systemfive_cancellable(void) {
|
|||
return systemfive_cancel();
|
||||
}
|
||||
#if IsModeDbg()
|
||||
if (!(pth->pt_flags & PT_INCANCEL)) {
|
||||
if (!(pth->pt_flags & PT_INCANCEL) && !(pth->pt_flags & PT_NOCANCEL)) {
|
||||
if (_weaken(report_cancelation_point)) {
|
||||
_weaken(report_cancelation_point)();
|
||||
_weaken(report_cancelation_point)(sysv_ordinal, xnu_ordinal);
|
||||
}
|
||||
__builtin_trap();
|
||||
}
|
||||
|
|
|
@ -930,7 +930,7 @@ powl(long double x, long double y)
|
|||
z = one - (r - z);
|
||||
o.value = z;
|
||||
j = o.parts32.mswhi;
|
||||
j += (n << 16);
|
||||
j += (int32_t)((uint32_t)n << 16); // TODO(jart): why ubsan
|
||||
if ((j >> 16) <= 0)
|
||||
z = scalbnl (z, n); /* subnormal output */
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue