C compilers
Getting GCC built is very important for the GNU project. It's written in C++ now but it can be built using earlier versions of GCC that are written in C. (e.g. 4.7)
Questions[edit]
Can pcc build tcc (mob) [yes][edit]
yes. http://repo.or.cz/tinycc.git
Can pcc build gcc 4.7? [no][edit]
No:
../.././libdecnumber/bid/decimal128.c, line 73: compiler error: classifystruct error: /home/debbie/pcc-boot/libexec/ccom terminated with status 1
Line 73 of ./libdecnumber/bid/decimal128.c:
/* __dpd128FromNumber returns in big endian. But _dpd_to_bid128 takes host endian. */ __ieee_to_host_128 (*d128, &u._Dec);
It would be good to figure out and why and make it work!
Can pcc build gcc 7.1.0 [unclear][edit]
Unclear. Since pcc also has a c++ compiler there is a chance.
CC=pcc CPP=pcpp CXX=p++ CC_FOR_TARGET=pcc CPP_FOR_TARGET=pcpp CXX_FOR_TARGET=p++ ./configure --enable-languages=c,c++ --prefix=$HOME/gcc-out
but I got the error:
checking for uintmax_t... no checking for uintptr_t... no configure: error: uint64_t or int64_t not found Makefile:4277: recipe for target 'configure-stage1-gcc' failed make[2]: *** [configure-stage1-gcc] Error 1
Can pcc build gcc 3.2 [no][edit]
No.
pcc -c -DIN_GCC -g -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wtraditional -pedantic -Wno-long-long -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -I. -I/home/debbie/gcc-3.2/gcc -I/home/debbie/gcc-3.2/gcc/. -I/home/debbie/gcc-3.2/gcc/config -I/home/debbie/gcc-3.2/gcc/../include /home/debbie/gcc-3.2/gcc/read-rtl.c -o read-rtl.o /home/debbie/gcc-3.2/gcc/read-rtl.c, line 662: lvalue required /home/debbie/gcc-3.2/gcc/read-rtl.c, line 662: cannot recover from earlier errors: goodbye! error: /home/debbie/pcc-boot/libexec/ccom terminated with status 1 Makefile:2177: recipe for target 'read-rtl.o' failed make[1]: *** [read-rtl.o] Error 1
Can tcc build gcc 4.7.4? [yes][edit]
Yes! Huge thanks to the tinycc mob: http://lists.nongnu.org/archive/html/tinycc-devel/2017-05/msg00099.html
$ sha256sum gcc-4.7.4.tar.gz ddbaa583c5d4e4f0928bf15d9f6b6c283349e16eedc47bde71e1b813f6f37819 gcc-4.7.4.tar.gz tinycc (mob) commit 53c5fc2246270e0242903de0152a9a5d40f3d679
http://repo.or.cz/tinycc.git/commit/53c5fc2246270e0242903de0152a9a5d40f3d679
MAKEINFO=missing CC=tcc $HOME/gcc-4.7.4/configure --prefix=$HOME/gcc-out --enable-languages=c --disable-multilib
it requires a lot of space, multiple gigabytes to build.
Build done on Debian 9.6, using gcc-4.7.4, gmp-4.2,4, mpc-0.8.1, mpfr-2.3.1. For gmp, mpc and mpfr, you have to extract them, rename to gmp, mpc and mpfr (i.e., remove the version number) and move inside the gcc-4.7.4 directory. The GCC build system will automatically find them. Trying the same operation on up-to-date Debian unstable (as of 2019-01-09) failed; maybe something has changed in the libc in an incompatible way.
Can tcc build pcc [almost!][edit]
No.
First of all CPP=tcc ./configure gives an error: preprocessor fails sanity check. If we just use the line
CC=tcc ./configure --prefix=$HOME/pcc-tcc-out/
it compiles some of the way then fails with:
tcc -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wsign-compare -Wtruncate -D_BSD_SOURCE -DGCC_COMPAT -DPCC_DEBUG -DNATIVE_FLOATING_POINT -D_ISOC99_SOURCE -Dos_linux -Dmach_amd64 -I. -I. -I../.. -I../../mip -I../../arch/amd64 -I../../os/linux -I../../common -c -o local2.o ../../arch/amd64/local2.c ../../arch/amd64/local2.c:44: error: unknown type size Makefile:148: recipe for target 'local2.o' failed make[2]: *** [local2.o] Error 1
UPDATE: We can actually make it build by hacking around this one issue!
Index: arch/amd64/local2.c =================================================================== RCS file: /cvsroot/pcc/arch/amd64/local2.c,v retrieving revision 1.67 diff -r1.67 local2.c 44c44,46 < char *rbyte[], *rshort[], *rlong[]; --- > char rbyte[44][44]; > char rshort[44][44]; > char rlong[44][44]; 145,148d146 < /* < * We here know what register to save and how much to < * add to the stack. < */ 711c709 < rc = rbyte; --- > rc = (char**)rbyte; 715c713 < rc = rshort; --- > rc = (char**)rshort; 719c717 < rc = rlong; --- > rc = (char**)rlong; 929c927 < char *rbyte[] = { --- > char rbyte[44][44] = { 931c929 < "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b", --- > "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" 933c931 < char *rshort[] = { --- > char rshort[44][44] = { 935c933 < "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w", --- > "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" 937c935 < char *rlong[] = { --- > char rlong[44][44] = { 939c937 < "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d", --- > "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" 1245d1242 <
Unfortunately it isn't quite able to build pcc-libs (which is a required part of pcc)
tcc -O -I. -DTARGET_LITTLE_ENDIAN=1 -Dos_linux -Dmach_amd64 -isystem ../libpcc/include -c fixunssfdi.c fixunssfdi.c:85: error: '__INT_MAX__' undeclared Makefile:52: recipe for target 'fixunssfdi.o' failed
Can nwcc build gcc 4.7? [no?][edit]
It claims to be able to on the website: http://nwcc.sourceforge.net/apps.html
but I wasn't able to:
$ CC=$HOME/nwcc-out/bin/nwcc LDFLAGS=-fpic ./configure --enable-languages=c,c++ --disable-multilib --prefix=$HOME/gcc-out $ make ... ... ... ../.././lto-plugin/lto-plugin.c:748: Warning: Assignment from incompatible pointer type (illegal in ISO C, and very probably not what you want) htab_t symtab = htab_create (t->nsyms, hash_sym, eq_sym, ((void *)0)); ^^^^^^^^^^^ here /var/tmp/cpp0.cpp - 0 error(s), 1 warning(s) /bin/bash ./libtool --tag=CC --tag=disable-static --mode=link /home/debbie/nwcc-out/bin/nwcc -Wall -g -module -bindir /home/debbie/gcc-out/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0 -fpic -o liblto_plugin.la -rpath /home/debbie/gcc-out/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0 lto-plugin.lo -Wc,../libiberty/pic/libiberty.a libtool: link: /home/debbie/nwcc-out/bin/nwcc -shared .libs/lto-plugin.o -lc ../libiberty/pic/libiberty.a -soname liblto_plugin.so.0 -o .libs/liblto_plugin.so.0.0.0 ld: .libs/lto-plugin.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC .libs/lto-plugin.o: error adding symbols: Bad value Makefile:339: recipe for target 'liblto_plugin.la' failed
Can nwcc build pcc? [no][edit]
configure: error: in `/home/debbie/pcc': configure: error: C preprocessor "/home/debbie/nwcc_0.8.3/out/bin/nwcpp" fails sanity check See `config.log' for more details configure:3780: checking whether we are using the GNU C compiler configure:3799: /home/debbie/nwcc_0.8.3/out/bin/nwcc -c conftest.c >&5 conftest.c:20: Error: Parse error at `me'(#2) ^^ here /var/tmp/cpp0.cpp - 1 error(s), 0 warning(s) configure:3799: $? = 1 configure: failed program was: | /* end confdefs.h. */ | | int | main () | { | #ifndef __GNUC__ | choke me | #endif | | ; | return 0; | }
tried again today and got a completely different error:
debbie@debian:~/pcc$ /home/debbie/nwcc-boot/bin/nwcc mkext.lo common.lo table.lo -o mkext No valid files to link.
Can nwcc build tcc? [yes][edit]
Hooray!
Can ucc build pcc? [no][edit]
ucc makes it through ./configure, unlike most. but fails quickly:
make[2]: Entering directory '/home/debbie/pcc/cc/cc' /home/debbie/ucc-c-compiler/ucc -g -Wall -Wmissing-prototypes -Wshadow -Wsign-compare -DLIBEXECDIR=\"/usr/local/libexec/\" -D_BSD_SOURCE -DGCC_COMPAT -DPCC_DEBUG -DNATIVE_FLOATING_POINT -DINCLUDEDIR=\"/usr/local/include/\" -DPCCINCDIR=\"/usr/local/lib/pcc/x86_64-unknown-linux-gnu/1.2.0.DEVEL/include/\" -DPCCLIBDIR=\"/usr/local/lib/pcc/x86_64-unknown-linux-gnu/1.2.0.DEVEL/lib/\" -Dos_linux -Dmach_amd64 -DTARGOSVER=0 -DCXXPROGNAME=\"p++\" -DCPPROGNAME=\"pcpp\" -I../../cc/driver -I../.. -I../../os/linux -I../../mip -I../../arch/amd64 -I../../common -c -o cc.o ./cc.c ./cc.c:1596:1: error: unterminated function-macro 'assert' "assert(sizeof(lists) / sizeof(lists[0]) ==" ^ /home/debbie/ucc-c-compiler/ucc: cpp2/cpp returned 1
could it be fixed?
step 1: edit cc/cc/cc.c so the macro is only a single line long.
Now we get this error:
/usr/lib/gcc/x86_64-linux-gnu/4.9.2/include/stddef.h:212:23: warning: unused variable 'size_t' "typedef unsigned long size_t;" ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/4.9.2/include/stddef.h:147:23: warning: unused variable 'ptrdiff_t' "typedef unsigned long ptrdiff_t;" ^~~~~~~~~ /usr/lib/gcc/x86_64-linux-gnu/4.9.2/include/stddef.h:324:13: warning: unused variable 'wchar_t' "typedef int wchar_t;" ^~~~~~~
Trouble[edit]
neatcc[edit]
neatcc requires neatlibc (for stdarg.h and other things). neatlibc requires fasm which I didn't have, was not able to build it with nasm or yasm.
recc[edit]
Unable to make the kernel:
#include "../generated/struct_type_description_memory_pool.h"
ucc[edit]
ucc does not seem to be able to self-compile.
SmallerC[edit]
Unable to compile a small test program with it:
$ smlrcc -SI/home/debbie/SmallerC/v0100/include/ t.c -o t Symbol '__start' not found Failed command 'smlrl -elf t.o -o t'
Author here: it can't find the library (lcl.a for Linux, lcm.a for MacOS). The documentation for smlrcc explains where searching for headers and libraries happens. Apparently, neither headers no libraries are there (normally you shouldn't need to use -SI and if you do, either you're doing something special or something's wrong). The easiest fix for Linux and MacOS is to simply do the usual make, sudo make install. Or you could also supply smlrcc with the full library name (that is, including the path).
Thank you very much I was able to compile hello world by passing in lcl.a !
pcc[edit]
Tried pcc again recently, Was able to build pcc and install to a local prefix with gcc but not self host. crt.o stuff. installing globally would probably fix it but it would be good to write full instructions for building and bootstrapping pcc.
lacc[edit]
TODO: try it. seems not to implement the posix cli.
Other[edit]
- Which C compilers can build which (other) C compilers?
- ACK http://tack.sourceforge.net/
- Recc http://recc.robertelder.org/
- Cint (interpreter)?
- clang
- SmallerC
- https://github.com/larmel/lacc (segfault attempting to compile tinycc)