<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Compiling fmt on Win64 with -fsanitize=address and -D_DLL crashes with sectionless symbol error"
   href="https://bugs.llvm.org/show_bug.cgi?id=47950">47950</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compiling fmt on Win64 with -fsanitize=address and -D_DLL crashes with sectionless symbol error
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nyanpasu64@tuta.io
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24094" name="attach_24094" title="Minimal reproducing test case, expanded, and bitcode">attachment 24094</a> <a href="attachment.cgi?id=24094&action=edit" title="Minimal reproducing test case, expanded, and bitcode">[details]</a></span>
Minimal reproducing test case, expanded, and bitcode

I'm running Windows 10 x64, and Clang 10 and 11 x64, using headers from MSVC.
When I try building fmt with -fsanitize=address enabled, Clang crashes with an
internal error.

C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -DFMT_LOCALE
-IC:/Users/nyanpasu/code/fmt/include -fsanitize=address -g -Xclang -gcodeview
-O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++14 -MD -MT
CMakeFiles/fmt.dir/src/format.cc.obj -MF CMakeFiles\fmt.dir\src\format.cc.obj.d
-o CMakeFiles/fmt.dir/src/format.cc.obj -c
C:/Users/nyanpasu/code/fmt/src/format.cc
fatal error: error in backend: cannot make section .ASAN$GL associative with
sectionless symbol ?id@?$numpunct@_W@std@@2V0locale@2@A
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -DFMT_LOCALE
-IC:/Users/nyanpasu/code/fmt/include -fsanitize=address -g -Xclang -gcodeview
-O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++14 -MD -MT
CMakeFiles/fmt.dir/src/format.cc.obj -MF CMakeFiles\fmt.dir\src\format.cc.obj.d
-o CMakeFiles/fmt.dir/src/format.cc.obj -c
C:/Users/nyanpasu/code/fmt/src/format.cc 
1.      <eof> parser at end of file
2.      Code generation
[truncated, see
<a href="https://gist.github.com/nyanpasu64/a80e00abf37e0fc1236d6ca3caff766d/raw/3feb42e9f024a10fd0a4e6b4c82269ccaa95d90c/10clang">https://gist.github.com/nyanpasu64/a80e00abf37e0fc1236d6ca3caff766d/raw/3feb42e9f024a10fd0a4e6b4c82269ccaa95d90c/10clang</a>
]


When I run `llc foo.bc`, I get the following:

Declaration may not be in a Comdat!
{ %"class.std::locale::id", [56 x i8] }*
@"?id@?$numpunct@_W@std@@2V0locale@2@A"
Declaration may not be in a Comdat!
{ %"class.std::locale::id", [56 x i8] }* @"?id@?$numpunct@D@std@@2V0locale@2@A"
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments: llc foo.bc
[truncated, see
<a href="https://gist.github.com/nyanpasu64/a80e00abf37e0fc1236d6ca3caff766d/raw/3feb42e9f024a10fd0a4e6b4c82269ccaa95d90c/20llc">https://gist.github.com/nyanpasu64/a80e00abf37e0fc1236d6ca3caff766d/raw/3feb42e9f024a10fd0a4e6b4c82269ccaa95d90c/20llc</a>
]

I get basically the same error when run `bugpoint -run-llc foo.bc` which is
intended to minimize the test case. I haven't had much luck with manually
minimizing it.

## Minimal reproducer (attachment format.cc)

#include <locale>

void grouping_impl() {
  std::use_facet<std::numpunct<char>>(std::locale());
}

Compile with `clang -fsanitize=address -D_DLL -std=c++14 -c format.cc`. There
is no crash if you do not pass in both -fsanitize=address and -D_DLL. And
MSVC's <locale> does not compile in Clang's -std=c++11 mode.

Running with -E expands to the 38,809 line, 1.3 MB abomination (attachment
preprocessed.cpp).

Running with `-emit-llvm -c -o foo.bc` produces attachment foo.bc. Trying to
run `llc foo.bc` (with any relocation model) produces error:

Declaration may not be in a Comdat!
{ %"class.std::locale::id", [56 x i8] }* @"?id@?$numpunct@D@std@@2V0locale@2@A"
llc.exe: foo.bc: error: input module is broken!

## Versions

OS: Windows 10 x64
LLVM/Clang: both 10.0.0 (old) and 11.0.0 (very recent), using MSVC headers/ABI
MSVC headers: latest v14.27 (Clang uses header C:\Program Files (x86)\Microsoft
Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\locale) 
fmt: latest 7.0.3
(<a href="https://github.com/fmtlib/fmt/releases/download/7.0.3/fmt-7.0.3.zip">https://github.com/fmtlib/fmt/releases/download/7.0.3/fmt-7.0.3.zip</a>) and
earlier versions, but see minimal reproducer</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>