[clang] [llvm] [MC,clang,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue May 7 14:31:17 PDT 2024


MaskRay wrote:

Thanks for the comments.

The syntax `-Wa,--crel -Wa,--experimental-crel` (or `-Wa,--crel,--experimental-crel`) might seem cumbersome, it serves a purpose:

* `-Wa,--experimental-crel`: no effect
* `-Wa,--crel`: driver error. Make sure users acknowledge the non-standard status.
* `-Wa,--crel,--experimental-crel`: CREL

As CREL adoption grows within the ecosystem, it has the potential to become a de-facto standard, similar to `SHF_EXCLUDE`.
Once that happens, the `--experimental-crel` flag can be deprecated and eventually removed.

This approahc parallels the strategy used for [`-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang`](https://reviews.llvm.org/D125142), albeit a nicer name.

---

I can split this PR into 5 components.

* llvm-mc
* clang driver
* yaml2obj/obj2yaml
* llvm-readobj
* llvm-objdump

The assembler testing might look bare-bone without llvm-readobj support.

---

While ELF allows extension space for processor/OS/application-specific section types, using them introduces challenges
since we want linker errors when SHT_CREL is unsupported (see `isKnownSpecificSectionType` in #85173):

* [SHT_LOUSER,SHT_HIUSER]: Not applicable as static relocation sections do not have the SHF_ALLOC flag.
* [SHT_LOOS,SHT_HIOS]: Requires annoying `SHF_OS_NONCONFORMING`. We want psABI documents to be willing to accept CREL when toolchain becomes ready, especially if their relocatable files are huge due to linker relaxation (e.g. RISC-V, LoongArch), we want to avoid GNUism / LLVMism.
* [SHT_LOPROC,SHT_HIPROC]: Processor-specific and not applicable.

We will unlikely change the format. I avoid the name `SHT_EXP_*` because the renaming would cause unnecessary churn.
We also don't want to support two section type codes, because testing would be unnecessarily complex.

Solaris-specific SHF_ORDERED and SHF_EXCLUDE, without a SunOS/Solaris name infix/prefix/suffix, make them into glibc elf.h.
`SHF_EXCLUDE` gets picked due to its linker semantics but `SHF_ORDERED` is never used.
A generic name `SHT_CREL` might not be fundamentally different from `SHF_ORDERED`.


https://github.com/llvm/llvm-project/pull/91280


More information about the cfe-commits mailing list