[all-commits] [llvm/llvm-project] 0af07c: [ELF] Support relocatable files using CREL with ex...

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Aug 1 10:22:25 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0af07c078798b7c427e2981377781b5cc555a568
      https://github.com/llvm/llvm-project/commit/0af07c078798b7c427e2981377781b5cc555a568
  Author: Fangrui Song <i at maskray.me>
  Date:   2024-08-01 (Thu, 01 Aug 2024)

  Changed paths:
    M lld/ELF/DWARF.cpp
    M lld/ELF/ICF.cpp
    M lld/ELF/InputFiles.cpp
    M lld/ELF/InputFiles.h
    M lld/ELF/InputSection.cpp
    M lld/ELF/InputSection.h
    M lld/ELF/LinkerScript.cpp
    M lld/ELF/MarkLive.cpp
    M lld/ELF/OutputSections.cpp
    M lld/ELF/OutputSections.h
    M lld/ELF/Relocations.cpp
    M lld/ELF/Relocations.h
    M lld/ELF/SyntheticSections.cpp
    M lld/ELF/Writer.cpp
    A lld/test/ELF/crel-rel-mixed.s
    A lld/test/ELF/crel.s
    M lld/test/ELF/debug-names.s
    M lld/test/ELF/gc-sections.s
    M lld/test/ELF/icf1.s
    M lld/test/ELF/icf4.s
    M lld/test/ELF/linkerscript/nocrossrefs.test
    A lld/test/ELF/relocatable-crel-32.s
    A lld/test/ELF/relocatable-crel.s

  Log Message:
  -----------
  [ELF] Support relocatable files using CREL with explicit addends

... using the temporary section type code 0x40000020
(`clang -c -Wa,--crel,--allow-experimental-crel`). LLVM will change the
code and break compatibility (Clang and lld of different versions are
not guaranteed to cooperate, unlike other features). CREL with implicit
addends are not supported.

---

Introduce `RelsOrRelas::crels` to iterate over SHT_CREL sections and
update users to check `crels`.

(The decoding performance is critical and error checking is difficult.
Follow `skipLeb` and `R_*LEB128` handling, do not use
`llvm::decodeULEB128`, whichs compiles to a lot of code.)

A few users (e.g. .eh_frame, LLDDwarfObj, s390x) require random access. Pass
`/*supportsCrel=*/false` to `relsOrRelas` to allocate a buffer and
convert CREL to RELA (`relas` instead of `crels` will be used). Since
allocating a buffer increases, the conversion is only performed when
absolutely necessary.

---

Non-alloc SHT_CREL sections may be created in -r and --emit-relocs
links. SHT_CREL and SHT_RELA components need reencoding since
r_offset/r_symidx/r_type/r_addend may change. (r_type may change because
relocations referencing a symbol in a discarded section are converted to
`R_*_NONE`).

* SHT_CREL components: decode with `RelsOrRelas` and re-encode (`OutputSection::finalizeNonAllocCrel`)
* SHT_RELA components: convert to CREL (`relToCrel`). An output section can only have one relocation section.
* SHT_REL components: print an error for now.

SHT_REL to SHT_CREL conversion for -r/--emit-relocs is complex and
unsupported yet.

Link: https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600

Pull Request: https://github.com/llvm/llvm-project/pull/98115



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list