Further improve usability of cosmocc

- Support -s flag in cosmocc
- Support posix_spawn() setsid() feature
- Disable monorepo debug path prefix stripping
This commit is contained in:
Justine Tunney 2023-07-10 05:55:00 -07:00
parent f7ae50462a
commit ee6566a152
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
9 changed files with 40 additions and 15 deletions

View file

@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
mode: ["", tiny, rel, nox87, aarch64, tinylinux, optlinux] mode: ["", tiny, rel, aarch64, tinylinux, optlinux]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View file

@ -172,7 +172,6 @@ DEFAULT_CCFLAGS += \
-Wall \ -Wall \
-Werror \ -Werror \
-fno-omit-frame-pointer \ -fno-omit-frame-pointer \
-fdebug-prefix-map='$(PWD)'= \
-frecord-gcc-switches -frecord-gcc-switches
DEFAULT_COPTS ?= \ DEFAULT_COPTS ?= \
@ -259,8 +258,7 @@ endif
ASONLYFLAGS = \ ASONLYFLAGS = \
-c \ -c \
-g \ -g
--debug-prefix-map='$(PWD)'=
DEFAULT_LDLIBS = DEFAULT_LDLIBS =

View file

@ -18,6 +18,7 @@
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
/** /**
@ -26,7 +27,11 @@
*/ */
int setsid(void) { int setsid(void) {
int rc; int rc;
rc = sys_setsid(); if (!IsWindows() && !IsMetal()) {
rc = sys_setsid();
} else {
rc = 0;
}
STRACE("setsid() → %d% m", rc); STRACE("setsid() → %d% m", rc);
return rc; return rc;
} }

View file

@ -735,7 +735,6 @@ void abort(void) wontreturn;
#pragma GCC diagnostic error "-Wnonnull" #pragma GCC diagnostic error "-Wnonnull"
#pragma GCC diagnostic error "-Wunused-result" #pragma GCC diagnostic error "-Wunused-result"
#pragma GCC diagnostic error "-Wstrict-aliasing" #pragma GCC diagnostic error "-Wstrict-aliasing"
#pragma GCC diagnostic error "-Wshift-negative-value"
#ifndef __cplusplus #ifndef __cplusplus
#pragma GCC diagnostic error "-Wimplicit-function-declaration" #pragma GCC diagnostic error "-Wimplicit-function-declaration"
#if __GNUC__ >= 6 #if __GNUC__ >= 6

View file

