title: Problems linking msvc intrinsics using clang on windows
body: <p>I'm swapping over a large codebase from using msvc to clang for a windows product.  This product uses a large number of the msvc compiler intrinsics such as _InterlockedOr etc.  If I build a little test program using clang on windows it builds, links and runs just fine, but if I build a library from our product that uses an intrinsics it comes up as a missing symbol.</p>
  
  <p>I've tried compiling both the test code and our product using the --verbose option and can't spot anything different between the two. The only difference in the way they are called is that the large product is built using fastbuild which necessitates the use of -c to prevent the compiler calling the linker as well.   Clang obviously adds in some libraries that are missing when I call the linker manually myself, so can anybody let me know what they might be?  (I'm already linking in the crt library (libcmt, msvcrt) so it's not that.</p>
  
  <p>I've started writing my own library of intrinsics in assembly which is fun, but shouldn't be necessary.  Any one?</p>
  
  <p>As per request, compiling the following code with clang works when using it directly, i.e. <code>clang IntrinsicsTest.cpp</code>produces an exe.</p>
  
  <pre><code>IntrinsicsTest.cpp
  #include "stdio.h"
  #include "intrin.h"
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      unsigned long long r = __rdtsc();
      printf("Intrinsic: %llu\n", r);
  }
  </code></pre>
  
  <p>Yet fails to link when called via fastbuild:
  <code>FBuild.exe -showcmds -clean IntrinsicsTest_debug_x86</code></p>
  
  <blockquote>
    <p>clang.exe "\IntrinsicsTest.cpp" -D_WINDOWS -c -m32 -mfpmath=sse -D_UNICODE -DUNICODE -fno-rtti -fexceptions -E ...\IntrinsicsTest.debug.Win32.lib</p>
    
    <p>lib.exe /NOLOGO /OUT:"...\IntrinsicsTest.debug.Win32.lib" "...\IntrinsicsTest.obj" ...\IntrinsicsTest.debug.Win32.exe</p>
    
    <p>link.exe /NOLOGO /INCREMENTAL:NO /OUT:"...\IntrinsicsTest.debug.Win32.exe" "...\IntrinsicsTest.obj" -defaultlib:libcmt.lib -INCREMENTAL -MANIFEST /MACHINE:X86 /SUBSYSTEM:CONSOLE /OPT:NOICF /OPT:NOREF </p>
    
    <p>IntrinsicsTest.obj : error LNK2019: unresolved external symbol ___rdtsc referenced in function
    _wmain ...\IntrinsicsTest.debug.Win32.exe</p>
    
    <p>fatal error LNK1120: 1 unresolved externals</p>
  </blockquote>