Reputation: 21
Does any body has clue why I get below error :-
/tmp/cceP5axg.o: in function `.L0 ':
(.text+0xc4): relocation truncated to fit: R_RISCV_JAL against `*UND*'
collect2: error: ld returned 1 exit status
Typical error looks like:
relocation R_RISCV_JAL out of range: 4734022 is not in [-1048576, 1048575];
Upvotes: 2
Views: 3327
Reputation: 38098
One approach would be to try building with optimization flag (e.g., -O2 or -O3 as suggested in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111420#c3)
I've opened a bug with binutils for tracking this issue:https://sourceware.org/bugzilla/show_bug.cgi?id=30855
Upvotes: 0
Reputation: 11
Since I've searched many resources to solve this issue, I think my attempt may help others. There're 2 reasons may trigger this issue:
bne ra, ra, <odd offset>
bne ra, ra, 0x80003000
My attempt to solve:
label:
addi x0, x0, 0x0
addi x0, x0, 0x0
bne ra, ra, label + 6 // Jump to an address that relates to a label
// This can generate Instruction Address Misaligned exception
sub_label:
addi x0, x0, 0x0
beq ra, ra, sub_label // Jump to a label directly
addi x0, x0, 0x0
nop
Upvotes: 1
Reputation: 41
This error can also happen as an odd result of branch instructions that use hard-coded offsets. I was getting the same exact error on a program that was far less than 2Mib. It turns out it was because I had several instructions that looked like bne rd, rs, offset
, but the offset was a number literal like 0x8.
The solution was to remove the literal offset and replace it with a label from the code so it looks like
bne x7, x9, branch_to_here
[code to skip]
branch_to_here:
more code ...
instead of
bne x7, x9, 0x8
[code to skip]
more code ...
When I did that to every branch instruction, the error went away. Sorry to answer this 10 months late, but I hope it helps you, anonymous reader.
Upvotes: 2
Reputation: 1746
R_RISCV_JAL relocation can represent an even signed 21-bit offset (-1MiB to +1MiB-2). If your symbol is further than this limit , then you have this error.
Upvotes: 3