<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109138>109138</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
TLS segment offset calculation different for target i386 and i386-unknown-linux
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
prabhjotsingh3
</td>
</tr>
</table>
<pre>
Hi,
The tls offsets calculation logic seems to be different for target i386 and i386-unknonwn-linux for local-exec model.
Example code :-
```
#include <stdio.h>
__thread int myvar;
int main(void)
{
myvar = 0;
return 0;
}
```
For target i386 :-
Command - `clang -ftls-model=local-exec --target=i386 -v thread.c`
```
080484a0 <main>:
80484a3: 50 push %eax
80484a4: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
80484ab: 65 a1 00 00 00 00 mov %gs:0x0,%eax
80484b1: c7 80 fc ff ff ff 00 movl $0x0,-0x4(%eax)
80484b8: 00 00 00
80484bb: 31 c0 xor %eax,%eax
80484bd: 83 c4 04 add $0x4,%esp
80484c0: 5d pop %ebp
80484c1: c3 ret
```
For target i386-unknown-linux :-
Command - `clang -ftls-model=local-exec --target=i386-unknown-linux -v thread.c`
```
000011a0 <main>:
11a0: 55 push %ebp
11a1: 89 e5 mov %esp,%ebp
11a3: 50 push %eax
11a4: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
11ab: 65 c7 05 fc ff ff ff movl $0x0,%gs:0xfffffffc
11b2: 00 00 00 00
11b6: 31 c0 xor %eax,%eax
11b8: 83 c4 04 add $0x4,%esp
11bb: 5d pop %ebp
11bc: c3 ret
11bd: 66 90 xchg %ax,%ax
11bf: 90 nop
```
Would be grateful if anyway could please let me know the reason for this and is there anyway to control this via clang arguments?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk2P6yYU_TVkc-UIA3achRfzJhN10V2f1OUTxtjmFYMFOJP595U_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