Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19340

Vendored wiredtiger rand.c fails to compile without -fno-strict-aliasing

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.7
    • Component/s: Build, Internal Code, WiredTiger
    • Labels:
      None
    • Environment:
      Ubuntu 15.04, GCC 4.9.2
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Remove -fno-strict-aliasing from the top level SConstruct and build with a modern GCC.

      Show
      Remove -fno-strict-aliasing from the top level SConstruct and build with a modern GCC.

      Description

      If the -fno-strict-aliasing flag is removed from the top level SConstruct, the vendored WiredTiger sources in src/third_party/wiredtiger do not compile. In particular, the rand.c file generates strict aliasing errors:

      src/third_party/wiredtiger/src/support/rand.c: In function '__wt_random_init':
      src/third_party/wiredtiger/src/support/rand.c:57:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
        M_W(rnd) = 521288629;
        ^
      src/third_party/wiredtiger/src/support/rand.c: In function '__wt_random':
      src/third_party/wiredtiger/src/support/rand.c:78:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
        w = M_W(rnd);
        ^
      src/third_party/wiredtiger/src/support/rand.c:91:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
        M_W(rnd) = w = 18000 * (w & 65535) + (w >> 16);
        ^
      cc1: all warnings being treated as errors
      

        Issue Links

          Activity

          Hide
          david.hows David Hows added a comment -

          I tried to reproduce this on my arch box w/ GCC 5.2.0 but could not get to the point where you failed;

          First I hit the following:

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

          With that resolved, I hit the following:

          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:98: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:66:29: note: '*((void*)(& record)+32).boost::intrusive_ptr<mongo::SharedBuffer::Holder>::px' was declared here
               boost::optional<Record> record;
          

          In file included from src/mongo/db/pipeline/document.h:31:0,
                           from src/mongo/db/pipeline/document_source.h:48,
                           from src/mongo/db/exec/pipeline_proxy.cpp:34:
          src/mongo/db/pipeline/document_internal.h: In static member function 'static const mongo::DocumentStorage& mongo::DocumentStorage::emptyDoc()':
          src/mongo/db/pipeline/document_internal.h:205:68: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
                   return *reinterpret_cast<const DocumentStorage*>(emptyBytes);
          

          Show
          david.hows David Hows added a comment - I tried to reproduce this on my arch box w/ GCC 5.2.0 but could not get to the point where you failed; First I hit the following: src/mongo/base/global_initializer.cpp:44:14: error: 'mongo::{anonymous}::_theGlobalInitializer' defined but not used [-Werror=unused-variable] Initializer* _theGlobalInitializer = &getGlobalInitializer(); With that resolved, I hit the following: 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:98: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:66:29: note: '*((void*)(& record)+32).boost::intrusive_ptr<mongo::SharedBuffer::Holder>::px' was declared here boost::optional<Record> record; In file included from src/mongo/db/pipeline/document.h:31:0, from src/mongo/db/pipeline/document_source.h:48, from src/mongo/db/exec/pipeline_proxy.cpp:34: src/mongo/db/pipeline/document_internal.h: In static member function 'static const mongo::DocumentStorage& mongo::DocumentStorage::emptyDoc()': src/mongo/db/pipeline/document_internal.h:205:68: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] return *reinterpret_cast<const DocumentStorage*>(emptyBytes);
          Hide
          alexander.gorrod Alexander Gorrod added a comment -

          David Hows GCC 5.2.0 is not yet supported. There is another ticket covering the warning you report:
          https://jira.mongodb.org/browse/SERVER-19353

          Show
          alexander.gorrod Alexander Gorrod added a comment - David Hows GCC 5.2.0 is not yet supported. There is another ticket covering the warning you report: https://jira.mongodb.org/browse/SERVER-19353
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

          Message: SERVER-19340 Avoid type aliasing in the random number generator.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/7063f8b6e80b130f9a682991203384bd05c58f24

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'} Message: SERVER-19340 Avoid type aliasing in the random number generator. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/7063f8b6e80b130f9a682991203384bd05c58f24
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

          Message: SERVER-19340 Fix the random state union.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/24569ab8457df6a07cd65866a560f6967a51d5fc

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'} Message: SERVER-19340 Fix the random state union. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/24569ab8457df6a07cd65866a560f6967a51d5fc
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'daveh86', u'name': u'David Hows', u'email': u'howsdav@gmail.com'}

          Message: Merge pull request #2088 from wiredtiger/rand-strict-alias

          SERVER-19340 Avoid type aliasing in the random number generator.
          Branch: develop
          https://github.com/wiredtiger/wiredtiger/commit/3ec45a7204e01a5ac176550fdfef30a7402046e8

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'daveh86', u'name': u'David Hows', u'email': u'howsdav@gmail.com'} Message: Merge pull request #2088 from wiredtiger/rand-strict-alias SERVER-19340 Avoid type aliasing in the random number generator. Branch: develop https://github.com/wiredtiger/wiredtiger/commit/3ec45a7204e01a5ac176550fdfef30a7402046e8
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'daveh86', u'name': u'David Hows', u'email': u'howsdav@gmail.com'}

          Message: Merge pull request #2088 from wiredtiger/rand-strict-alias

          SERVER-19340 Avoid type aliasing in the random number generator.
          (cherry picked from commit 3ec45a7204e01a5ac176550fdfef30a7402046e8)
          Branch: mongodb-3.0
          https://github.com/wiredtiger/wiredtiger/commit/69819d42bbe625ddef576939e112cf4e1e745948

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'daveh86', u'name': u'David Hows', u'email': u'howsdav@gmail.com'} Message: Merge pull request #2088 from wiredtiger/rand-strict-alias SERVER-19340 Avoid type aliasing in the random number generator. (cherry picked from commit 3ec45a7204e01a5ac176550fdfef30a7402046e8) Branch: mongodb-3.0 https://github.com/wiredtiger/wiredtiger/commit/69819d42bbe625ddef576939e112cf4e1e745948

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: