[PATCH] D153097: [RISCV] Make linker-relaxable instructions terminate MCDataFragment

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 21:47:44 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: asb, barannikov88, efriedma, jrtc27, jyknight, nickdesaulniers.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson, emaste.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD.
Herald added a project: LLVM.

`MCExpr::evaluateAsAbsolute` has a longstanding bug. When the MCAssembler is
non-null and the MCAsmLayout is null, it may incorrectly fold A-B even if A and
B are separated by a linker-relaxable instruction. This behavior can suppress
some ADD/SUB relocations and lead to wrong results if the linker performs
relaxation.

To fix the bug, ensure that linker-relaxable instructions only appear at the end
of an MCDataFragment, thereby making them terminate the fragment. When computing
A-B, suppress folding if A and B are separated by a linker-relaxable
instruction.

- `.subsection` now correctly give errors for non-foldable expressions.
- gen-dwarf.s will pass even if we add back the .debug_line code from D150004 <https://reviews.llvm.org/D150004>
- This will fix suppressed relocation when we add R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128.

In the future, we should investigate the desired behavior for
`MCExpr::evaluateAsAbsolute` when both MCAsmLayout is non-null.

(Note: MCRelaxableFragment is only for assembler-relaxation. If we ever need
linker-relaxable MCRelaxableFragment, we would need to adjust RISCVMCExpr.cpp
(D58943 <https://reviews.llvm.org/D58943>/D73211 <https://reviews.llvm.org/D73211>).)

Depends on D153096 <https://reviews.llvm.org/D153096>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153097

Files:
  llvm/include/llvm/MC/MCAsmBackend.h
  llvm/include/llvm/MC/MCFragment.h
  llvm/lib/MC/MCAsmBackend.cpp
  llvm/lib/MC/MCELFStreamer.cpp
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/MC/MCObjectStreamer.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
  llvm/test/MC/ELF/RISCV/subsection.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153097.531980.patch
Type: text/x-patch
Size: 8356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230616/d403b14d/attachment.bin>


More information about the llvm-commits mailing list