Stream: general

Topic: ✔ A bit of help ?


view this post on Zulip infrandomness (Apr 24 2022 at 16:21):

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

view this post on Zulip infrandomness (Apr 24 2022 at 16:36):

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)

Standalone JIT-style runtime for WebAssembly, using Cranelift - wasmtime/basic.rs at main · bytecodealliance/wasmtime

view this post on Zulip Notification Bot (Apr 24 2022 at 17:22):

infrandomness has marked this topic as resolved.

view this post on Zulip infrandomness (Apr 25 2022 at 09:51):

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

view this post on Zulip bjorn3 (Apr 25 2022 at 19:20):

@infrandomness You should use call declare_function with Linkage::Export instead of Linkage::Local of you want to export a function.

view this post on Zulip infrandomness (Apr 25 2022 at 20:36):

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

view this post on Zulip infrandomness (Apr 25 2022 at 22:34):

EDIT: your suggestion seems to have fixed it :+1:

view this post on Zulip bjorn3 (Apr 26 2022 at 06:23):

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: Dec 23 2024 at 12:05 UTC