jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.37k stars 597 forks source link

cosmocc segfaults on static struct sigaction #1183

Open tavianator opened 2 months ago

tavianator commented 2 months ago

With cosmocc-3.3.6:

tavianator@tachyon $ cat foo.c
#include <signal.h>

static struct sigaction action = {
        .sa_sigaction = 0,
        .sa_flags = SA_RESTART | SA_SIGINFO,
};
tavianator@tachyon $ cosmocc foo.c
foo.c:6:1: internal compiler error: SIGSEGV
    6 | };
      | ^
no stack trace because unwind library not available
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <https://gcc.gnu.org/bugs/> for instructions.
ahgamut commented 2 months ago

I haven't seen this one in a while, it's probably because -fportcosmo is not reading that union right before correctly.

Thanks for posting a minimal example! Does it work if you use earlier versions of Cosmopolitan Libc and cosmocc, say from https://github.com/jart/cosmopolitan/releases/tag/3.2.4 (I don't expect it to, but if it does then that means the error is from a different spot).

ahgamut commented 1 month ago

Updated the gcc build to handle this case. I ran the below script for cosmocc to compile the example file without crashing.

cat > foo.c <<EOF
#include <signal.h>

static struct sigaction action = {
        .sa_sigaction = 0,
        .sa_flags = SA_RESTART | SA_SIGINFO,
};

int main() {
    return 0;
}
EOF
wget https://github.com/jart/cosmopolitan/releases/download/3.3.6/cosmocc-3.3.6.zip
unzip cosmocc-3.3.6.zip
wget https://github.com/ahgamut/superconfigure/releases/download/z0.0.40/aarch64-gcc.zip
unzip -o aarch64-gcc.zip
wget https://github.com/ahgamut/superconfigure/releases/download/z0.0.40/x86_64-gcc.zip
unzip -o x86_64-gcc.zip
./bin/cosmocc foo.c -o foo.com
./foo.com

@jart after confirming the build works, we can close the issue when releasing a new cosmocc.