a-nick-fischer opened issue #5996:
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:
- 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 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:
- 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 callingmain
. This is also the only project I came across which usescranelift-object
. Requires an extra toolchain to be installed.- Using
cranelift-faerie
, which is deprecated. Not sure if it has the same problem, through.- I'm yet to reverse-engineer how
rustc-codegen-cranelift
does it
bjorn3 commented on issue #5996:
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.
bjorn3 edited a comment on issue #5996:
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.
a-nick-fischer commented on issue #5996:
Alright I see. I'll be going with the gcc solution then too
a-nick-fischer closed issue #5996:
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:
- 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 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:
- 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 callingmain
. This is also the only project I came across which usescranelift-object
. Requires an extra toolchain to be installed.- Using
cranelift-faerie
, which is deprecated. Not sure if it has the same problem, through.- I'm yet to reverse-engineer how
rustc-codegen-cranelift
does it
Last updated: Nov 22 2024 at 17:03 UTC