<p dir="ltr">If someone could pacify the overzealous lint check that doesn't run on Windows, I'd appreciate it, I'm on a train. Thanks!</p>
<p dir="ltr">Sent from phone</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Nov 8, 2016 4:06 PM, "Juergen Ributzka" <<a href="mailto:juergen@ributzka.de">juergen@ributzka.de</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Reid,<div><br></div><div>could you please take a look at this bot: <span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"> </span><font color="#136cb2" face="Segoe UI, Segoe UI Web Regular, Segoe UI Symbol, Lato, Helvetica Neue, Helvetica, Arial, sans-serif" size="2"><span><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:<wbr>8080/green/job/clang-stage2-<wbr>configure-Rlto_check/9576/<wbr>consoleFull#-15796076f80f5c9c-<wbr>2aaa-47fb-b15d-be39b7128d72</a></span></font><font face="Segoe UI, Segoe UI Web Regular, Segoe UI Symbol, Lato, Helvetica Neue, Helvetica, Arial, sans-serif" size="2"><span style="background-color:rgb(255,255,255)"> ?</span></font></div><div><font face="Segoe UI, Segoe UI Web Regular, Segoe UI Symbol, Lato, Helvetica Neue, Helvetica, Arial, sans-serif" size="2"><span style="background-color:rgb(255,255,255)"><br></span></font></div><div><span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">This is failing the SanitizerLintCheck.</span></div><div><span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></span></div><div><span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Thanks</span></div><div><span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></span></div><div><span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Cheers,</span></div><div><span style="font-family:'Segoe UI','Segoe UI Web Regular','Segoe UI Symbol',Lato,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Juergen</span></div><div><font face="Segoe UI, Segoe UI Web Regular, Segoe UI Symbol, Lato, Helvetica Neue, Helvetica, Arial, sans-serif" size="2"><span style="background-color:rgb(255,255,255)"><br></span></font><div><blockquote type="cite"><div>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:</div><br class="m_4722383420627854013Apple-interchange-newline"><div><div>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-<wbr>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/<wbr>search/?q=CRT.XL&sq=package:<wbr>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/<wbr>D26404</a><br><br>Added:<br>    compiler-rt/trunk/test/<wbr>asan/TestCases/Windows/tls_<wbr>init.cc<br>Modified:<br>    compiler-rt/trunk/lib/asan/<wbr>asan_win.cc<br>    compiler-rt/trunk/lib/asan/<wbr>asan_win_dll_thunk.cc<br>    compiler-rt/trunk/lib/asan/<wbr>asan_win_dynamic_runtime_<wbr>thunk.cc<br><br>Modified: compiler-rt/trunk/lib/asan/<wbr>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-<wbr>project/compiler-rt/trunk/lib/<wbr>asan/asan_win.cc?rev=286290&<wbr>r1=286289&r2=286290&view=diff</a><br>==============================<wbr>==============================<wbr>==================<br>--- compiler-rt/trunk/lib/asan/<wbr>asan_win.cc (original)<br>+++ compiler-rt/trunk/lib/asan/<wbr>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$<wbr>XCAB"))<br>-    int (*__intercept_seh)() = __asan_set_seh_filter;<br>+__declspec(allocate(".CRT$<wbr>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$<wbr>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/<wbr>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-<wbr>project/compiler-rt/trunk/lib/<wbr>asan/asan_win_dll_thunk.cc?<wbr>rev=286290&r1=286289&r2=<wbr>286290&view=diff</a><br>==============================<wbr>==============================<wbr>==================<br>--- compiler-rt/trunk/lib/asan/<wbr>asan_win_dll_thunk.cc (original)<br>+++ compiler-rt/trunk/lib/asan/<wbr>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"<wbr>)) 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>+                               <wbr>    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$<wbr>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/<wbr>asan_win_dynamic_runtime_<wbr>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-<wbr>project/compiler-rt/trunk/lib/<wbr>asan/asan_win_dynamic_runtime_<wbr>thunk.cc?rev=286290&r1=286289&<wbr>r2=286290&view=diff</a><br>==============================<wbr>==============================<wbr>==================<br>--- compiler-rt/trunk/lib/asan/<wbr>asan_win_dynamic_runtime_<wbr>thunk.cc (original)<br>+++ compiler-rt/trunk/lib/asan/<wbr>asan_win_dynamic_runtime_<wbr>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> //////////////////////////////<wbr>//////////////////////////////<wbr>////////////////////<br> // Define a copy of __asan_option_detect_stack_<wbr>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$<wbr>XIB"))<br>-int (*__asan_initialize_cloned_<wbr>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$<wbr>XIB")) int (*__asan_initialize_cloned_<wbr>variables)() =<br>+    InitializeClonedVariables;<br>+__declspec(allocate(".CRT$<wbr>XLAB")) void (NTAPI *__asan_tls_init)(<br>+    void *, unsigned long, void *) = asan_thread_init;<br><br> //////////////////////////////<wbr>//////////////////////////////<wbr>////////////////////<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/<wbr>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-<wbr>project/compiler-rt/trunk/<wbr>test/asan/TestCases/Windows/<wbr>tls_init.cc?rev=286290&view=<wbr>auto</a><br>==============================<wbr>==============================<wbr>==================<br>--- compiler-rt/trunk/test/asan/<wbr>TestCases/Windows/tls_init.cc (added)<br>+++ compiler-rt/trunk/test/asan/<wbr>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_<wbr>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_<wbr>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>______________________________<wbr>_________________<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/<wbr>mailman/listinfo/llvm-commits</a><br></div></div></blockquote></div><br></div></div></blockquote></div></div>