You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I can tell, there's no build-in way to generate an entrypoint (_start) when generating an object file using cranelift-object. Please correct me if I'm mistaken, but I think this makes it impossible to actually produce a properly executable file using only cranelift and a linker.
Two solutions came to my mind:
A function like define_entrypoint, which let's us define an entrypoint directly (_start). One could define a custom entrypoint similar to how one defines a function now.
cranelift-object defines a default entrypoint, calling a main-function (similar to what C does)
Being able to actually generate runnable executables with cranelift-object.
Implementation
I'm definitely not qualified to fill this section in :P
Alternatives
Some alternative approaches come to mind:
Compile the object file to a dynamic library and link it with a "boot"-program written in C/Rust, which calls a custom entrypoint in our "library". Requires an extra toolchain to be installed.
Do what saltwater does and link it using cc, which apperantely insert a valid entrypoint calling main. This is also the only project I came across which uses cranelift-object. Requires an extra toolchain to be installed.
Using cranelift-faerie, which is deprecated. Not sure if it has the same problem, through.
cranelift-object only produces object files. You need to link them yourself to get an executable or dynamic library. If you link you will either have to provide the right crt.o to define the _start function or you have gcc/clang provide it for you. cranelift-object can't know what the right contents are. On some systems it calls __libc_start_main, on others it calls the constrictors and directly jumps to main and on yet other systems it does low level hardware initialization and sets up a stack before calling main.
I did just recommend defining main and then using gcc or clang to link the executable. This is what rustc_codegen_cranelift does too.
Feature
As far as I can tell, there's no build-in way to generate an entrypoint (
_start
) when generating an object file usingcranelift-object
. Please correct me if I'm mistaken, but I think this makes it impossible to actually produce a properly executable file using only cranelift and a linker.Two solutions came to my mind:
define_entrypoint
, which let's us define an entrypoint directly (_start
). One could define a custom entrypoint similar to how one defines a function now.cranelift-object
defines a default entrypoint, calling amain
-function (similar to what C does)Note: I tried defining
_start
as a function which obviously didn't work out.Benefit
Being able to actually generate runnable executables with
cranelift-object
.Implementation
I'm definitely not qualified to fill this section in :P
Alternatives
Some alternative approaches come to mind:
cc
, which apperantely insert a valid entrypoint callingmain
. This is also the only project I came across which usescranelift-object
. Requires an extra toolchain to be installed.cranelift-faerie
, which is deprecated. Not sure if it has the same problem, through.rustc-codegen-cranelift
does itThe text was updated successfully, but these errors were encountered: