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

    <tr>
        <th>Summary</th>
        <td>
            Semantic difference for option -fno-zero-initialized-in-bss between gcc and clang
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dustanddreams
      </td>
    </tr>
</table>

<pre>
    When the `-fzero-initialized-in-bss` option was introduced in gcc 3.x,
it would only affect global variables with an explicit initializer turning out
to be equivalent to the zero initialization (C11 6.7.9#10).

Its current implementation (at least in clang 16) makes the decision at a very
low level place in the llvm stack, and affects global variables with an
initializer turning out to be equivalent to zero initialization. However, at
this state, every global variable has been given an initializer, regardless of
the presence of an explicit initialization or not.

This has the consequence that the negative option,
`-fno-zero-initialized-in-bss`, causes all global variables which would be
initialized with zero to be put in the data section with an explicit zero
initializer, and nothing ends up in bss anymore.

Consider the following example:
```
int bss_variable;
int zero_variable = 0;
int nonzero_variable = 42;
```

when compiling this with `gcc -fno-zero-initialized-in-bss`:
- `bss_variable` end up in bss.
- `zero_variable` and `nonzero_variable` end up in data.

when compiling this with `clang -fno-zero-initialized-in-bss`:
- all three variables end up in data.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVV2vozYQ_TXOyygIDCHJAw-7dxW1z63Ux8rYA7hrbNYekpv99ZVNPm6y2XaliEh45syZM4exCEH3FrFhm89s82UlZhqcb9QcSFilPIoxrFqnzs1fA1qgAYHV-br7jt6ttdWkhdHfUa21XbchsDoHN5F2Fk4igLbknZolKtAWeimhzN4Zf2P5F5Z_0gQnNxsFzpoziK5DSdAb1woDR-G1aA0GOGkaQFjA98loqQnuVT3Q7K22PbiZFkxy0CLgt1kfhUFLQC6RjnzvmSIxZHz3VhRQZ9tsz3hZ5IzvswVmef5OAeTsfcTR42RwREu3XEFgUIRICKQRtoeiZnwPo_iKIRVVKHWI0YJAwBH9ecE17gQGj2hgMkJiBIjhxhxHCCTkV8bfQFh10ST8VJSLjq8FgVdavNAhg9_cCY_oU9WrjoMOkQthfBtPz88sYBABWkQLvT6ijTP6wCSmeeyFVwZDANddcREmjwGtRHDd68EuEjsP1tHDQP6MrGLZCCOdDfhtTkg0CEovLfaC9BEvLrx5LZnWuvXPfRsJSzEHDCCMeSH5oOVwMWyLz8qrZSRJ3kX3aabrYJUgAQHl8l08-znm_DDIqwOsoyHOE60KME8RsQ0BhD2PzuODOG_OBq2iBwaEzhnjTinzXUTrsvLTTYnL71KTIuLf10ZZ-fl-EKndToCVXyB_OLfO_hhS8VvMU63leYqLRLpx0ibyS05LorA6jyvi_-Z0bWQdEx6o13nU6S5T9iHwgWeMjOqyOn9u4REkTi77VfLLEvh1-tFmNHjEDy57WXqlmlLty71YYVNs82K3qzZ1tRqaVhYVb9Wu2vBN2_GiKrloN2213W15u93lK93wnJcFz-tiW_GqyvJainyzKZQqc4l7zqocR6FNFpdP5ny_0iHM2GyruuQrI1o0Id0NnKf2GOfxmvBNjF-3cx9YlRsdKNwRSJPB5g8chSUtQemuQ58-08756_XwXzJBi3RKi0XKNKdUejV70wxEU4ga8gPjh17TMLeZdCPjh1j_8reevPsHJTF-SO0Exg-po38DAAD__zvnUd4">