<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/77128>77128</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM uses R_X86_64_TPOFF32 relocations for large code model (-mcmodel=large), resulting in 'relocation truncated to fit' error
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nmosier
</td>
</tr>
</table>
<pre>
LLVM appears to generate R_X86_64_TPOFF32 relocations for accesses to thread-local variables, even when the large code model is enabled with the clang flag `-mcmodel=large`. This results in a linker error for programs that require >4GB thread-local data sections (.tdata and .tbss).
Here is an example program that fails to compile:
```c
#define BUFSIZE (1024UL * 1024UL * 1024UL * 5UL)
_Thread_local char buf[BUFSIZE];
int main() {
buf[BUFSIZE-1] = 0;
}
```
Compile as follows: `clang -mcmodel=large test.c`
Produces following error:
```
/tmp/user/20498/large-633e12.o: in function `main':
large.c:(.text+0xf): relocation truncated to fit: R_X86_64_TPOFF32 against symbol `buf' defined in .tbss section in /tmp/user/20498/large-633e12.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVF2PozYU_TU3L1dBxkAIDzxMNktbaaqu2pmq6ktk4AJujZ3aJjP77yubJO3ujNqVoiSYe-7XOT7COTlqohqKAxTHjVj8ZGytZ-Mk2U1r-s_14-OvP6I4n0lYh97gSJqs8IQ_n37b7067_PT06aemyThaUqYTXhrtcDAWRdeRcxRRfrIk-m0IUHgRVopWkQP-AelCGl8m0ugnQiXsSNiZnnA2PSmUDkmH4B5fpJ9iUKeEHnFQYkTYse3cxVDIjhENO5bg0yQdWnKL8g6lRoFK6j_JIllrbGzvbM1oxezQT8Kjpb8WaQkh-5h_d_iy3154gY66dTTg-8THI6F7THzrHPAqAXYE9rB-f0-WQudCI72K-azoVm0tNgip4lo6M5-lIsiuQNix9dNdn3nW0yA14eG5-eWH3z-G6inj-fMjAn_A9_8Wz4_AqzXD6SlOclon6SZhsV0GKA7XhFAcITussVJ7nIXUwPfAK4Tyeo5fQrYpFEeE7IjsDoXy-NUE6-OHdUAUQRJKmRcH2UNgbeXwa-7Qk_NJd4d_sqZfOrqBpR5XAmOS9-oBb_x8Bt4sjizwhrO82gNvYvbtLsso5YkJcKlxWHTkNPSzzl3emYiApAvPgW969cAP7HUIi80e_qV19HbRnfDUB0IH6cPrN3dDjEJq59F9nlujQsGwUl7iSm8f2olSuuksHHzjMLHfuM9Q-r6fq-A7M89BqEFzt0tEr9KvlywNgloc4fYS2ndEKPXlOtpdRPclb_o666usEhuq05Ll-T4t8moz1QVVlFdtllKblbuC2K5q27JtB5ZRN2R8I2vOeM5SVqQVK_J9wtK8zDPBurwti1K0kDOahVSJUpc5MXbcSOcWqssy5fuNEi0pF32Kc00vGF8C58G2bB0w23YZHeRMSefdP1m89IpWF1uCGf2vbb2xIOD7Nx7Dq-Bdq8EEVUa2yv9SBS9XajaLVfXk_dlFbTXAm1H6aWmTzsyBXHW5_WzP1vxBnQfexHEd8Cau4-8AAAD__6yEyVg">