Issue 149583
Summary [LLD][RISCV] LLD RISC-V relaxation bug
Labels lld
Assignees
Reporter luismarques
    While investigating #82752, @jwnrt and I found the following bug:

```shell-session
$ cat bug.s
  .text
  .global _start
_start:
 call _start
  .equ x, _start + 4

$ clang -target riscv32 -march=rv32i -mrelax -nostdlib -fuse-ld=lld -o bug bug.s && llvm-readelf -Ws bug

Symbol table '.symtab' contains 5 entries:
   Num:    Value  Size Type    Bind Vis       Ndx Name
     (...)
     3: 000110d4     0 NOTYPE  GLOBAL DEFAULT 1 _start
     4: 000110d4     0 NOTYPE  GLOBAL DEFAULT     1 x
```

The relaxation of the `call` (`auipc` + `jalr`) into just the `jalr` should not affect `x = _start + 4`, but it does. The symbol `x` gets assigned the final address `_start + 0` instead of `_start + 4`.

For completeness, we have the following combinations of `x = _start + offset` requested offsets and generated offsets:

| offset | LLD    | Binutils |
|--------|--------|----------|
|     -1 | -1 - 4 |       -1 |
|      0 | 0 |        0 |
|      1 |  1 - 4 |        1 |
|      4 |  4 - 4 | 4 |
|      5 |  5 - 4 |    5 - 4 |
|      8 |  8 - 4 |        8 |
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to