std=c++14 greatly increases debuginfo size. why?
John Steele Scott
toojays@toojays.net
Mon Nov 7 23:38:00 GMT 2016
On 04/11/16 22:32, John Steele Scott wrote:
> Hi,
>
> A colleague of mine noticed that switching from -std=c++11 to -std=c++14
> dramatically increased the size of our binary.
>
> After some investigation, this seems to be due to debuginfo.
>
> Consider the following simple example, compiled four different ways:
>
> jscott@citra:~/src/debuginfo-bloat$ cat simple.cpp
> #include <string>
>
> size_t length (const std::string &data)
> {
> size_t len = 0;
> for (auto iter = data.cbegin(); iter != data.cend(); iter++)
> {
> len++;
> }
>
> return len;
> }
> jscott@citra:~/src/debuginfo-bloat$ g++-6 -gdwarf-4 -std=c++11 -c simple.cpp -o simple-11.o
> jscott@citra:~/src/debuginfo-bloat$ g++-6 -gdwarf-4 -std=c++14 -c simple.cpp -o simple-14.o
> jscott@citra:~/src/debuginfo-bloat$ g++-6 -gdwarf-4 -std=c++11 -c simple.cpp -o simple-11-g1.o -g1
> jscott@citra:~/src/debuginfo-bloat$ g++-6 -gdwarf-4 -std=c++14 -c simple.cpp -o simple-14-g1.o -g1
> jscott@citra:~/src/debuginfo-bloat$ ls -l simple*o
> -rw-rw-r-- 1 jscott jscott 6904 Nov 4 22:25 simple-11-g1.o
> -rw-rw-r-- 1 jscott jscott 60192 Nov 4 22:25 simple-11.o
> -rw-rw-r-- 1 jscott jscott 6904 Nov 4 22:25 simple-14-g1.o
> -rw-rw-r-- 1 jscott jscott 129376 Nov 4 22:25 simple-14.o
>
>
> So with the default -g2, the C++14 output is almost double that of C++11. But
> with -g1 they are the same.
>
> Can someone tell me why this is so? Am I getting much better debuginfo for those
> bytes?
I did some further digging with dwarfdump, and the increase in this case is due
to std::literals::string_literals. If I ifdef those operators out (at the end of
basic_string.h), the C++11 and C++14 sizes are the same.
I guess these operators cause GCC to think that the wchar_t, char16_t, char32_t
versions of basic_string are used, and so it must emit debuginfo for them. But
I'm not using the operators, therefore these classes are not used.
Sounds like a GCC bug to me - it shouldn't emit debuginfo for types referenced
by an inline function if that function is never used.
Cheers,
John
More information about the Gcc-help
mailing list