<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/135521>135521</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LoongArch] ADD/SUB and TLS relocation should move away from `FirstLiteralRelocationKind + offset`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:loongarch
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MaskRay
</td>
</tr>
</table>
<pre>
The current implementation of `R_LARCH_SUB{8,16,32,64}` and TLS relocation types relies on fixup kinds `FirstLiteralRelocationKind + offset` (originally intended for `.reloc` directives). While this is clever and prevents switch cases like
```c
case fixup_...sub8:
return ELF::R_LARCH_SUB8;
```
it needs revision.
GNU Assembler treats `.reloc` directives differently from standard relocations, notably by skipping
* Skipping STT_SECTION adjustments (when a referenced symbol is local and satisfies certain conditions, it can be redirected to a section symbol).
* Skipping STT_TLS symbol type setting for TLS relocations.
I intend to fix a `.reloc` behavior in ELFObjectWriter (https://github.com/llvm/llvm-project/pull/135519) and notice that `llvm/test/MC/LoongArch/Relocations/relax-addsub.s` (#76433) will be broken. @MQ-mengqing
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVMFu2zgQ_Rr6MoggUZJjH3SwnWq32KTFxgl6DChyZE1Nk14O5cR_v6DstinQHgoIEDDkzJv33nAUM-0cYiPqtajvZmqMgw_Ng-L9ozrPOm_OzdOAoMcQ0EWgw9HiAV1UkbwD34OY548v96vHzd8v2-e1uF0vhNwUcyE3pRRyM6_E7Z2Y56Ccgaf7LQS0Xl-y4_mInAKEDN5BT2_jEfbkDKeyLQWO9xQxKPv4PesfcgaEXIPve8aYSgu58IF25JS1ZyAX0Rk00PuQymQTYrpnKKCOdEIWcpkBfBnIIsSBGIhBWzxhmPo8Bjyhiwz8SlEPoBUjg6U9inyVvnl--bTIV-nw0vpLlmU8dgtRpksAAeMYHHy4b1OkXL3TaSHK9ftCl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