[SERVER-19353] Compilation failure with GCC 5.1 Created: 10/Jul/15  Updated: 14/Apr/16  Resolved: 22/Sep/15

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alexander Gorrod Assignee: Alexander Gorrod
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

Install GCC 5.1 on Fedora 22.

$ git clone https://github.com/mongodb/mongo.git
$ cd mongo
$ scons mongod

Sprint: Platform 6 07/17/15
Participants:

 Description   

When I build with gcc 5.1 (default GCC on Fedora 22), I see warnings from the boost library.

My particular compiler version:

$ gcc --version
gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
$ g++ --version
g++ (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The build warnings are:

In file included from src/third_party/boost-1.56.0/boost/filesystem/path_traits.hpp:23:0,
                 from src/third_party/boost-1.56.0/boost/filesystem/path.hpp:25,
                 from src/third_party/boost-1.56.0/boost/filesystem/operations.hpp:25,
                 from src/mongo/db/db.cpp:35:
src/third_party/boost-1.56.0/boost/system/error_code.hpp:221:36: error: 'boost::system::posix_category' defined but not used [-Werror=unused-variable]
     static const error_category &  posix_category = generic_categor
                                    ^
src/third_party/boost-1.56.0/boost/system/error_code.hpp:222:36: error: 'boost::system::errno_ecat' defined but not used [-Werror=unused-variable]
     static const error_category &  errno_ecat     = generic_categor
                                    ^
src/third_party/boost-1.56.0/boost/system/error_code.hpp:223:36: error: 'boost::system::native_ecat' defined but not used [-Werror=unused-variable]
     static const error_category &  native_ecat    = system_category
                                    ^
cc1plus: all warnings being treated as errors



 Comments   
Comment by Alexander Gorrod [ 22/Sep/15 ]

This is harder than I'd hoped. Fixing the unused variable warning, I see another error:

In file included from src/mongo/bson/bsonobj.h:48:0,
                 from src/mongo/db/jsobj.h:50,
                 from src/mongo/db/exec/plan_stats.h:37,
                 from src/mongo/db/query/plan_cache.h:34,
                 from src/mongo/db/catalog/collection_info_cache.h:34,
                 from src/mongo/db/catalog/collection.h:41,
                 from src/mongo/db/exec/multi_iterator.h:34,
                 from src/mongo/db/exec/multi_iterator.cpp:31:
src/mongo/util/shared_buffer.h: In member function 'virtual mongo::PlanStage::StageState mongo::MultiIteratorStage::work(mongo::WorkingSetID*)':
src/mongo/util/shared_buffer.h:96:24: error: '*((void*)(& record)+32).boost::intrusive_ptr<mongo::SharedBuffer::Holder>::px' may be used uninitialized in this function [-Werror=maybe-uninitialized]
                 free(h);
                        ^
src/mongo/db/exec/multi_iterator.cpp:65:29: note: '*((void*)(& record)+32).boost::intrusive_ptr<mongo::SharedBuffer::Holder>::px' was declared here
     boost::optional<Record> record;
                             ^

That one is out of my C++ knowledge. I'm going to close this issue for now. Can be revisited once we decide to officially support GCC 5.1

Comment by Andrew Morrow (Inactive) [ 15/Jul/15 ]

Static initializers are thread safe in C++11, but not yet on all of our supported compilers unfortunately. However, I don't think that is really the issue here. The compiler warning is actually correct: the variable isn't used, and this isn't a warning we want to disable. I suspect that GCC 5 has just expanded the scope of detection for this class of warning. The solution is probably to attach MONGO_COMPILER_VARIABLE_UNUSED. Please note though that GCC 5 is not yet a supported compiler. My recommendation is that you either build with the --disable-warnings-as-errors flag, or, if it is really a problem for you, make the patch to attach the unused macro and send a code review, which I'll be happy to approve.

Comment by Alexander Gorrod [ 13/Jul/15 ]

Thanks acm that change helps significantly. I still see the second warning:

src/mongo/base/global_initializer.cpp:44:14: error: 'mongo::{anonymous}::_theGlobalInitializer' defined but not used [-Werror=unused-variable]
 Initializer* _theGlobalInitializer = &getGlobalInitializer();

According to this article (http://stackoverflow.com/questions/18542804/global-static-initialization-threading) static initializers are thread safe in C++11, so maybe the code is redundant now?

Comment by Githook User [ 10/Jul/15 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: SERVER-19353 Do not use the deprecated boost system interfaces

(cherry picked from commit 55af30c1040e346e09dbf6b3aa496a241685dc78)
Branch: v3.0
https://github.com/mongodb/mongo/commit/56ed85c71a8e2a0f0cc70a092b51344d6be186d3

Comment by Githook User [ 10/Jul/15 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: SERVER-19353 Do not use the deprecated boost system interfaces
Branch: master
https://github.com/mongodb/mongo/commit/55af30c1040e346e09dbf6b3aa496a241685dc78

Comment by Andrew Morrow (Inactive) [ 10/Jul/15 ]

You can work around this by building with --disable-warnings-as-errors, however, this is a nuisance. I took a closer look at this, and I think we can fix this, permanently, by appending BOOST_SYSTEM_NO_DEPRECATED to our defines.

agorrod - could you see if applying the following to the top level SConstruct makes this go away for you (without specifying --disable-warnings-as-errors):

diff --git a/SConstruct b/SConstruct
index 5362b6e..c2b2f49 100644
--- a/SConstruct
+++ b/SConstruct
@@ -2047,6 +2047,7 @@ def doConfigure(myenv):
             # Boost thread v4's variadic thread support doesn't
             # permit more than four parameters.
             "BOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD",
+            "BOOST_SYSTEM_NO_DEPRECATED",
         ]
     )

Comment by Alexander Gorrod [ 10/Jul/15 ]

I do see one other error as well - though only if I specify a parallel build:

src/mongo/base/global_initializer.cpp:44:14: error: 'mongo::{anonymous}::_theGlobalInitializer' defined but not used [-Werror=unused-variable]
 Initializer* _theGlobalInitializer = &getGlobalInitializer();
              ^
cc1plus: all warnings being treated as errors

As another point of reference I can build without warnings on my Ubuntu box that has GCC 4.8.2.

Comment by Andy Schwerin [ 10/Jul/15 ]

Those errors may be a symptom. On earlier compilers, I think those are the last errors to appear sometimes when something else in the translation unit stops the compiler. Are those the first errors for the unit? If -j is large, sometimes the first error is hundreds of lines up in the build log.

Comment by Alexander Gorrod [ 10/Jul/15 ]

I can work around this problem by passing the following flags to scons:

scons -j 20 --cache LINKFLAGS=-fuse-ld=gold CCFLAGS="-Wno-unused-variable -Wno-maybe-uninitialized" core

Generated at Thu Feb 08 03:50:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.