The issue seems to be that clang and g++ use different rules for assigning
line numbers to functions. It seems like g++ uses the first
line of the signature (excluding template<...>) and clang uses the line
with the opening '{'. This is a problem because g++ was used to compile
libstdc++.so and clang was used to compile our .o's. This seems to only happen in --opt=off builds because clang inlines these functions otherwise.
Example errors:
/usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:4931 from build/ninja/mongo/libbase.a(build/ninja/mongo/logger/rotatable_file_manager.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:4929 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.tcc:1149 from build/ninja/mongo/client/libclientdriver.a(build/ninja/mongo/client/connection_string_connect.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:1147 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char*, void>(char*, char*, std::allocator<char> const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:552 from build/ninja/mongo/db/catalog/libcatalog.a(build/ninja/mongo/db/catalog/index_catalog.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:549 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.tcc:1164 from build/ninja/mongo/db/pipeline/libdocument_source.a(build/ninja/mongo/db/pipeline/document_source_unwind.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:1163 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, void>(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<char> const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:552 from build/ninja/mongo/db/repl/libisself.a(build/ninja/mongo/db/repl/isself.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:549 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::forward_iterator_tag)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.tcc:209 from build/ninja/mongo/db/repl/libisself.a(build/ninja/mongo/db/repl/isself.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:206 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char const*, void>(char const*, char const*, std::allocator<char> const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:552 from build/ninja/mongo/client/libsasl_client.a(build/ninja/mongo/client/sasl_client_authenticate.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:549 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::forward_iterator_tag)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.tcc:209 from build/ninja/mongo/client/libclientdriver.a(build/ninja/mongo/client/mongo_uri_connect.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:206 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so /usr/bin/ld.gold: warning: while linking build/ninja/mongo/mongod: symbol 'std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string<wchar_t const*, void>(wchar_t const*, wchar_t const*, std::allocator<wchar_t> const&)' defined in multiple places (possible ODR violation): /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../include/c++/6.3.1/bits/basic_string.h:552 from build/ninja/third_party/boost-1.60.0/libboost_regex.a(build/ninja/third_party/boost-1.60.0/libs/regex/src/wc_regex_traits.o) /build/gcc-multilib/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/basic_string.h:549 from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1/../../../../lib64/libstdc++.so