iankronquist / rustyvisor

A hypervisor written in Rust.
MIT License
115 stars 9 forks source link

Link with librustyvisor.a #46

Closed tathanhdinh closed 3 years ago

tathanhdinh commented 5 years ago

Hello,

I've managed to build rustyvisor after some minor changes but it seems the module rustyvisor.ko does not link with librustyvisor.a.

I've got the following report:

RUST_TARGET_PATH=/public/Github/rustyvisor RUSTFLAGS='-C relocation-model=static --deny warnings' xargo build --target=x86_64-linux --verbose --features ""runtime_tests""
+ "rustc" "--print" "sysroot"
+ "rustc" "--print" "target-list"
+ RUSTFLAGS="-C relocation-model=static --deny warnings --sysroot /home/tathanhdinh/.xargo"
+ "cargo" "build" "--target=x86_64-linux" "--verbose" "--features" "runtime_tests"
       Fresh cfg-if v0.1.9
       Fresh spin v0.4.10
       Fresh log v0.4.6
   Compiling rustyvisor v0.1.0 (/public/Github/rustyvisor)
       Fresh log v0.3.9
     Running `/public/Github/rustyvisor/target/debug/build/rustyvisor-3396327d20ebec25/build-script-build`
     Running `rustc --crate-name rustyvisor src/lib.rs --color always --crate-type staticlib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="runtime_tests"' -C metadata=60ed51c75f0b01e7 -C extra-filename=-60ed51c75f0b01e7 --out-dir /public/Github/rustyvisor/target/x86_64-linux/debug/deps --target x86_64-linux -C incremental=/public/Github/rustyvisor/target/x86_64-linux/debug/incremental -L dependency=/public/Github/rustyvisor/target/x86_64-linux/debug/deps -L dependency=/public/Github/rustyvisor/target/debug/deps --extern log=/public/Github/rustyvisor/target/x86_64-linux/debug/deps/liblog-70345355243127a8.rlib --extern spin=/public/Github/rustyvisor/target/x86_64-linux/debug/deps/libspin-bc726ec8ef613206.rlib -C relocation-model=static --deny warnings --sysroot /home/tathanhdinh/.xargo`
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
make -C /lib/modules/5.1.11-200.fc29.x86_64/build SUBDIRS=/public/Github/rustyvisor modules
make[1] : on entre dans le répertoire « /usr/src/kernels/5.1.11-200.fc29.x86_64 »
Makefile:205: ================= WARNING ================
Makefile:206: 'SUBDIRS' will be removed after Linux 5.3
Makefile:207: Please use 'M=' or 'KBUILD_EXTMOD' instead
Makefile:208: ==========================================
  CC [M]  /public/Github/rustyvisor/loader/linux.o
  LD [M]  /public/Github/rustyvisor/rustyvisor.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: /public/Github/rustyvisor/rustyvisor.o(.init.text+0xbb): Section mismatch in reference from the function init_module() to the function .exit.text:rustyvisor_exit()
The function __init init_module() references
a function __exit rustyvisor_exit().
This is often seen when error handling in the init function
uses functionality in the exit path.
The fix is often to remove the __exit annotation of
rustyvisor_exit() so it may be used outside an exit section.

WARNING: "rustyvisor_core_unload" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
WARNING: "rustyvisor_load" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
WARNING: "rustyvisor_core_load" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
WARNING: "rustyvisor_unload" [/public/Github/rustyvisor/rustyvisor.ko] undefined!
  CC      /public/Github/rustyvisor/rustyvisor.mod.o
  LD [M]  /public/Github/rustyvisor/rustyvisor.ko
make[1] : on quitte le répertoire « /usr/src/kernels/5.1.11-200.fc29.x86_64 »

Analyzing the rustyvisor.ko by an disassembler also confirm that these functions are not linked.

Many thanks for any help.

tathanhdinh commented 5 years ago

That's weird! On Ubuntu (even the lastest LTS 18.04), it links but on Fedora (both 29/30), it doesn't.

iankronquist commented 5 years ago

So I see two things going on here. First is the init calling exit issue, which is totally fixable. But then there's the undefined symbols issue. I don't have a copy of Fedora lying around, can you run nm on rustyvisor.ko, rustyvisor.o and loader/linux.o target/$(TARGET)/$(RELEASE)/librustyvisor.a and post the results on here? It might be some sort of symbol visibility issue on different rust versions?

iankronquist commented 3 years ago

Closing because I'm rewriting the project.