This is an archive of the discontinued LLVM Phabricator instance.

Pass only mangled function names to __cxa_demangle
ClosedPublic

Authored by emaste on Jan 15 2014, 4:48 AM.

Details

Reviewers
samsonov
Group Reviewers
deleted
Summary

The Itanium C++ ABI states the string passed to __cxa_demnagle "may be either an external name, i.e. with a "_Z" prefix, or an internal NTBS mangling, e.g. of a type for type_info."

llvm-symbolizer passes all names to cxa_demangle, which fails for many names on FreeBSD. Our cxa_demangle is currently not very strict about rejecting invalid names, and returns "unsigned int" for a function "main". On other platforms I believe llvm-symbolizer would produce incorrect output for functions with the same name as a mangled type - for example, returning "float" for a function "f".

This change checks that the name starts with the _Z prefix before passing it to __cxa_demangle.

http://llvm.org/pr18431

Diff Detail

Event Timeline

emaste updated this revision to Unknown Object (????).Jan 15 2014, 3:10 PM

I missed that the _Z heuristic already exists, but was applied to global data only. Move the heuristic into DemangleName so that it is applied to function names too.

Add a new .c test specifically for llvm-symbolizer. I was going to modify dwarfdump-test.cc to make function f() extern "C", but don't want to have to deal with the binary objects that were already generated from it.

samsonov accepted this revision.Jan 16 2014, 1:43 AM

LGTM (modulo comment below).

test/DebugInfo/Inputs/llvm-symbolizer-test.c
14 ↗(On Diff #6478)

Update the build instructions.

emaste closed this revision.Jan 16 2014, 10:37 AM

Committed as r199404