[cfe-dev] Underscores/mangling symbol names

Rui Ueyama ruiu at google.com
Mon Dec 23 21:14:17 PST 2013

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

C:\> dumpbin /headers "C:\Program Files (x86)\Microsoft Visual Studio

  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

(Because I'm using MSVC 2013, the library's version number is 130, but it's
not important.)

As you can see, the symbol defined by MSVCRT.LIB is _printf, so undefined
symbol _printf will be resolved with this library. The symbol name used by
the static linker does not have to be the same as the name used by the
dynamic linker. When the (static) linker creates the import table entry for
_printf in the executable, it mangled the name as specified by "Name type"
field. It's "no prefix" in this case, which make the linker to strip the
beginning underscore.

On Sun, Dec 22, 2013 at 8:22 PM, Astron B <boldaster at gmail.com> wrote:

> Hi.
> 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
> _printf
> 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?
> Thanks.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131224/7749810b/attachment.html>

More information about the cfe-dev mailing list