Compiling xv6 with Clang

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Compiling xv6 with Clang

David Blaikie via cfe-dev
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!

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compiling xv6 with Clang

David Blaikie via cfe-dev
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)

On Sun, Nov 4, 2018 at 3:30 AM Ahmad Nouralizadeh Khorrami via cfe-dev <[hidden email]> wrote:
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!
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compiling xv6 with Clang

David Blaikie via cfe-dev
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.

On Sun, 4 Nov 2018 at 19:28, David Blaikie <[hidden email]> wrote:
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)

On Sun, Nov 4, 2018 at 3:30 AM Ahmad Nouralizadeh Khorrami via cfe-dev <[hidden email]> wrote:
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!
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compiling xv6 with Clang

David Blaikie via cfe-dev
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.

On Thu, Nov 8, 2018 at 3:08 PM Ahmad Nouralizadeh Khorrami <[hidden email]> wrote:
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.

On Sun, 4 Nov 2018 at 19:28, David Blaikie <[hidden email]> wrote:
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)

On Sun, Nov 4, 2018 at 3:30 AM Ahmad Nouralizadeh Khorrami via cfe-dev <[hidden email]> wrote:
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!
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Compiling xv6 with Clang

David Blaikie via cfe-dev
In reply to this post by David Blaikie via cfe-dev
Hi Ahmad,


On Fri, Nov 9, 2018 at 12:08 AM Ahmad Nouralizadeh Khorrami via
cfe-dev <[hidden email]> wrote:
>
> 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
--
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformat way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev