<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang-cl and msvc-cl disagree about static initialization"
   href="https://llvm.org/bugs/show_bug.cgi?id=26210">26210</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-cl and msvc-cl disagree about static initialization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jmuizelaar@mozilla.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When compiling a function like this:
inline const T *Ops() {
    static int k;
    static const T sOps = true ? 0 : &k;
    return &sOps;
}

msvc puts sOps in a read-write section, while clang puts sOps in a read-only
section. If the code for Ops() is not included in the object file from clang,
the linker can pick the read-only sOps from clang and Ops() implementation from
msvc. When the msvc Ops() runs it will crash trying to write to sOps.

I've put up a repo that reproduces this issue here:
<a href="https://github.com/jrmuizel/read-only-symbol-crash/">https://github.com/jrmuizel/read-only-symbol-crash/</a>

We're currently trying to bisect some clang related compilation issues and this
is preventing us from linking object files from clang and cl together. I
suspect using the clang front end on top of cl2 backend will also suffer from
this interoperability issue.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>