[LLD] Sorting in RelocationBaseSection::computeRels() breaks R_RISCV_VENDOR
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
RISCV vendor-specific relocations are implemented be placing an `R_RISCV_VENDOR` relocation (which points to a vendor-specific symbol) before each `R_RISCV_CUSTOM[192-155]` relocations. This prepending order needs to be preserved in the dynamic relocations in order for them to be correctly parsed.
Today, we sort dynamic relocations in this code: https://github.com/llvm/llvm-project/blob/98ceb458f42ed05e2c3e9fb5bc75cd6b1df7a438/lld/ELF/SyntheticSections.cpp#L1722
based on the tuple of (symbol, offset). This is incompatible with `R_RISCV_VENDOR`, since the `R_RISCV_VENDOR` will point to a difference symbol than the following custom relocation.
I can see a few possible solutions, and would like to get input:
- Should we sort only by offset on RISCV?
- Should we sort only be offset if we know vendor-specific relocations are present?
- Should we try to be clever and treat the pair of relocations as a unit for the purposes of sorting?
Contributor guide
Research direction
Start at lld/ELF/SyntheticSections.cpp around line 1722, where dynamic relocations are sorted by symbol and offset. Read RelocationBaseSection::computeRels() and the R_RISCV_VENDOR and R_RISCV_CUSTOM[192-155] handling. Done means preserving the required vendor-relocation ordering so the dynamic relocations can be parsed correctly.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100