@ -84,6 +84,12 @@ int posix_spawn(int *pid, const char *path,
if (!(child = vfork())) { if (!(child = vfork())) {
if (attrp && *attrp) { if (attrp && *attrp) {
posix_spawnattr_getflags(attrp, &flags); posix_spawnattr_getflags(attrp, &flags);
if (flags & POSIX_SPAWN_SETSID) {
if (setsid()) {
STRACE("posix_spawn fail #%d", 1);
_Exit(127);
}
}
if (flags & POSIX_SPAWN_SETPGROUP) { if (flags & POSIX_SPAWN_SETPGROUP) {
if (setpgid(0, (*attrp)->pgroup)) { if (setpgid(0, (*attrp)->pgroup)) {
STRACE("posix_spawn fail #%d", 1); STRACE("posix_spawn fail #%d", 1);

View file

@ -3,12 +3,13 @@
#include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#define POSIX_SPAWN_RESETIDS 0x01 #define POSIX_SPAWN_RESETIDS 1
#define POSIX_SPAWN_SETPGROUP 0x02 #define POSIX_SPAWN_SETPGROUP 2
#define POSIX_SPAWN_SETSIGDEF 0x04 #define POSIX_SPAWN_SETSIGDEF 4
#define POSIX_SPAWN_SETSIGMASK 0x08 #define POSIX_SPAWN_SETSIGMASK 8
#define POSIX_SPAWN_SETSCHEDPARAM 0x10 #define POSIX_SPAWN_SETSCHEDPARAM 16
#define POSIX_SPAWN_SETSCHEDULER 0x20 #define POSIX_SPAWN_SETSCHEDULER 32
#define POSIX_SPAWN_SETSID 128
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_

View file

@ -89,6 +89,7 @@ int posix_spawnattr_getflags(const posix_spawnattr_t *attr, short *flags) {
* - `POSIX_SPAWN_SETSIGMASK` * - `POSIX_SPAWN_SETSIGMASK`
* - `POSIX_SPAWN_SETSCHEDPARAM` * - `POSIX_SPAWN_SETSCHEDPARAM`
* - `POSIX_SPAWN_SETSCHEDULER` * - `POSIX_SPAWN_SETSCHEDULER`
* - `POSIX_SPAWN_SETSID`
* @return 0 on success, or errno on error * @return 0 on success, or errno on error
* @raise EINVAL if `flags` has invalid bits * @raise EINVAL if `flags` has invalid bits
*/ */
@ -96,9 +97,10 @@ int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags) {
if (!(IsLinux() || IsFreebsd() || IsNetbsd())) { if (!(IsLinux() || IsFreebsd() || IsNetbsd())) {
flags &= ~(POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER); flags &= ~(POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER);
} }
if (flags & ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP | if (flags &
POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK | ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF |
POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)) { POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSCHEDPARAM |
POSIX_SPAWN_SETSCHEDULER | POSIX_SPAWN_SETSID)) {
return EINVAL; return EINVAL;
} }
(*attr)->flags = flags; (*attr)->flags = flags;

View file

@ -78,6 +78,7 @@ APEFLAGS="-L$COSMOS/lib -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/public/ape.l
LDLIBS="$COSMO/o/$MODE/third_party/libcxx/libcxx.a $COSMO/o/$MODE/cosmopolitan.a" LDLIBS="$COSMO/o/$MODE/third_party/libcxx/libcxx.a $COSMO/o/$MODE/cosmopolitan.a"
CXX="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-g++" CXX="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-g++"
STRIP="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-strip"
OBJCOPY="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-objcopy" OBJCOPY="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-objcopy"
FIXUPOBJ="$COSMO/o/$MODE/tool/build/fixupobj.com" FIXUPOBJ="$COSMO/o/$MODE/tool/build/fixupobj.com"
ZIPCOPY="$COSMO/o/$MODE/tool/build/zipcopy.com" ZIPCOPY="$COSMO/o/$MODE/tool/build/zipcopy.com"
@ -115,6 +116,7 @@ done
OPT= OPT=
FIRST=1 FIRST=1
OUTPUT= OUTPUT=
SFLAG=0
INTENT=ld INTENT=ld
NEED_OUTPUT= NEED_OUTPUT=
RELOCATABLE=0 RELOCATABLE=0
@ -140,6 +142,9 @@ for x; do
OPT=$x OPT=$x
elif [ x"$x" = x"-c" ]; then elif [ x"$x" = x"-c" ]; then
INTENT=cc INTENT=cc
elif [ x"$x" = x"-s" ]; then
SFLAG=1
continue
elif [ x"$x" = x"-r" ]; then elif [ x"$x" = x"-r" ]; then
RELOCATABLE=1 RELOCATABLE=1
elif [ x"$x" = x"-E" ]; then elif [ x"$x" = x"-E" ]; then
@ -204,6 +209,8 @@ if [ -n "$OUTPUT" ] && [ -f "$OUTPUT" ]; then
mv -f "$OUTPUT" "$OUTPUT.dbg" || exit mv -f "$OUTPUT" "$OUTPUT.dbg" || exit
"$OBJCOPY" -S -O binary "$OUTPUT.dbg" "$OUTPUT" || exit "$OBJCOPY" -S -O binary "$OUTPUT.dbg" "$OUTPUT" || exit
"$ZIPCOPY" "$OUTPUT.dbg" "$OUTPUT" || exit "$ZIPCOPY" "$OUTPUT.dbg" "$OUTPUT" || exit
elif [ $SFLAG -eq 1 ]; then
"$STRIP" "$OUTPUT" || exit
fi fi
fi fi
fi fi

View file

@ -78,6 +78,7 @@ APEFLAGS="-L$COSMOS/lib -Wl,--gc-sections -Wl,-T,$COSMO/o/$MODE/ape/public/ape.l
LDLIBS="$COSMO/o/$MODE/cosmopolitan.a" LDLIBS="$COSMO/o/$MODE/cosmopolitan.a"
CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc" CC="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
STRIP="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-strip"
OBJCOPY="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-objcopy" OBJCOPY="$COSMO/o/third_party/gcc/bin/x86_64-linux-musl-objcopy"
FIXUPOBJ="$COSMO/o/$MODE/tool/build/fixupobj.com" FIXUPOBJ="$COSMO/o/$MODE/tool/build/fixupobj.com"
ZIPCOPY="$COSMO/o/$MODE/tool/build/zipcopy.com" ZIPCOPY="$COSMO/o/$MODE/tool/build/zipcopy.com"
@ -115,6 +116,7 @@ done
OPT= OPT=
FIRST=1 FIRST=1
OUTPUT= OUTPUT=
SFLAG=0
INTENT=ld INTENT=ld
NEED_OUTPUT= NEED_OUTPUT=
RELOCATABLE=0 RELOCATABLE=0
@ -138,6 +140,9 @@ for x; do
OPT=$x OPT=$x
elif [ x"$x" = x"-c" ]; then elif [ x"$x" = x"-c" ]; then
INTENT=cc INTENT=cc
elif [ x"$x" = x"-s" ]; then
SFLAG=1
continue
elif [ x"$x" = x"-r" ]; then elif [ x"$x" = x"-r" ]; then
RELOCATABLE=1 RELOCATABLE=1
elif [ x"$x" = x"-E" ]; then elif [ x"$x" = x"-E" ]; then
@ -202,6 +207,8 @@ if [ -n "$OUTPUT" ] && [ -f "$OUTPUT" ]; then
mv -f "$OUTPUT" "$OUTPUT.dbg" || exit mv -f "$OUTPUT" "$OUTPUT.dbg" || exit
"$OBJCOPY" -S -O binary "$OUTPUT.dbg" "$OUTPUT" || exit "$OBJCOPY" -S -O binary "$OUTPUT.dbg" "$OUTPUT" || exit
"$ZIPCOPY" "$OUTPUT.dbg" "$OUTPUT" || exit "$ZIPCOPY" "$OUTPUT.dbg" "$OUTPUT" || exit
elif [ $SFLAG -eq 1 ]; then
"$STRIP" "$OUTPUT" || exit
fi fi
fi fi
fi fi