On 08/11/16 11:46, Jonathan Wakely wrote: > On 7 November 2016 at 23:36, John Steele Scott <toojays@xxxxxxxxxxx> wrote: >> 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 was going to suggest that this is almost certainly due to additional > declarations in the headers with C++14 is used, not a difference in > dwarf output caused by the -std options. > >> 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. > > There might be some reason the debuginfo is useful in that case, but I > suggest opening a bug report so it can be assessed properly. Thanks. > Thanks Jonathan. I filed <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78247>. Cheers, John