Skip to content

[LLD][RISCV] LLD RISC-V relaxation bug #149583

@luismarques

Description

@luismarques

While investigating #82752, @jwnrt and I found the following bug:

$ 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 - 4
9 9 - 4 9

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions