unikraft / static-pie-apps

Built Linux applications (static-pie) for Unikraft binary compatibility mode
7 stars 40 forks source link

Add Rust application #8

Closed mkroening closed 2 years ago

mkroening commented 2 years ago

Closes https://github.com/unikraft/static-pie-apps/pull/3.

This adds a Rust "Hello World" application compiled for both musl and GNU.

mkroening commented 2 years ago

@razvand, the suggestion in https://github.com/unikraft/static-pie-apps/pull/3#issuecomment-1172441922 is absolutely correct.

If you have rustup installed, rustup target add x86_64-unknown-linux-musl should do the trick.

Would you still want me to write a README?

mkroening commented 2 years ago

I also did not test if this throws the same error as I found in https://github.com/unikraft/static-pie-apps/pull/3#pullrequestreview-1019417203, since I don't have Unikraft set up right now. It would be awesome, if you could test the included binary, @razvand. :)

razvand commented 2 years ago

Hi, @mkroening , thanks for submitting this.

I am able to run the provided ELFs. They're OK:

unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ ldd ./helloworld-gnu 
  statically linked
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ ldd ./helloworld-musl 
  statically linked
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ checksec --file=./helloworld-musl
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      Symbols         FORTIFY Fortified       Fortifiable  FILE
Full RELRO      No canary found   NX enabled    PIE enabled     No RPATH   No RUNPATH   1159 Symbols     No     0               0       ./helloworld-musl
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ checksec --file=./helloworld-gnu
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      Symbols         FORTIFY Fortified       Fortifiable  FILE
Full RELRO      Canary found      NX enabled    PIE enabled     No RPATH   No RUNPATH   3268 Symbols     No     0               0       ./helloworld-gnu

But I'm not able to properly build them. The gnu build creates a non-PIE ELF. And the musl build still fails:

unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ make clean
rm -f helloworld-musl helloworld-gnu
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ make helloworld-gnu 
rustc -C target-feature=+crt-static --target x86_64-unknown-linux-gnu -o helloworld-gnu helloworld.rs
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ make helloworld-musl
rustc --target x86_64-unknown-linux-musl -o helloworld-musl helloworld.rs
error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-unknown-linux-musl` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-unknown-linux-musl`

error: cannot find macro `println` in this scope
 --> helloworld.rs:2:5
  |
2 |     println!("Hello, world!");
  |     ^^^^^^^

error: requires `sized` lang_item

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0463`.
make: *** [Makefile:11: helloworld-musl] Error 1
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ ls
helloworld-gnu  helloworld.rs  Makefile
unikraft@wasp:~/lyon-binary-compat/apps/static-pie-apps/lang/rust$ checksec --file=./helloworld-gnu
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH      Symbols         FORTIFY Fortified       Fortifiable  FILE
Partial RELRO   Canary found      NX enabled    No PIE          No RPATH   No RUNPATH   3453 Symbols     No     0               0       ./helloworld-gnu

Any ideas why this is happening?

razvand commented 2 years ago

Running the provided static PIE ELFs on Unikraft renders the same error you encountered during the hackathon:

fatal runtime error: assertion failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR

This is indeed an issue on Unikraft; I'll create an issue for it.

razvand commented 2 years ago

@mkroening , could you please also sign-off your commit?

mkroening commented 2 years ago

@mkroening , could you please also sign-off your commit?

Done. :+1: