<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202179>202179</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] ld.lld undefined weak PCREL address not resolved to zero rv32 high text
</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 links the legal high-text sample and folds the unresolved weak address materialization to `li a5,0`, but ld.lld 18.1.8/20.1.8/21.1.3/22.1.0 link the same input successfully while keeping `auipc a5,0x70000; mv a5,a5`, so the final weak address is non-zero and the following `beqz` observes the wrong value.
### Expected behavior
Link a normal RV32 executable at a high text address while materializing the address of an undefined weak function `f` with `lla`. This is a meaningful startup pattern for probing optional callbacks: unresolved weak addresses must resolve to the constant zero value.
### Environment
- linker route: GNU as plus ld.lld with GNU ld.bfd control
- march: rv32i
- mabi: ilp32
- first failing stage: link
- local stability check: False
### Reduced testcase
The testcase is already minimized locally, but this case directory does not contain a small source-only subtree I can paste directly here.
### 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: False.
- Tracker guidance link: https://llvm.org/docs/HowToSubmitABug.html
- evidence summary: 3 clean reproductions under hunt/verify/lld_weakref32_undefined_weak_pcrel_not_zero/run1..run3 show stable GNU-as assembly success, stable GNU ld.bfd outputs beginning with `li a5,0; beqz a5`, and stable ld.lld 18/20/21/22 outputs beginning with `auipc a5,0x70000; mv a5,a5; beqz a5`. The normalized instruction-fragment hashes are identical across run1..run3 for every linker variant, confirming stable reproduction. This is distinct from the RV64 false-overflow weak root because the RV32 link succeeds and the defect is a wrong final address value, not a link-time range diagnostic.
### Notes
upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/weakref32.s; D:/search_ascii/upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/weakref32.d; D:/search_ascii/upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/weakref.ld
Root key: `lld.riscv.undefined_weak_pcrel_address_not_resolved_to_zero_rv32_high_text`
Case id: `20260528-lld-weakref32-undefined-weak-pcrel-not-zero`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V0tv4zgS_jXKpWBBlmPHPviQR3umgdnGIj3duzejRJYkbihSy4fd7l-_KOrhZJDMXHaAIFEosp5ffR-F3qvGEO2z9UO2frrBGFrr9v9WaCtlml9tXJbL3U1l5WX_GRwaUCZYCK3ycG6VJnAko1CmAYTnz18fF99BK_NCDgL5INBTDr-3vK13VkZBDpQH36HWWfkIaCR8hhZPBBWRAU_EtkJL4LHjYz7qAMIar3wgE_QFUDjrPYTWEW9w0fg8K56y4n78Xa6GH_gauw7dZVj-5cs30DKvapki9MmJpgY1tKppF4F-BHbaa0ph1VbLYVM0jrzVJ5JwJnwBlNKR99BhIKdQq58YlDUQLGSbQivAdVY-Ftmm4BSrGNiv1hKW23yZb7PyUBbTwzJf5it-KPNlXqTIrtkr08cAPgpB3tdR68tY9BeinuuUbQqMqhejxx93RVEU2eoButOwhOsxCm-T2VoZ1G-zUB6MNYuf5GzKO22zWtvz6KGi__7MNgXYypM70VCTs7OmgRPqSB8U_9OPnkQgCRW1eFLWDRt-4wwRjHUdanj-viqBfpCIASsufABM7YDUjinGIetrvSeMTO9tDWggGkm1MlOb6mhE6ku2KWpO4KxCmzqkMdsUjEuV0kfoCI0yTR01-IAuxB56DIGcgdo66F2aBrA920MNArWuULz4bHX_ETzIQxd9gPElhKEDDOWAJkAq-J8W0JyUs6YjE4ZXi2m0nI2B2DV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