Compiling xv6 with Clang

Hi.
I tried to compile xv6 (a 10000 line teaching operating system from MIT) with Clang instead of GCC, but it led to an error. The compiled bootblock was larger than 1 sector (i.e., 512 bytes). Should I change the compiler options? How?

Thanks!

Hard to say without more info - it’s possible that Clang doesn’t produce as compact code as GCC in some cases. You can try compiling with optimization modes that prioritize code size: -Os and -Oz (one of them is more agrgessive, I forget which)

Hi David,
The problem is still there. The sequence of commands to build the bootblock (for gcc) is as follows:

gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -O -nostdinc -I. -c bootmain.c
gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -nostdinc -I. -c bootasm.S
ld -m elf_i386 -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o
objdump -S bootblock.o > bootblock.asm
objcopy -S -O binary -j .text bootblock.o bootblock
./sign.pl bootblock

There are two files (one assembly file and one C file that are linked to generate the boot block). Any help is appreciated.
Regards.

As in the code is still too large even using -Os or -Oz? (using them together would just have one override the other, consulting the manual, it seems -Oz is the more aggressive size-reduction mode ( https://clang.llvm.org/docs/CommandGuide/clang.html#code-generation-options )).

If that still doesn’t produce sufficiently small code, I’m not sure what else to try - sorry. Perhaps someone else on the mailing list does.

Hi Ahmad,

Hi David,
The problem is still there. The sequence of commands to build the bootblock (for gcc) is as follows:
gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -O -nostdinc -I. -c bootmain.c

You seem to have a -O towards the end of the command line, which would
override the earlier -O2 . Is this intentional?

You have two object files (bootmain.o and bootasm.o). Compare the
sizes generated by gcc and clang for both object files.

You could use -save-temps when compiling the .c file to look at the
generated assembly and try to spot differences between clang and GCC.

Csaba