Skip to content

minimal-compiler

This branch, starting on `releases/gcc-4.6.4` provides, in order:

1. A set of patches (4 patches) that make gcc compilable with more
   recent toolchains. These patches need to be separated and used from the
   guix packaging because they are not part of the project itself. That's
   easy, `git format-patch` them and then use them from `guix.scm` when we
   have a distribution mechanism.

2. A really minimal and precarious Guix package (`guix.scm`) that lets
   us build a minimal compiler (2 commits). This allows us to run `guix
   build -f guix.scm` (even with a time-machine if needed) to compile the
   project without thinking too much about it. It has issues though: it
   doesn't find `glibc` properly and it doesn't interact with `binutils`.
   That is not a problem of our work, but a packaging problem.

3. A commit that includes all the changes from the upstream RISC-V port.
   It's a breaking change, it is backported in the next commits.

4. Next commit fixes MD files, unrolling unsupported loops and replacing
   unsupported constructs like `simple-return` in the machine
   description files.

5. Next makes most of the C code compatible with the old C based API. It
   makes some sacrifices though:
   - It eliminates all the builtins support. This is not very important,
     yet. We leave it for the next milestone.
   - It doesn't check the MEMMODEL, as it was not available in this GCC
     version. We need to take a look to how to solve this one.

6. Last commit of the series handles input arguments (-march and that
   kind of things) using the old API.

With all these changes is now possible to generate a minimal compiler:

```
$ guix build -f guix.scm
...
/gnu/store/gsq72r3xnv7b2f1l4z5idpy3j900hizk-gcc-4.6.4-HEAD-debug
/gnu/store/qglp0cx0nq2nblcg9ya4gmc5gfk2amjg-gcc-4.6.4-HEAD-lib
/gnu/store/l612a4h9a6l4hs7kq49rph4clwf6l2k5-gcc-4.6.4-HEAD

$ tree /gnu/store/l612a4h9a6l4hs7kq49rph4clwf6l2k5-gcc-4.6.4-HEAD
/gnu/store/l612a4h9a6l4hs7kq49rph4clwf6l2k5-gcc-4.6.4-HEAD
├── bin
│   ├── riscv64-unknown-linux-gnu-cpp
│   ├── riscv64-unknown-linux-gnu-gcc
│   ├── riscv64-unknown-linux-gnu-gcc-4.6.4
│   └── riscv64-unknown-linux-gnu-gcov
├── etc
│   └── ld.so.cache
├── libexec
│   └── gcc
│       └── riscv64-unknown-linux-gnu
│           └── 4.6.4
│               ├── cc1
│               ├── collect2
│               ├── install-tools
│               │   ├── fixincl
│               │   ├── fixinc.sh
│               │   ├── mkheaders
│               │   └── mkinstalldirs
│               └── lto-wrapper
├── riscv64-unknown-linux-gnu
│   └── lib
└── share
    ├── doc
    │   └── gcc-4.6.4-HEAD
    │       ├── COPYING
    │       ├── COPYING3
    │       ├── COPYING3.LIB
    │       ├── COPYING.LIB
    │       └── COPYING.RUNTIME
    ├── info
    │   ├── cpp.info.gz
    │   ├── cppinternals.info.gz
    │   ├── gcc.info.gz
    │   ├── gccinstall.info.gz
    │   └── gccint.info.gz
    └── man
        ├── man1
        │   ├── riscv64-unknown-linux-gnu-cpp.1.gz
        │   ├── riscv64-unknown-linux-gnu-gcc.1.gz
        │   └── riscv64-unknown-linux-gnu-gcov.1.gz
        └── man7
            ├── fsf-funding.7.gz
            ├── gfdl.7.gz
            └── gpl.7.gz

16 directories, 28 files

$ cat <<END > hello.c
int main (int argc, char * argv[]){
    return 19;
}
END

$ /gnu/store/.../riscv64-unknown-linux-gnu-gcc -S hello.c
$ cat hello.s
.file	"hello.c"
	.option nopic
	.text
	.align	1
	.globl	main
	.type	main, @function
main:
	add	sp,sp,-32
	sd	s0,24(sp)
	add	s0,sp,32
	mv	a5,a0
	sd	a1,-32(s0)
	sw	a5,-20(s0)
	li	a5,19
	mv	a0,a5
	ld	s0,24(sp)
	add	sp,sp,32
	jr	ra
	.size	main, .-main
	.ident	"GCC: (GNU) 4.6.4"
```

This can be later assembled and linked using binutils with not much
trouble.
Assets 2