google / bloaty

Bloaty: a size profiler for binaries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DWARF > 3 seems to misattribute symbols to wrong compile units

brianosman opened this issue · comments

I've been trying to do some size profiling recently, and I was getting lots of symbols attributed to surprising compile units (when running with -d compileunits,symbols).

I built a trivial test application, and I see the same behavior. It looks like it's down to the version of DWARF data:
https://gist.github.com/brianosman/e2a37f5a9b5f8a47fd42a80fe35fc36e

Building that with clang -gdwarf-3 main.cpp other.cpp produces reasonable output. (main is attributed to main.cpp, Foo's functions are attributed to other.cpp). With -gdwarf-4 or -gdwarf-5, all of Foo's functions are attributed to main.cpp, and main is just attributed to the text section, but with no compileunit. I've got the output of bloaty with each version of DWARF info: https://gist.github.com/brianosman/c461911d99d77c4117c2a10b2ea4d42e

Is this expected? Is there some other tweak to the debug information flags that will help?

Thanks for the excellent small repro! This is a bug, Bloaty was seeing the declaration in the header file and counting it against the first compileunit where that declaration was included.

I have a fix in #268