[PATCH] D159082: [lld][RISCV] Fix --emit-relocs with relaxation

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 04:12:57 PDT 2023


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

Linker relaxation may change relocations (offsets and types). However,
when --emit-relocs is used, relocations are simply copied from the input
section causing a mismatch with the corresponding (relaxed) code
section.

This patch fixes this as follows: for non-relocatable RISC-V binaries,
`InputSection::copyRelocations` reads relocations from the relocated
section's `relocations` array (since this gets updated by the relaxation
code). For all other cases, relocations are read from the input section
directly as before.

In order to reuse as much code as possible, and to keep the diff small,
the original `InputSection::copyRelocations` is changed to accept the
relocations as a range of `Relocation` objects. This means that, in the
general case when reading from the input section, raw relocations need
to be converted to `Relocation`s first, which introduces quite a bit of
boiler plate. It also means there's a slight code size increase due to
the extra instantiations of `copyRelocations` (for both range types).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159082

Files:
  lld/ELF/InputSection.cpp
  lld/ELF/InputSection.h
  lld/test/ELF/riscv-relax-emit-relocs.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159082.554254.patch
Type: text/x-patch
Size: 6563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230829/1defa02f/attachment.bin>


More information about the llvm-commits mailing list