<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87127>87127</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV] Relocation truncated to fit with -O0 on very large functions.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
topperc
</td>
</tr>
</table>
<pre>
clang -O0 implicitly passes -mno-relax-all. This causes the MC layer to relax all jumps to the longest form possible. Except we don't convert uncompressed relative jumps to indirect since that requires a temporary register.
The CodeGen layer carefully measured the function size and relaxed any branches and unconditional branches that it needed to, but it is not aware of the relaxation the MC layer is going to do for -mrelax-all.
If the function is sufficiently large, relaxing the branches in the MC layer may cause some unconditional jump to go out of range leading to a linking failure.
I believe the branch relaxation was added to the MC layer to make things easier for programmers writing handwritten assembly so they didn't have to worry about the small offset of conditional branches. Maybe we should disable it when assembling CodeGen output?
cc: @preames @MaskRay @jrtc27 @kito-cheng @asb
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxslMFy4zYMhp9GvmDskSk7dg46pEnd2UOmM-lO7xAJSUgoUiXIOOrTd0i7dbLdi02JJP4PwC-gCA-OqK32v1T7pxWmOPrQRj_PFPSq82ZptUU3wPr3GniaLWuOdoEZRUhgPTm_DmTxY43WbuD7yAIaU96LI8HzI1hcKED0UI4BWguvaZolv8pHrHcDSYTehwlmL8KdpQ38-qFpjnAmMN5V6hBBe_dOIUJy2k9zIBEyJWjkd7rFZGc4kI4g7DRBHDFCoL8SBxJAiDTNPmBYINDAEilsqvqpqh8uv99Hgkdv6DdyV3KNgfpk7QIToaRApmD3yenI3oHw3wToLigfZADdAl1Ap8cs6EwBdobzabS3rULGERyRyUF9pR6hS-UdCzgfAc8YCHxfFEt8LJpfSssCg2c35OSNz3WE9XTryefsvvVf2VlAUt-zZnK5qxbDQBmjXC8xR7oR8w_KEy6XZoP4iX7IMzckIw0efIo5iYBuILCE5kqLYNm95Yce2aZAX2GhI8v0Tp8gPhfhjAJoLqX7n9kmfMv32A0ChMIUSmHm4IeA00RB4Bw4Zu0RncnrSA6yq6fOLiAl5AKGzcV9I2YQD2cfwgLY5ZyyqEzZ0b7vhUqSP2v1Bp5x6SibWUafrAHDgp2l3OrzeNPNOP-6z6c4p1g1p8810bpqHqDa1XMgnEjy8hnl7QWXvHwNUatDXr1x9Gs9khvyE0oHK9M25r65xxW128N2e9jv1fa4Gttme6fUTtPhqI67g6q1vjsejdrtu8Phvj_SiltVq13dqHvVNE1z3OgadXO8u6ub5g5x31e7miZku7H2fdr4MKxYJFF7PGzVYWWxIytlwijl6Axls1IqD5zQ5jvrLg1S7WrLEuUWJXK0ZTS9fPvj8c9q_wQvZL2-fgMhOY3x0v4-F5LjWMaUd_BO4erm_8wum1UKth1jnKVqHip1qtRp4DimbqP9VKlT1r3-refgX0nHSp0KrVTqVLL5JwAA__-7ecvq">