[RISCV] relocation R_RISCV_JAL out of range
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Description
I wrote a cpp file showed below ,with two HUGE branches in the if-else control flow . When linking I got this error. Is there any way to solve this problem?
## Reproduce
### Version
```
clang version 22.1.5
```
### Codes
```C++
// a.cpp
int foo (int a) {
if (a) {
asm volatile (".rept 0x200000\n nop\n .endr\n"::: "memory");
return a+1;
} else {
asm volatile (".rept 0x210000\n nop\n .endr\n"::: "memory");
return a+2;
}
}
int g_value1;
int g_value2;
int main() {
g_value2 = foo(g_value1);
}
```
### Commands
``` cmd
clang --target=riscv64 a.cpp -O3 -c -o a.o
ld.lld a.o -X --relax -o a.out
```
## Results
```
ld.lld: warning: cannot find entry symbol _start; not setting start address
ld.lld: error: a.o:(function foo(int): .text+0x2): relocation R_RISCV_JAL out of range: 4194312 is not in [-1048576, 1048575]; references '.L0 '
>>> referenced by a.cpp
>>> defined in a.o
ld.lld: error: a.o:(function main: .text+0x820018): relocation R_RISCV_JAL out of range: 4194322 is not in [-1048576, 1048575]; references '.L0 '
>>> referenced by a.cpp
>>> defined in a.o
```
Contributor guide
Research direction
Start by compiling the provided a.cpp with the exact clang command, then run the ld.lld command to reproduce the R_RISCV_JAL out-of-range errors. Trace how the linker handles the two large conditional branches and determine the expected behavior for this relocation. Done should include a justified resolution and coverage for this reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100