Missed CALL relaxation due to single pass of CALL relaxations

Open
#666 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Start with the supplied RISC-V assembly and linker script, then run the llvm-mc, ld.eld, and llvm-objdump commands to reproduce the missed relaxation. Trace the linker’s CALL-relaxation pass and its handling of earlier calls. Done means the call at address 0x0 is relaxed to a JAL when its final displacement is in range.

Written by the indexing model from the issue text.

Description

enhancement risc-v

We only perform a single pass of CALL relaxations. This result in missed relaxations when a CALL relaxation can decrease the caller -callee displacement of a previous call.

Reproducer:

#!/usr/bin/env bash

cat >1.s <<\EOF
.section .text
.global _start
_start:
  jump high, t0

.section .high, "ax", @progbits
  jump high, t0
high:
  nop
EOF

cat >script.t <<\EOF
SECTIONS {
  .text 0x0 : { *(.text) }
  .high 0xffffa : { *(.high) }
}
EOF

llvm-mc -o 1.o -filetype=obj -triple=riscv64 -mattr=+c,+relax 1.s
#clang -o 1.o 1.s -c 
LDs=(ld.eld)
SFs=(eld)

for i in "${!SFs[@]}"; do
  ${LDs[$i]} -o 1.${SFs[$i]}.out 1.o -T script.t
done

llvm-objdump -d 1.eld.out output:

Disassembly of section .text:

0000000000000000 <_start>:
       0: 00100297      auipc   t0, 0x100
       4: ffc28067      jr      -0x4(t0) <high>

Disassembly of section .high:

00000000000ffffa <.high>:
   ffffa: a009          j       0xffffc <high>

00000000000ffffc <high>:
   ffffc: 0001          nop

The caller-callee displacement for the high call at 0x0 is 0xffffc that is within the range of immediate operand of JAL instruction
and thus we can relax AUIPC + JALR to JAL here.

Dominant language
C++
Stars
259
Forks
84
Avg merge
2d 14h
Merged PRs (30d)
72

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from qualcomm/eld

All issues in qualcomm/eld

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.