Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support combined rust and c application #3

Open
tlambertz opened this issue Jun 25, 2020 · 4 comments
Open

Support combined rust and c application #3

tlambertz opened this issue Jun 25, 2020 · 4 comments
Assignees

Comments

@tlambertz
Copy link

I want to trace a C application running on hermitcore with my tracer written in rust (rftrace). I'd ideally want to:

  • compile the kernel into a static library libhermit.a
  • compile the rust library into a static library librftrace_frontend_ffi.a
  • compile the C application, linking to these two (gcc main.c -lhermit -lrftrace_frontend_ffi -o main)

I got it working, but this currently requires a number of workarounds:

  • duplicate runtime_entry:
    • the rust-library needs std. std defines runtime_entry, so does newlib which the c app requires.
    • workaround: remove runtime_entry symbol from the library. As far as I can see this will only affect environment variables, which I dont need and some destructors, which are not strictly needed since the OS will shut down on exit. (objcopy --strip-symbol runtime_entry librftrace_frontend_ffi.a)
  • OOM exceptions
    • currently, only 4MB of heap space is allocated for the "kernel" if we enable the newlib feature. This is not actual kernel heap, but all of rust heap. (sidenote: this might also be an issue even if not linking rust+c together, depending on how the virtio virtqueues are utilized)
    • workaround: patch kernel to increase the size. (let size = 100 * LargePageSize::SIZE; in /src/mm/mod.rs::init())
  • errors about non-defined functions like sys_tcp_stream_connect
    • the rust stdlib includes hermit-abi, which contains all "systemcalls". Since the networking changes, there are now a bunch of functions which are not defined in the kernel, but in hermit-sys.
    • workaround: define empty stub-functions in the c source.
    • it might be possible to compile hermit-sys as a static library and link against it instead of libhermit.a? I have not investigated this further
@stlankes
Copy link
Collaborator

stlankes commented Jul 4, 2020

@tlambertz I oversaw this issue. I merged the latest version of libhermit to this project. However, some test cases didn't run. I will solve it.

@stlankes
Copy link
Collaborator

stlankes commented Jul 5, 2020

Now, the latest version of lib hermit-rs is able to run C applications. Now, I will look in your problems.

I am not sure if I understand your issue. Do you want to use Rust`s libstd in combination newlib?

@tlambertz
Copy link
Author

Do you want to use Rust`s libstd in combination newlib?

Yes, this is essentially what I want. libstd in a library, linked to a newlib C application.

@stlankes
Copy link
Collaborator

stlankes commented Jul 10, 2020

Hm, difficult... Currently, Rust's libstd uses another memory layout in comparison to newlib. This is the reason, why we forward the feature flag newlib during the build process of libhermit, if we use it in combination of newlib.

@mkroening mkroening self-assigned this Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants