Hi, new member here,
I wanted to know if here was the right place, being a total beginner in compiler development, to ask for help
infrandomness said:
Hi, new member here,
I wanted to know if here was the right place, being a total beginner in compiler development, to ask for help
if I can ask for help here :
Hello guys, I'm in the process of creating a compiler for my programming language in rust with cranelift
I had questions about cranelift-module and cranelift-object :thinking:
I currently use both cranelift-module and cranelift-object to put together an ELF file. (I helped myself of https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/object/tests/basic.rs#L149 to put something together)
The ELF file looks fine except for a thing, the file headers of the ELF file indicate
object: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000
the start_address variable is set to 0, which means that the ELF file will never be able to know where to start execution at if the kernel executes the ELF
Does anyone know how to fix that ? What am I missing ?
and last question : in the code, there is usage of malloc and https://docs.rs/cranelift-frontend/latest/cranelift_frontend/struct.FunctionBuilder.html#method.call_memset,
but ldd states my ELF is not dynamically linked against anything (I can't tell if it is statically linked and if so, where is memset and memcpy)
infrandomness has marked this topic as resolved.
I was also wondering if anyone knows what part of the cranelift code determines what IR function should be considered global symbols ?
I’m having troubles having a function seen as main to my linker because it is not global
@infrandomness You should use call declare_function with Linkage::Export instead of Linkage::Local of you want to export a function.
bjorn3 said:
infrandomness You should use call declare_function with Linkage::Export instead of Linkage::Local of you want to export a function.
I am not willing to export a function, but I am willing to have GNU ld detect my main function, and I think the reason as to why it does not is because the main symbol is not global
EDIT: your suggestion seems to have fixed it :+1:
The linker doesn't export symbols from am executable by default. You need to export main
from the local object file for the linker to resolve it in the crt object which uses it.
Last updated: Nov 22 2024 at 16:03 UTC