<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/109087>109087</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            TLS segment offsets 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 used is 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 it uses offsets from the beginning of tls segment :-
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 it uses offsets from the end of tls segment :-
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/eJy0Vk-To6oX_TRkc8sUghqzcDHT6dRv8du9qXrLKQRU5iFYgun0t3-lmGjSznRvHmWZP_few-FwD8qcU7WRskDpd5Sedmzwje2Lrmdl88t6p0zd0F1pxXvxP4XIC8InhL-F-49GgtcObFU56R0MTgpQDoSqKtlL46GyPXjW19KDonkGzIjpSzSYf4w1bybSygzXKU9bznQkr5JDa4XU-_VUr1fWdloCt0ICot-idXC-Z3i-wk9CleF6mPJfnBfK7htEX0P050_f9JIJUMZD-35hPaLfQ2j6hymDSH6xSiBynAEPcwLMYyoDRE-A78W3WC_90JtVAB1O2zSn-_lJJ-VHMRdlq9624BsJpayVMcrUYKtJeyfrdlR60eTFtu2ocwQow1wzU0NUee2iSVVETyuhoyjMiuhpmje6QNBlzxeGj4RxjpM8YXhUdZKJviI6LwNCjCJ6EyLF0A2uAQBEUsmuD3nJkscPkKRQccB4uUaN7UUDIgm-YkReInxNEMlHqLK7b8yMVi5oWQosfoYKaCOP2iH6LSB-ZFXGD6xyPLKqqvn6hBW7PrEq8wXtTuYhYUWbxsAxXG0Pi16bFMVSk1PgCeAEngYTIjBMZgjXrSE4Xu2ReC4Oo7PdjUj5WDxJxOl2WS_9n2y51e_hOLifBr_tfmnEf9L3T_N_yQYY4zj-jQ0AYIytJE7XNrirGfJWDZcfQaYbmo6NOxe7bt7QO0ocPzluezc3bBjm_6oN4VMjBrxHI_ID4PTBQxt4iymrMPgasSQbJlp8FHKyMSc46OP4o6dCfb7hqdFEN5offBTKyq_56OO2l3wl-2dWmktWvs8yOGK48qYO67ot62lV1VJxxGBst9nMf9tBCygl1D3zsho0qAqYeX9j78CnWKclcxK09NBKGM0yGbKXzFkTHvONcuH57sZQL28A3gK3xvdWh5yLYhDsyfp6GE3sED3vREHFkR7ZThbxgWQZzbI42zWFrEqRseMhz_NcVHGaJKKklGCKGePiyHaqIJgk-BjnOI2zNNvHLKZlJnhcHQ88yWKUYNkypfdaX9q97eudcm6QRYyPOD_sNCuldtP7DyFGvsEURYSMr0N9MRZF5VA7lGCtnHcLjFdey-LH__-6n0a3E-urb0C3I2c39LpovO9GEyByRuRcK98M5Z7bFpHzOOX8EXW9_SW5R-Q8EXWInOeVXArybwAAAP__6zKcog">