pczarn / rustboot

A multi-platform kernel written in Rust
http://pczarn.github.io/rustboot/doc/main/index.html
MIT License
197 stars 15 forks source link

Is this actually supposed to work? #2

Closed derekchiang closed 10 years ago

derekchiang commented 10 years ago

Sorry I pressed the comment button too quickly. Details follow:

I was trying to compile this repo according to the instructions given, but got lots of errors.

  1. Some files, for instance arch/x86/cpu/gdt.rs, did not import kernel::memory::Allocator. As a result the alloc method couldn't be called.
  2. The lib attribute does not work anymore. It was replaced by crate_id.
  3. After fixing the previous two errors, which was easy enough, I got this:
/usr/bin/clang -O2 -ffreestanding -target i686-intel-linux -c boot/main.bc -o boot/main.o
clang: error: no such file or directory: 'boot/main.bc'
clang: error: no input files

At the first glance, there is indeed no such file. The file intended to be used seems to be rustboot.bc. So it indicates that there are some errors in the Makefile.

derekchiang commented 10 years ago

So I replaced main with rustboot in the Makefile and the compilation was able to proceed a little bit. Now I'm getting even weirder errors:

make all -C arch/x86/
make[1]: Entering directory `/media/Work_Study/CS/workspace/rust/rustboot/arch/x86'
/usr/bin/clang -O2 -ffreestanding -target i686-intel-linux -c boot/rustboot.bc -o boot/rustboot.o
/usr/bin/ld -melf_i386 -o boot/floppy.elf -T ./boot/linker.ld ./boot/loader.o ./boot/rustboot.o "-(" ./boot/libcore-2e829c2f-0.0.rlib "-)" -Map=././boot/linker.map
./boot/libcore-2e829c2f-0.0.rlib(core.o): In function `core::u64::mul_with_overflow':
/media/Work_Study/CS/workspace/rust/rustboot/arch/x86/../../rust-core/core/u64.rs:29: undefined reference to `__udivdi3'
./boot/libcore-2e829c2f-0.0.rlib(core.o): In function `core::i64::mul_with_overflow':
/media/Work_Study/CS/workspace/rust/rustboot/arch/x86/../../rust-core/core/i64.rs:35: undefined reference to `__mulodi4'
make[1]: *** [boot/floppy.elf] Error 1
make[1]: Leaving directory `/media/Work_Study/CS/workspace/rust/rustboot/arch/x86'
make: *** [all] Error 2

Any clue what's going on?

pczarn commented 10 years ago

This problem is caused by u64.rs and i64.rs, both can be removed in rust-core/core/lib.rs as a workaround. thestinger commented on f47d13b

You need clang with compiler-rt for udivdi3 and mulodi4. If you don't want to build position independent code you can pass -fno_pie.

I'm surprised your changes work, I got this:

$ make
make all -C arch/x86/
make[1]: Entering directory '/home/piotr/Desktop/rustboot/arch/x86'
make[1]: *** No rule to make target 'boot/rustboot.o', needed by 'boot/floppy.elf'.  Stop.
make[1]: Leaving directory '/home/piotr/Desktop/rustboot/arch/x86'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2
pczarn commented 10 years ago

Just an idea, main.rs (perhaps you changed it to rustboot.rs) can be moved to kernel/lib.rs or arch/.../lib.rs.

pczarn commented 10 years ago

FAQ

Is this actually supposed to work?

Yes.

Is it any good?

Yes.

derekchiang commented 10 years ago

Indeed, I made some mistakes. Now the Makefile should work.

When I pass -fno_pie to ld, I get this error:

/usr/bin/ld -melf_i386 -fno_pie -o boot/floppy.elf -T ./boot/linker.ld ./boot/loader.o ./boot/main.o "-(" ./boot/libcore-2e829c2f-0.0.rlib "-)" -Map=././boot/linker.map
/usr/bin/ld: -f may not be used without -shared
make[1]: *** [boot/floppy.elf] Error 1

Do you know why?

derekchiang commented 10 years ago

Oh I misread the message. Thought it said with rather than without.

So I added -shared (without knowing what the consequences are) and it compiled. When I do make run though, all I see is a black screen flashing with the message:

Booting from Hard Disk...
Boot failed: could not read the boot disk

Booting from Floppy...
pczarn commented 10 years ago

compiler-rt

First, link compiler-rt runtime library that manipulates integers larger than 32 bits. I'm using x86_64 Arch Linux and clang package contains /usr/lib/clang/3.4/lib/linux/libclang_rt.full-x86_64.a. Unfortunately, it's incompatible with i386. Two options remain.

Then append path to libclang_rt.full-i386.a to LINK in Makefile.

no position independent code

I don't think it matters. Maybe add -fno-pie to CFLAGS. The code is first generated by clang, not ld!