[all-commits] [llvm/llvm-project] 649cac: [ELF][RISCV] Implement --emit-relocs with relaxation

Job Noorman via All-commits all-commits at lists.llvm.org
Sat Sep 9 03:07:02 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 649cac3b627fa3d466b8807536c8be970cc8c32f
      https://github.com/llvm/llvm-project/commit/649cac3b627fa3d466b8807536c8be970cc8c32f
  Author: Job Noorman <jnoorman at igalia.com>
  Date:   2023-09-09 (Sat, 09 Sep 2023)

  Changed paths:
    M lld/ELF/InputSection.cpp
    M lld/ELF/InputSection.h
    A lld/test/ELF/riscv-relax-emit-relocs.s

  Log Message:
  -----------
  [ELF][RISCV] Implement --emit-relocs with relaxation

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).

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159082




More information about the All-commits mailing list