<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/202176>202176</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V][lld] ld.lld pack relative relocs ignored (before LLVM 15)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          XiaobingHou1219
      </td>
    </tr>
</table>

<pre>
    I ran into this while reducing a RISC-V linker testcase. The reproducer is small, and I have been seeing the same result consistently across three reruns.

### Summary
ld.lld 14.0.6 links the legal shared-object and PIE forms successfully but warns `unknown -z value: pack-relative-relocs` and leaves all relative relocations unpacked in `.rela.dyn` with no `DT_RELR` or `.relr.dyn`. ld.lld 15.0.7/16.0.6/17.0.6/18.1.8/20.1.8/22.1.0 emit the requested RELR metadata on the same input.

### Expected behavior
Link a legal RV64 GOT-address materialization sample in shared-object and PIE modes with `-z pack-relative-relocs`, which requests RELR packing for ordinary relative relocations. This is a meaningful dynamic-linking case because the output still carries live symbolic `R_RISCV_64` relocations alongside packable relatives.

### Environment
- linker route: GNU as plus ld.lld version replay
- march: rv64i
- mabi: lp64
- first failing stage: link
- local stability check: True

### Reduced testcase
These are the reduced input files from the minimized reproducer I used locally:

#### `relr-got.s`
```asm
.text
.option norelax
.option pic
.global _start
_start:
        la      x1, sym_local
        la      x1, sym_hidden
        la      x1, sym_global
        la      x1, sym_global_abs
        la      x1, sym_weak_undef
        la      x1, _DYNAMIC

sym_local:
        nop

.global sym_hidden
.hidden sym_hidden
sym_hidden:
        nop

.global sym_global
sym_global:
        nop

.global sym_global_abs
.set sym_global_abs, 42

.global sym_weak_undef
.weak sym_weak_undef
```

#### `relr-relocs.ld`
```ld
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS
{
 PROVIDE (__executable_start = 0x8000); . = 0x10000;
  .text : { *(.before) *(.text) *(.after) } =0
  . = 0x20000;
  .got : { *(.got) *(.got.plt) }
  . = 0x12340000;
  .far : { *(.far) }
 .riscv.attributes 0 : { *(.ARM.atttributes) }
  .data : { *(.data) }
}
```

### Reproduction notes
- This packaged root does not have a single canonical `run.ps1` wrapper.
- Use the reduced inputs under `case/` and follow the commands documented in `case/README.md`.
- Stable witness outputs, when present, are preserved under `verify/run1..run3/`.

### What I checked
- Reduced inputs are preserved under case/.
- Stable witness outputs are preserved under verify/run1..run3/.
- The strict recheck says stable normalized run signatures across three runs: True.
- Tracker guidance link: https://llvm.org/docs/HowToSubmitABug.html
- evidence summary: 3 clean reproductions under hunt/verify/lld_pack_relative_relocs_option_ignored_before_15/run1..run3 are stable by hash. In every run, `asm.rc.txt` is 0, `lld14.shared.stderr.txt` and `lld14.pie.stderr.txt` contain the same `unknown -z value: pack-relative-relocs` warning, and the 14 readelf outputs have only `.rela.dyn`. The same run directories show `out.15.shared.readelf.txt` and later version replays with `DT_RELR`, `RELRSZ`, `RELRENT`, and a non-empty `.relr.dyn`, proving that the input itself is legal and the first failure is old ld.lld's missing RISC-V support for the option.

### Notes
hunt/cases/confirmed/lld_pie_weak_undef_dynamic_relocs_dropped_after_18/relr-got.s and relr-relocs.ld

Root key: `lld.riscv.pack_relative_relocs_ignored_before_15`
Case id: `20260528-lld-pack-relative-relocs-ignored-before-15`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUWFtv47ju_zTuCxHBdu4PfWibdrfATGeRZub_3_MSyBYd61SWfHRJm_n0B5TtJs2ku2eBYsaiSIqkfuIl3Dm504jXyfQ2ma6uePC1sdf_L7kppN79bkKWZ8urwojD9SNYrkFqb8DX0sFrLRWCRRFKqXfAYf34fDf6AUrqF7Tg0fmSO2SwqYmttUaEEi1IB67hSiX5HXAt4BFqvkcoEDU4RNLlawTHGxJzQXkojXbSedReHYCX1jgHvrZIDDZox5J0laQ3_b_5uPuD59A03B46shJMKQHZhKVsFo108RyFO67A1dyiGJni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