I have tried both just running the build/configure scripts, and I tried running the compiler directly like in the documentation (including telling it what standard to use). I've done gcc (shown), TinyCC, and clang.
~/Downloads/SubC $ ./configure
NOTE:
The signal() function of this port may cause handlers to segfault.
In this case, you can either
- uncomment the alternative signal() function in
src/targets/linux-x86-64/crt0-linux-x86-64.s
and set SYSLIBC to "/usr/lib/libc.a" in
src/targets/linux-x86-64/sys-linux-x86-64.h
(resulting in massively bloated executables)
- or, just not use signal() in your code, if that's an option.
Building for linux/x86-64. Now cd to src and run make.
~/Downloads/SubC $ cd src
~/Downloads/SubC/src $ make
cc -o scc0 cg.c decl.c error.c expr.c gen.c main.c misc.c opt.c prep.c scan.c stmt.c sym.c tree.c
In file included from cg.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from decl.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
decl.c: In function 'enumdecl':
decl.c:38:29: error: expected expression before 'constexpr'
38 | v = constexpr();
| ^~~~~~~~~
decl.c: In function 'initlist':
decl.c:80:21: error: expected expression before 'constexpr'
80 | v = constexpr();
| ^~~~~~~~~
decl.c: In function 'declarator':
decl.c:263:25: error: expected expression before 'constexpr'
263 | *pval = constexpr();
| ^~~~~~~~~
decl.c:311:34: error: expected expression before 'constexpr'
311 | *psize = constexpr();
| ^~~~~~~~~
In file included from error.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from expr.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
expr.c:877:15: error: expected identifier or '(' before 'void'
877 | int constexpr(void) {
| ^~~~
In file included from gen.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from main.c:10:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from misc.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from opt.c:9:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from prep.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from scan.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from stmt.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
stmt.c: In function 'switch_block':
stmt.c:218:36: error: expected expression before 'constexpr'
218 | cval[nc] = constexpr();
| ^~~~~~~~~
stmt.c: In function 'wrong_ctx':
stmt.c:292:27: error: expected identifier or '(' before ')' token
292 | constexpr();
| ^
In file included from sym.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
In file included from tree.c:8:
decl.h:21:19: error: expected identifier or '(' before 'void'
21 | int constexpr(void);
| ^~~~
make: *** [Makefile:48: scc0] Error 1
When I compiled myself and defined the standard c90 or c89 with gcc specifically, it did produce an executable, but one that segfaulted if actually run on anything.
~/Downloads/SubC/src $ ./scc0 -c lib/*.c
Segmentation fault
Moved onto looking at the make settings and changing things to see how far I could get that way, and that significantly helped.
~/Downloads/SubC/src $ make CC="gcc -std=c99"
gcc -std=c99 -o scc0 cg.c decl.c error.c expr.c gen.c main.c misc.c opt.c prep.c scan.c stmt.c sym.c tree.c
main.c: In function 'newfilename':
main.c:29:22: error: implicit declaration of function 'strdup'; did you mean 'strcmp'? [-Wimplicit-function-declaration]
29 | if ((ofile = strdup(file)) == NULL)
| ^~~~~~
| strcmp
main.c:29:20: error: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
29 | if ((ofile = strdup(file)) == NULL)
| ^
make: *** [Makefile:48: scc0] Error 1
I tried just adding a simpe implementation of strdup into main before newfilename is called, re-ran the Makefile, and got what seemed like a pretty reasonable output. Decided to verify by trying to run scc0 on itself, and it failed but did not segfault; the self-created binary just did not want to actually work.
~/Downloads/SubC/src $ make CC="gcc -std=c99"
gcc -std=c99 -o scc0 cg.c decl.c error.c expr.c gen.c main.c misc.c opt.c prep.c scan.c stmt.c sym.c tree.c
as -o lib/crt0.o lib/crt0.s
sed -e '/C_init.*[;@#]INIT/d' \
-e 's/\(.*\)Cexit\(.*\)EXIT/\1C_exit\2EXIT/' \
<lib/crt0.s >lib/ncrt0.s
as -o lib/ncrt0.o lib/ncrt0.s
./scc0 -c lib/init.c
./scc0 -c lib/abort.c
./scc0 -c lib/abs.c
./scc0 -c lib/atexit.c
./scc0 -c lib/atoi.c
./scc0 -c lib/bsearch.c
./scc0 -c lib/calloc.c
./scc0 -c lib/clearerr.c
./scc0 -c lib/ctime.c
./scc0 -c lib/ctype.c
./scc0 -c lib/difftime.c
./scc0 -c lib/exit.c
./scc0 -c lib/fclose.c
./scc0 -c lib/fdopen.c
./scc0 -c lib/feof.c
./scc0 -c lib/ferror.c
./scc0 -c lib/fflush.c
./scc0 -c lib/fgetc.c
./scc0 -c lib/fgetpos.c
./scc0 -c lib/fgets.c
./scc0 -c lib/fileno.c
./scc0 -c lib/fopen.c
./scc0 -c lib/fprintf.c
./scc0 -c lib/fputc.c
./scc0 -c lib/fputs.c
./scc0 -c lib/fread.c
./scc0 -c lib/free.c
./scc0 -c lib/freopen.c
./scc0 -c lib/fscanf.c
./scc0 -c lib/fseek.c
./scc0 -c lib/fsetpos.c
./scc0 -c lib/ftell.c
./scc0 -c lib/fwrite.c
./scc0 -c lib/getchar.c
./scc0 -c lib/getenv.c
./scc0 -c lib/kprintf.c
./scc0 -c lib/malloc.c
./scc0 -c lib/memchr.c
./scc0 -c lib/memcmp.c
./scc0 -c lib/memcpy.c
./scc0 -c lib/memmove.c
./scc0 -c lib/memset.c
./scc0 -c lib/perror.c
./scc0 -c lib/printf.c
./scc0 -c lib/putchar.c
./scc0 -c lib/puts.c
./scc0 -c lib/qsort.c
./scc0 -c lib/rand.c
./scc0 -c lib/realloc.c
./scc0 -c lib/remove.c
./scc0 -c lib/rename.c
./scc0 -c lib/rewind.c
./scc0 -c lib/scanf.c
./scc0 -c lib/setbuf.c
./scc0 -c lib/setvbuf.c
./scc0 -c lib/sprintf.c
./scc0 -c lib/sscanf.c
./scc0 -c lib/strcat.c
./scc0 -c lib/strchr.c
./scc0 -c lib/strcmp.c
./scc0 -c lib/strcpy.c
./scc0 -c lib/strcspn.c
./scc0 -c lib/strdup.c
./scc0 -c lib/strerror.c
./scc0 -c lib/strlen.c
./scc0 -c lib/strncat.c
./scc0 -c lib/strncmp.c
./scc0 -c lib/strncpy.c
./scc0 -c lib/strpbrk.c
./scc0 -c lib/strrchr.c
./scc0 -c lib/strspn.c
./scc0 -c lib/strtok.c
./scc0 -c lib/strtol.c
./scc0 -c lib/system.c
./scc0 -c lib/time.c
./scc0 -c lib/tmpfile.c
./scc0 -c lib/tmpnam.c
./scc0 -c lib/ungetc.c
./scc0 -c lib/varargs.c
./scc0 -c lib/vformat.c
./scc0 -c lib/vfprintf.c
./scc0 -c lib/vprintf.c
./scc0 -c lib/vscan.c
./scc0 -c lib/vsprintf.c
ar -rc lib/libscc.a lib/init.o lib/abort.o lib/abs.o lib/atexit.o lib/atoi.o lib/bsearch.o lib/calloc.o lib/clearerr.o lib/ctime.o lib/ctype.o lib/difftime.o lib/exit.o lib/fclose.o lib/fdopen.o lib/feof.o lib/ferror.o lib/fflush.o lib/fgetc.o lib/fgetpos.o lib/fgets.o lib/fileno.o lib/fopen.o lib/fprintf.o lib/fputc.o lib/fputs.o lib/fread.o lib/free.o lib/freopen.o lib/fscanf.o lib/fseek.o lib/fsetpos.o lib/ftell.o lib/fwrite.o lib/getchar.o lib/getenv.o lib/kprintf.o lib/malloc.o lib/memchr.o lib/memcmp.o lib/memcpy.o lib/memmove.o lib/memset.o lib/perror.o lib/printf.o lib/putchar.o lib/puts.o lib/qsort.o lib/rand.o lib/realloc.o lib/remove.o lib/rename.o lib/rewind.o lib/scanf.o lib/setbuf.o lib/setvbuf.o lib/sprintf.o lib/sscanf.o lib/strcat.o lib/strchr.o lib/strcmp.o lib/strcpy.o lib/strcspn.o lib/strdup.o lib/strerror.o lib/strlen.o lib/strncat.o lib/strncmp.o lib/strncpy.o lib/strpbrk.o lib/strrchr.o lib/strspn.o lib/strtok.o lib/strtol.o lib/system.o lib/time.o lib/tmpfile.o lib/tmpnam.o lib/ungetc.o lib/varargs.o lib/vformat.o lib/vfprintf.o lib/vprintf.o lib/vscan.o lib/vsprintf.o
ranlib lib/libscc.a
~/Downloads/SubC/src $ ./scc0 -o scc1 *.c
~/Downloads/SubC/src $ ./scc1 -o scc *.c
/bin/sh: syntax error: unexpected "("
scc: assembler invocation failed
I'm not entirely sure where to go from here :/ Was hoping maybe I could patch this myself
I have tried both just running the build/configure scripts, and I tried running the compiler directly like in the documentation (including telling it what standard to use). I've done gcc (shown), TinyCC, and clang.
When I compiled myself and defined the standard
c90orc89withgccspecifically, it did produce an executable, but one that segfaulted if actually run on anything.Moved onto looking at the make settings and changing things to see how far I could get that way, and that significantly helped.
I tried just adding a simpe implementation of
strdupinto main beforenewfilenameis called, re-ran the Makefile, and got what seemed like a pretty reasonable output. Decided to verify by trying to run scc0 on itself, and it failed but did not segfault; the self-created binary just did not want to actually work.I'm not entirely sure where to go from here :/ Was hoping maybe I could patch this myself