[PATCH] D71978: [RISCV] Fix evalutePCRelLo for symbols at the end of a fragment

James Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 14:15:44 PST 2020


jrtc27 added a comment.

Perhaps this helps. Let's take:

      nop
  .option pop
  1:  auipc a1, %pcrel_hi(foo)
      addi a1, a1, %pcrel_lo(1b)

As fragments, this ends up being:

  Fragment1 {
      nop
  .Ltmp0:
  }
  
  Fragment2 {
      auipc a1, %pcrel_hi(foo)
      addi a1, a1, %pcrel_lo(.Ltmp0)
  }

What this code is trying to do is make the `%pcrel_lo(.Ltmp0)` look like a more conventional `%pcrel_lo(foo + (. - .Ltmp0))`. To do so, it requires `.` and `.Ltmp0` be in the same fragment, since `getOffset` for `.Ltmp0` and the `%pcrel_lo` fixup both return their offset within the fragment. This is checked earlier by ensuring `findAssociatedFragment()` matches for each.

AUIPCSymbol here is `.Ltmp0` and has offset 4 within Fragment1. We call `getPCRelHiFixup`, which sees that the symbol is at the end of the fragment, looks in the next one (Fragment2) at offset 0 and gives us back that `%pcrel_hi(foo)`. The caller is however unaware that the fixups are in a different fragment to AUIPCSymbol and so should do the same check as happens inside `getPCRelHiFixup` so they agree on when to advance to the next fragment. The caller should thus see that `.Ltmp0` is at the end of Fragment1, and that the AUIPC is therefore really at the very beginning of the next fragment, ie offset 0. This gives us the correct value for `. - .Ltmp0` of `4 - 0` rather than `4 - 4`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71978/new/

https://reviews.llvm.org/D71978





More information about the llvm-commits mailing list