[PATCH] D73211: [RISCV] Fix evaluating %pcrel_lo against global and weak symbols

James Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 09:27:37 PST 2020


jrtc27 created this revision.
jrtc27 added reviewers: asb, lenary, efriedma.
Herald added subscribers: llvm-commits, luismarques, apazos, sameer.abuasal, pzheng, s.egerton, Jim, benna, psnobl, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, MaskRay, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
Herald added a project: LLVM.

Previously, we would erroneously turn %pcrel_lo(label), where label has
a %pcrel_hi against a weak symbol, into %pcrel_lo(label + offset), as
evaluatePCRelLo would believe the target independent logic was going to
fold it. Moreover, even if that were fixed, shouldForceRelocation lacks
an MCAsmLayout and thus cannot evaluate the %pcrel_hi fixup to a value
and check the symbol, so we would then erroneously constant-fold the
%pcrel_lo whilst leaving the %pcrel_hi intact. After D72197 <https://reviews.llvm.org/D72197>, this same
sequence also occurs for symbols with global binding, which is triggered
in real-world code.

Instead, as discussed in D71978 <https://reviews.llvm.org/D71978>, we introduce a new FKF_IsTarget flag to
avoid these kinds of issues. All the resolution logic happens in one
place, with no coordination required between RISCAsmBackend and
RISCVMCExpr to ensure they implement the same logic twice. Although the
implementation of %pcrel_hi can be left as target independent, we make
it target dependent to ensure that they are handled identically to
%pcrel_lo, otherwise we risk one of them being constant folded but the
other being preserved.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73211

Files:
  llvm/include/llvm/MC/MCAsmBackend.h
  llvm/include/llvm/MC/MCFixupKindInfo.h
  llvm/lib/MC/MCAssembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h
  llvm/test/MC/RISCV/pcrel-fixups.s
  llvm/test/MC/RISCV/pcrel-lo12-invalid.s
  llvm/test/MC/RISCV/rv32i-aliases-valid.s
  llvm/test/MC/RISCV/rv32i-valid.s
  llvm/test/MC/RISCV/rv64i-aliases-valid.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73211.239623.patch
Type: text/x-patch
Size: 19493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200122/544a5dab/attachment-0001.bin>


More information about the llvm-commits mailing list