Open KilianVounckx opened 1 year ago
The format
and run
panics are likely separate bugs. Can you try passing --linker=legacy
to roc run
and see if that helps?
It works with the --linker=legacy flag. The compile time is much longer now though. Thanks for the quick response.
cc @bhansconnect who has implemented the default linker.
I don't have access to my x86 machine for a few days, but will look into this once I do.
I did some digging. The relocation in question is
[crates/linker/src/lib.rs:2788] &rel = (
26934,
Relocation {
kind: Relative,
encoding: Generic,
size: 32,
target: Symbol(
SymbolIndex(
587,
),
),
addend: -4,
implicit_addend: false,
},
)
That symbol is
[crates/linker/src/lib.rs:2788] app_obj.symbol_by_index(index) = Ok(
Symbol {
name: "",
address: 0,
size: 0,
kind: Section,
section: Section(
SectionIndex(
9,
),
),
scope: Compilation,
weak: false,
flags: Elf {
st_info: 3,
st_other: 0,
},
},
)
The symbol name is empty, and that means we can't find it in our hashmap of functions which we know how to relocate.
Looking at the symbol table:
583: 0000000000001d6c 18 OBJECT LOCAL DEFAULT 8 __unnamed_432
584: 0000000000001d7e 17 OBJECT LOCAL DEFAULT 8 __unnamed_433
585: 0000000000001d8f 18 OBJECT LOCAL DEFAULT 8 __unnamed_434
586: 0000000000001da1 18 OBJECT LOCAL DEFAULT 8 __unnamed_435
587: 0000000000000000 0 SECTION LOCAL DEFAULT 9
588: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND roc_alloc
589: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND memcpy
590: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND memset
591: 0000000000003140 486 FUNC WEAK DEFAULT 2 __muloti4
Our symbol 587
is of kind SECTION
, which is odd. It is in secton 9, which is
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .strtab STRTAB 0000000000000000 01ce50 00395a 00 0 0 1
[ 2] .text PROGBITS 0000000000000000 000040 00c3b8 00 AX 0 0 16
[ 3] .rela.text RELA 0000000000000000 018440 0014b8 18 14 2 8
[ 4] .rodata.cst16 PROGBITS 0000000000000000 00c400 000100 10 AM 0 0 16
[ 5] .rodata.cst8 PROGBITS 0000000000000000 00c500 0000a0 08 AM 0 0 8
[ 6] .rodata PROGBITS 0000000000000000 00c5a0 003448 00 A 0 0 8
[ 7] .rela.rodata RELA 0000000000000000 0198f8 0001f8 18 14 6 8
[ 8] .rodata.str1.1 PROGBITS 0000000000000000 00f9e8 001dd8 01 AMS 0 0 1
[ 9] .data.rel.ro PROGBITS 0000000000000000 0117c0 002880 00 WA 0 0 8
[10] .rela.data.rel.ro RELA 0000000000000000 019af0 002880 18 14 9 8
This is where my (current) knowledge stops.
So this definitely seems to be the same root issue as #3609. The fix would theoretically be what is mentioned here: https://github.com/roc-lang/roc/issues/3609#issuecomment-1193179430.
In the case the cause is specifically Num.toStr
on floats. If you remove that function and just replace it with something silly like (\x -> if x > 0 then "+" else "-")
, it will compile with the surgical linker.
What this really means is that the zig builtin creates a constant pointer to constant data. The surgical linker can not yet deal with constant pointers. They need to be converted to a relocation that will happen at run time. Before run time, we don't know the correct address space to setup pointers correctly. Theoretically, we could change the zig builtin in some way to fix this, but really the root issue needs to be addressed.
Anything nested and constant will use section like .data.rel.ro
and we currently don't have code to deal with relocations for that.
This bug could be issued already, but the compiler told me to file a new issue, so I will :)
I translated the RPN calculator from learnyouahaskell to roc. It is not the most performant or idiomatic translation, but it was a first try. Here is the code:
After running
RUST_BACKTRACE=full roc run
, I get the following output:Running
roc check
does not give any errors, Runningroc build
gives the same error.Running
roc format
gives this error:I understand the language is new, and there are still a lot of bugs needed to be fixed. I just hope this issue can help someone fix one bug!