Rust 'dylib' for custom target

Hello, this is my first post on the rust forum. I normally don't make posts on forums but since there is (almost) nothing of examples for what i want to do and have no idea how to start.

So the goal is to load a dylib at runtime in my custom kernel. The dylib is meant as a module for my kernel.
That means that the finshed product can load an dylib execute a predefined function and access kernel functions and also other modules.

The problem is when i want to compile my module to the target (x86_64 baremetal) it says it doesn't support dylib as crate target.

If i am correct this is because i never defined how a dynamic library should work in my own kernel?
If so how do i fix this? Where do i start?

Just to be sure, am i in the correct category?

EDIT:
The crates with their dependencies:

  • kernel (bin)

    • kernel-core
  • example-module-1 (dylib)

    • kernel-core
  • example-module-2 (dylib)

    • kernel-core
    • example-module-1
  • kernel-core (lib)

The ideal solution would be that kernel-core is staticly linked in the kernel and modules acces it from there.

EDIT2: adding crate type to edit 1

Exactly, it depends on what binary format your kernel uses. There cannot be a general "dylib for bare metal".

As an example you could look at how they make Linux kernel modules in rust: https://github.com/fishinabarrel/linux-kernel-module-rust

The example you gave makes use of the crate type staticlib, i can't use this since it static links all the dependencies such as other modules. (core and alloc are already linked in the kernel itself so i would also like to avoid adding those to each module)

If you use bin as crate type for the kernel, no function are exported from it.

I have a 'core' crate that can be used by the modules and the kernel. I am going to edit my topic and put my crate structure there.

What is the crate-type of kernel? Does it have main.rs (bin) or lib.rs (lib)?

Oops should've put it in the edit... It is bin

Then the kernel binary won't export any symbols other than the start function. This means that any symbols in kernel-core won't be available for the kernel modules.

Oh you are right, but if i load the modules myself in i can map the kernel-core to the dylib modules no?

kernel-core is linked into the kernel, so no. That would only be possible if kernel-core were to be a dylib, but then kernel would need to be linked itself, requiring you to write your own bootloader or a stub that links the rest of the kernel.

Full re-edit, i looked somewhat more things up about dynamic link etc. I can make my own dynamic linker in my kernel that loads ELF files, i just need my rust compiled as an dylib so that i can feed it into my own dynamic linker.