[all-commits] [llvm/llvm-project] 464531: [ELF] --emit-relocs: adjust offsets of .rel[a].eh_...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Mar 29 09:51:56 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 464531193353584cef7003c11ceffee61a7dc38a
      https://github.com/llvm/llvm-project/commit/464531193353584cef7003c11ceffee61a7dc38a
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-03-29 (Tue, 29 Mar 2022)

  Changed paths:
    M lld/ELF/InputSection.cpp
    M lld/ELF/InputSection.h
    M lld/test/ELF/eh-frame-merge.s
    M lld/test/ELF/ehframe-relocation.s
    M lld/test/ELF/mips64-eh-abs-reloc.s

  Log Message:
  -----------
  [ELF] --emit-relocs: adjust offsets of .rel[a].eh_frame relocations

Two code paths may reach the EHFrame case in SectionBase::getOffset:

* .eh_frame reference
* relocation copy for --emit-relocs

The first may be used by clang_rt.crtbegin.o and GCC crtbeginT.o to get the
start address of the output .eh_frame. The relocation has an offset of 0 or
(x86-64 PC-relative leaq for clang_rt.crtbegin.o) -4. The current code just
returns `offset`, which handles this case well.

The second is related to InputSection::copyRelocations on .eh_frame (used by
--emit-relocs). .eh_frame pieces may be dropped due to GC/ICF, so we should
convert the input offset to the output offset. Use the same way as
MergeInputSection with a special case handling outSecOff==-1 for an invalid
piece (see eh-frame-marker.s).

This exposes an issue in mips64-eh-abs-reloc.s that we don't reliably
handle anyway. Just add --no-check-dynamic-relocations to paper over it.

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




More information about the All-commits mailing list