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

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V][lld] lld.riscv.missing_pt_riscv_attributes_program_header
        </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
GNU ld.bfd 2.45 emits a dedicated RISCV_ATTRIBUT program header mapping only .riscv.attributes, while ld.lld 18.1.8/19.1.7/20.1.8/21.1.3/22.1.0 emit only generic LOAD headers and place .riscv.attributes under a LOAD segment mapping.

### Expected behavior
Link a tiny RV32 executable carrying a normal .riscv.attributes section and verify that output ELF program headers represent that metadata correctly.

### Environment
- linker route: GNU as plus ld.lld version replay with GNU ld.bfd control
- march: rv32ic
- mabi: ilp32
- first failing stage: link
- local stability check: True

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

#### `attr-phdr.s`
```asm
        .attribute arch, "rv32i2p0_m2p0"
        .option nopic
        .text
        .align  1
        .globl  _start
        .type   _start, @function
_start:
        ret
        .size   _start, .-_start
```

### 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_missing_pt_riscv_attributes_phdr/run1..run3 show stable GNU-as assembly success, stable GNU ld.bfd outputs whose readelf -l -S contains a RISCV_ATTRIBUT program header and section-to-segment mapping with .riscv.attributes isolated from .text, and stable ld.lld 18/19/20/21/22 outputs whose readelf -l -S contain only LOAD headers and map .riscv.attributes under a LOAD segment.

### Notes
upstream///binutils-gdb/ld/testsuite/ld-riscv-elf/attr-phdr.d

Root key: `lld.riscv.missing_pt_riscv_attributes_program_header`
Case id: `20260526-lld-missing-pt-riscv-attributes-phdr`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVl1v2zrS_jXyzUCCRNlOfOELt6nPCdC3L5Ck3b0zKHIscUORAod06vPrF6QkO2mT3YMFhHyQ8_HM1zPkRKo1iNts9Slb3S148J11238qbhtl2j9tqFi1WTRWnrf34LgBZbwF3ymCl05pBIcyCGVa4PBw__g5_wFamWd04JG84IQFPHVRbHBWBoEOFAH1XOuMfQZuJNxDx08IDaIBQoy2fIdAvI9qFLQHYQ0p8mi8PgMXzhKB7xxGARcMFVl5l5W76Serxw8eQ99zdx6P__j2HbQsmqMEVixXgL3yBBwkSiW4R5nw_zjsnp4e7j99f4LB2dbxHjrkEh30fBgiNmv0GQqnSJwK7r1TTfBIMZgxIVoWWkuobouquM3YvtoUVXGTsT0rpxNWFVVRxz9YURVlQjKabdGgUwK-_v_ubvJLKUeD5gJ_9wrBRGh8VCBsezR-RvpBUr78HFDEcBvs-ElZNwp8VeYZOHhlzvDwo2aAP1EEzxuNILhz57HGxrqe63eQEAqvrEloT-jU8Qy-4x5s8EPw8OXr_peEUuoJpIg4SfboueSeg7DOofD6_FEE5qScNTHW8Sqfe87Z4DGrdxCLzQkGHWguyAkdRYAOB83P8KJ8B696QljjndWzwZ470UVL7lQzJa7HjYqnSg81mw-PypGHI1c65og8bxOGiOmCzwqu41WjtPJnEB2K5yj05AK-H-VDHCyUlzka7586JATuMM2Im2SUiTk-Ko0ER2f7dNkro3r1F8rXw3cPgVCOePQ5q3fvOo_-s3UZy5sPnXQFZetyklmX48epn3U310aAlDf2GTLGUurYUB56NpQZY1dxO6ReMXaYUxtPPf70r0x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