Underscores/mangling symbol names


I compiled some simple code using clang that prints to console using printf. When I check the name of the symbols in the compiled object file I find


I’m wondering why the name appears to be mangled when the printf function in msvcr110.dll is simply “printf.” How does the linker match up these symbols correctly?


Yes, the linker matches up these symbols. The linker uses an import library to look up symbols exported by a DLL. MSVCR*.DLL’s export library is MSVCRT.lib. You can see the contents of the import library using dumpbin command.

C:> dumpbin /headers “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\MSVCRT.lib”

Version : 0
Machine : 14C (x86)
TimeDateStamp: 524F7A25 Sat Oct 05 11:32:05 2013
SizeOfData : 00000015
DLL name : MSVCR120.dll
Symbol name : _printf
Type : code
Name type : no prefix
Hint : 1789
Name : printf