https://sourceware.org/bugzilla/show_bug.cgi?id=33191

            Bug ID: 33191
           Summary: RISC-V relaxation affects unrelated symbol
           Product: binutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: luismarques at lowrisc dot org
  Target Milestone: ---

For context, this bug is the binutils/ld counterpart of essentially the same
LLD bug we filed earlier: https://github.com/llvm/llvm-project/issues/149583

In the following reproducer, the symbol x is being moved due to the call
relaxation, when it arguably shouldn't be affected, as it's defined only
relative to _start.

$ cat bug.s
  .text
  .global _start
_start:
  call _start
  .equ x, _start + 8

$ riscv64-linux-gnu-gcc -march=rv32i -mabi=ilp32 -mrelax -nostdlib -o bug bug.s
&& readelf -Ws bug

Symbol table '.symtab' contains 25 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
    (...)
    12: 000001bc     0 NOTYPE  LOCAL  DEFAULT    6 x
    (...)
    19: 000001b8     0 NOTYPE  GLOBAL DEFAULT    6 _start

That is, we observe x = _start + 4 instead of _start + 8.

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 |

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to