Skip to content

Support combined rust and c application #3

@tlambertz

Description

@tlambertz

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions