<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.E-MailFormatvorlage18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I should have fixed this in r286346. Let’s see if the bots go green again.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Jonas<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> llvm-commits [mailto:llvm-commits-bounces@lists.llvm.org] <b>On Behalf Of </b>Renato Golin via llvm-commits<br><b>Sent:</b> Wednesday, November 09, 2016 3:19 AM<br><b>To:</b> Reid Kleckner<br><b>Cc:</b> LLVM Commits<br><b>Subject:</b> Re: [compiler-rt] r286290 - [asan/win] Add init hooks to .CRT$XLAB<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p>Can someone revert? It's breaking both Aarch64 bots:<o:p></o:p></p><p><a href="http://lab.llvm.org:8011/builders/clang-cmake-aarch64-39vma/builds/391">http://lab.llvm.org:8011/builders/clang-cmake-aarch64-39vma/builds/391</a><o:p></o:p></p><p>Cheers, <br>Renato<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On 9 Nov 2016 01:27, "Reid Kleckner via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p><p>If someone could pacify the overzealous lint check that doesn't run on Windows, I'd appreciate it, I'm on a train. Thanks!<o:p></o:p></p><p>Sent from phone<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Nov 8, 2016 4:06 PM, "Juergen Ributzka" <<a href="mailto:juergen@ributzka.de" target="_blank">juergen@ributzka.de</a>> wrote:<o:p></o:p></p><div><p class=MsoNormal>Hi Reid,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>could you please take a look at this bot: <span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";background:white'> </span><span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";color:#136CB2'><a href="http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/9576/consoleFull#-15796076f80f5c9c-2aaa-47fb-b15d-be39b7128d72" target="_blank">http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/9576/consoleFull#-15796076f80f5c9c-2aaa-47fb-b15d-be39b7128d72</a></span><span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";background:white'> ?</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";background:white'>This is failing the SanitizerLintCheck.</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";background:white'>Thanks</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";background:white'>Cheers,</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Segoe UI","sans-serif";background:white'>Juergen</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On Nov 8, 2016, at 12:45 PM, Reid Kleckner via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Author: rnk<br>Date: Tue Nov  8 14:45:45 2016<br>New Revision: 286290<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=286290&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=286290&view=rev</a><br>Log:<br>[asan/win] Add init hooks to .CRT$XLAB<br><br>Summary:<br>User applications may register hooks in the .CRT$XL* callback list,<br>which is called very early by the loader. This is very common in<br>Chromium:<br><a href="https://cs.chromium.org/search/?q=CRT.XL&sq=package:chromium&type=cs" target="_blank">https://cs.chromium.org/search/?q=CRT.XL&sq=package:chromium&type=cs</a><br><br>This has flown under the radar for a long time because the loader<br>appears to catch exceptions originating from these callbacks. It's a<br>real problem when you're debugging an asan application, though, since it<br>makes the program crash early.<br><br>The solution is to add our own callback to this list, and sort it very<br>early in the list like we do elsewhere. Also add a test with such an<br>instrumented callback, and test that it gets called with asan.<br><br>Reviewers: etienneb<br><br>Subscribers: llvm-commits, kubabrecka<br><br>Differential Revision: <a href="https://reviews.llvm.org/D26404" target="_blank">https://reviews.llvm.org/D26404</a><br><br>Added:<br>   compiler-rt/trunk/test/asan/TestCases/Windows/tls_init.cc<br>Modified:<br>   compiler-rt/trunk/lib/asan/asan_win.cc<br>   compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc<br>   compiler-rt/trunk/lib/asan/asan_win_dynamic_runtime_thunk.cc<br><br>Modified: compiler-rt/trunk/lib/asan/asan_win.cc<br>URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=286290&r1=286289&r2=286290&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=286290&r1=286289&r2=286290&view=diff</a><br>==============================================================================<br>--- compiler-rt/trunk/lib/asan/asan_win.cc (original)<br>+++ compiler-rt/trunk/lib/asan/asan_win.cc Tue Nov  8 14:45:45 2016<br>@@ -343,9 +343,23 @@ int __asan_set_seh_filter() {<br>// immediately after the CRT runs. This way, our exception filter is called<br>// first and we can delegate to their filter if appropriate.<br>#pragma section(".CRT$XCAB", long, read)  // NOLINT<br>-__declspec(allocate(".CRT$XCAB"))<br>-    int (*__intercept_seh)() = __asan_set_seh_filter;<br>+__declspec(allocate(".CRT$XCAB")) int (*__intercept_seh)() =<br>+    __asan_set_seh_filter;<br>+<br>+// Piggyback on the TLS initialization callback directory to initialize asan as<br>+// early as possible. Initializers in .CRT$XL* are called directly by ntdll,<br>+// which run before the CRT. Users also add code to .CRT$XLC, so it's important<br>+// to run our initializers first.<br>+static void NTAPI asan_thread_init(void *module, DWORD reason, void *reserved) {<br>+  if (reason == DLL_PROCESS_ATTACH) __asan_init();<br>+}<br>+<br>+#pragma section(".CRT$XLAB", long, read)  // NOLINT<br>+__declspec(allocate(".CRT$XLAB")) void (NTAPI *__asan_tls_init)(<br>+    void *, unsigned long, void *) = asan_thread_init;<br>#endif<br>+<br>+<br>// }}}<br>}  // namespace __asan<br><br><br>Modified: compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc<br>URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc?rev=286290&r1=286289&r2=286290&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc?rev=286290&r1=286289&r2=286290&view=diff</a><br>==============================================================================<br>--- compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc (original)<br>+++ compiler-rt/trunk/lib/asan/asan_win_dll_thunk.cc Tue Nov  8 14:45:45 2016<br>@@ -456,4 +456,19 @@ static int call_asan_init() {<br>#pragma section(".CRT$XIB", long, read)  // NOLINT<br>__declspec(allocate(".CRT$XIB")) int (*__asan_preinit)() = call_asan_init;<br><br>+#ifdef _M_IX86<br>+#define NTAPI __stdcall<br>+#else<br>+#define NTAPI<br>+#endif<br>+<br>+static void NTAPI asan_thread_init(void *mod, unsigned long reason,<br>+                                   void *reserved) {<br>+  if (reason == /*DLL_PROCESS_ATTACH=*/1) __asan_init();<br>+}<br>+<br>+#pragma section(".CRT$XLAB", long, read)  // NOLINT<br>+__declspec(allocate(".CRT$XLAB")) void (NTAPI *__asan_tls_init)(<br>+    void *, unsigned long, void *) = asan_thread_init;<br>+<br>#endif // ASAN_DLL_THUNK<br><br>Modified: compiler-rt/trunk/lib/asan/asan_win_dynamic_runtime_thunk.cc<br>URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win_dynamic_runtime_thunk.cc?rev=286290&r1=286289&r2=286290&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win_dynamic_runtime_thunk.cc?rev=286290&r1=286289&r2=286290&view=diff</a><br>==============================================================================<br>--- compiler-rt/trunk/lib/asan/asan_win_dynamic_runtime_thunk.cc (original)<br>+++ compiler-rt/trunk/lib/asan/asan_win_dynamic_runtime_thunk.cc Tue Nov  8 14:45:45 2016<br>@@ -33,6 +33,7 @@<br>#pragma section(".CRT$XCAB", long, read)  // NOLINT<br>#pragma section(".CRT$XTW", long, read)  // NOLINT<br>#pragma section(".CRT$XTY", long, read)  // NOLINT<br>+#pragma section(".CRT$XLAB", long, read)  // NOLINT<br><br>////////////////////////////////////////////////////////////////////////////////<br>// Define a copy of __asan_option_detect_stack_use_after_return that should be<br>@@ -61,9 +62,17 @@ static int InitializeClonedVariables() {<br>  return 0;<br>}<br><br>-// Our cloned variables must be initialized before C/C++ constructors.<br>-__declspec(allocate(".CRT$XIB"))<br>-int (*__asan_initialize_cloned_variables)() = InitializeClonedVariables;<br>+static void NTAPI asan_thread_init(void *mod, unsigned long reason, void *reserved) {<br>+  if (reason == DLL_PROCESS_ATTACH) InitializeClonedVariables();<br>+}<br>+<br>+// Our cloned variables must be initialized before C/C++ constructors.  If TLS<br>+// is used, our .CRT$XLAB initializer will run first. If not, our .CRT$XIB<br>+// initializer is needed as a backup.<br>+__declspec(allocate(".CRT$XIB")) int (*__asan_initialize_cloned_variables)() =<br>+    InitializeClonedVariables;<br>+__declspec(allocate(".CRT$XLAB")) void (NTAPI *__asan_tls_init)(<br>+    void *, unsigned long, void *) = asan_thread_init;<br><br>////////////////////////////////////////////////////////////////////////////////<br>// For some reason, the MD CRT doesn't call the C/C++ terminators during on DLL<br><br>Added: compiler-rt/trunk/test/asan/TestCases/Windows/tls_init.cc<br>URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/tls_init.cc?rev=286290&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/tls_init.cc?rev=286290&view=auto</a><br>==============================================================================<br>--- compiler-rt/trunk/test/asan/TestCases/Windows/tls_init.cc (added)<br>+++ compiler-rt/trunk/test/asan/TestCases/Windows/tls_init.cc Tue Nov  8 14:45:45 2016<br>@@ -0,0 +1,51 @@<br>+// RUN: %clang_cl_asan %s -Fe%t.exe<br>+// RUN: %run %t.exe | FileCheck %s<br>+<br>+// CHECK: my_thread_callback<br>+// CHECK: ran_before_main: 1<br>+<br>+#include <windows.h><br>+#include <stdio.h><br>+#include <string.h><br>+<br>+#pragma comment (lib, "dbghelp")<br>+<br>+static bool ran_before_main = false;<br>+<br>+extern "C" void __asan_init(void);<br>+<br>+static void NTAPI /*__attribute__((no_sanitize_address))*/<br>+my_thread_callback(PVOID module, DWORD reason, PVOID reserved) {<br>+  ran_before_main = true;<br>+  static const char str[] = "my_thread_callback\n";<br>+<br>+  // Fail the test if we aren't called for the expected reason or we can't write<br>+  // stdout.<br>+  if (reason != DLL_PROCESS_ATTACH)<br>+    return;<br>+  HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);<br>+  if (!out || out == INVALID_HANDLE_VALUE)<br>+    return;<br>+<br>+  DWORD written = 0;<br>+  WriteFile(out, &str[0], sizeof(str), &written, NULL);<br>+}<br>+<br>+extern "C" {<br>+#pragma const_seg(".CRT$XLC")<br>+extern const PIMAGE_TLS_CALLBACK p_thread_callback;<br>+const PIMAGE_TLS_CALLBACK p_thread_callback = my_thread_callback;<br>+#pragma const_seg()<br>+}<br>+<br>+#ifdef _WIN64<br>+#pragma comment(linker, "/INCLUDE:_tls_used")<br>+#pragma comment(linker, "/INCLUDE:p_thread_callback")<br>+#else<br>+#pragma comment(linker, "/INCLUDE:__tls_used")<br>+#pragma comment(linker, "/INCLUDE:_p_thread_callback")<br>+#endif<br>+<br>+int main() {<br>+  printf("ran_before_main: %d\n", ran_before_main);<br>+}<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p></div></div></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p></div></div></div></div></body></html>