New issue
Advanced search Search tips

Issue 636398 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Mar 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 1
Type: Feature

Blocking:
issue 636399



Sign in to add a comment

mini_installer with asan is broken due to missing dependencies

Project Member Reported by etienneb@chromium.org, Aug 10 2016

Issue description

The mini_installer cannot be ASAN-instrumented on windows.
The ASAN libraries are bringing some dependencies that are missing.

Related to:
https://bugs.chromium.org/p/chromium/issues/detail?id=598761

With this config:
---
target_cpu = "x86"
is_debug = false
is_asan = true
is_clang = true
---

Output:
---
D:\src\chromium\src>ninja -j1 -C out\asan
ninja: Entering directory `out\asan'
[1/1] Regenerating ninja files
[1/10198] LINK mini_installer.exe mini_installer.exe.pdb
FAILED: mini_installer.exe mini_installer.exe.pdb
D:/src/depot_tools/python276_bin/python.exe gyp-win-tool link-wrapper environment.x86 False link.exe /nologo /OUT:./mini
_installer.exe /PDB:./mini_installer.exe.pdb @./mini_installer.exe.rsp
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strlen referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strnlen referenced in func
tion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strcmp referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strncmp referenced in func
tion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strstr referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strchr referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strrchr referenced in func
tion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strspn referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strcspn referenced in func
tion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strpbrk referenced in func
tion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _memcmp referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _memchr referenced in funct
ion "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _frexp referenced in functi
on "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _longjmp referenced in func
 

Comment 1 by r...@chromium.org, Aug 10 2016

I can confirm this fails locally for me for the same reasons:
[50/50] LINK mini_installer.exe mini_installer.exe.pdb
FAILED: mini_installer.exe mini_installer.exe.pdb
C:/python_27_amd64/files/python.exe gyp-win-tool link-wrapper environment.x86 False link.exe /nologo /OUT:./mini_installer.exe /PDB:./mini_installer.exe.pdb @./mini_installer.exe.rsp
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strlen referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strnlen referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strcmp referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strncmp referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strstr referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strchr referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strrchr referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strspn referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strcspn referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _strpbrk referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _memcmp referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)
clang_rt.asan-i386.lib(asan_interceptors.cc.obj) : error LNK2019: unresolved external symbol _memchr referenced in function "void __cdecl InitializeCommonInterceptors(void)" (?InitializeCommonInterceptors@@YAXXZ)

Comment 2 by thakis@chromium.org, Aug 22 2016

Blocking: 636399

Comment 3 by thakis@chromium.org, Aug 22 2016

These 4 targets don't link locally, with missing symbols that should come from the CRT:

  remoting_host, remoting_console, remoting_desktop, mini_installer


They all use /ENTRY: in ldflags to set a custom entry point. I guess /ENTRY: disables some linker magic that normally pulls in the right crt? Normally /MD or similary puts a .drectve section with /DEFAULTLIB:msvcrt.lib in each .obj file, but maybe /ENTRY makes link.exe ignore that?

Comment 4 by thakis@chromium.org, Aug 22 2016

C:\src\chrome\src>type test.cc
#include <stdlib.h>
int main() { malloc(4);return 4; }

C:\src\chrome\src>cl /c test.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23918 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cc

C:\src\chrome\src>link test.obj
Microsoft (R) Incremental Linker Version 14.00.23918.0
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\src\chrome\src>link test.obj  /ENTRY:main libcmt.lib
Microsoft (R) Incremental Linker Version 14.00.23918.0
Copyright (C) Microsoft Corporation.  All rights reserved.

test.obj : error LNK2019: unresolved external symbol _malloc referenced in function _main
test.exe : fatal error LNK1120: 1 unresolved externals

Comment 5 by thakis@chromium.org, Aug 22 2016

Err, last bit was supposed to say:

C:\src\chrome\src>link test.obj  /ENTRY:main
Microsoft (R) Incremental Linker Version 14.00.23918.0
Copyright (C) Microsoft Corporation.  All rights reserved.

test.obj : error LNK2019: unresolved external symbol _malloc referenced in function _main
test.exe : fatal error LNK1120: 1 unresolved externals

Comment 6 by r...@chromium.org, Aug 25 2016

So, do you think the solution is to add '#pragma comment(lib, "msvcrt")' to asan?

Comment 7 by thakis@chromium.org, Aug 25 2016

I'm not sure does that do the right thing when the client program is built with all of /MT /MD etc?

Also, does mainCRTStartup do crt initialization that's missing if we go through a different entry point?

Comment 8 by r...@chromium.org, Aug 25 2016

I think we have defines in ASan that tell us whether we expect to use this variant of the ASan runtime with /MT or /MD.

Comment 9 by thakis@chromium.org, Aug 25 2016

What about initialization?
Cc: chrisha@chromium.org
As pointed out by Nico on #9, there is an issue with the initialization.

Here is an example:

[host.cc]
  int *p = 0;

  int main() {
    *p = 42;
    return 0;
  }

  int Entry() {
    *p = 42;
    return 0;
  }

Compiled with:
  % clang-cl.exe host.cc /c

Linked and executed with:
  % link.exe host.obj
  % link.exe host.obj /ENTRY:HostEntryPoint

As expected, both executable are crashing.


Compiled with: (adding sanitizer)
  % clang-cl.exe host.cc /c -fsanitize=address

Linked with:
  % link.exe host.obj ..\ninja\lib\clang\4.0.0\lib\windows\clang_rt.asan-i386.lib

The error is correctly detected:
=================================================================
==9800==ERROR: AddressSanitizer: access-violation on unknown address 0x00000000 (pc 0x011d1052 bp 0x003afb58 sp 0x003afb
48 T0)
==9800==The signal is caused by a WRITE memory access.
==9800==Hint: address points to the zero page.
    #0 0x11d1051  (D:\src\llvm\examples\host.exe+0x401051)
    #1 0x11f5029 in _sanitizer_print_stack_trace+0x91c9 (D:\src\llvm\examples\host.exe+0x425029)
    #2 0x77403369 in BaseThreadInitThunk+0x11 (C:\Windows\syswow64\kernel32.dll+0x7dd73369)
    #3 0x77939901 in RtlInitializeExceptionChain+0x62 (C:\Windows\SysWOW64\ntdll.dll+0x7dea9901)
    #4 0x779398d4 in RtlInitializeExceptionChain+0x35 (C:\Windows\SysWOW64\ntdll.dll+0x7dea98d4)


BUT, when linked with the /ENTRY switch

  % link.exe host.obj ..\ninja\lib\clang\4.0.0\lib\windows\clang_rt.asan_dynamic-i386.lib /ENTRY:Entry

  Microsoft (R) Incremental Linker Version 14.00.23506.0
  Copyright (C) Microsoft Corporation.  All rights reserved.

  host.obj : warning LNK4210: .CRT section exists; there may be unhandled   static initializers or terminators

**** The initializers are not executed! ****


I looked why this was not an issue with the chromium targets (i.e. remoting_console.exe). The target is loading an instrumentd DLL which is calling __asan_init (redirected to the main executable) on load time, before the ENTRY point is reached.


I've made an alternative fix for the same bug (still few things to fix).
But the idea is to avoid the 'code size' optimisation (using /ENTRY:) for these executables.

  see: https://codereview.chromium.org/2621223003/

This is fixing the initializers issue. But, the intrumented executable are slighty different because they are now linking with the CRT.
Status: Fixed (was: Assigned)

Sign in to add a comment