[CXX-2652] Get a coredump when building with g++73 Created: 09/Feb/23  Updated: 27/Oct/23  Resolved: 29/Mar/23

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: wiki fire Assignee: Kevin Albertson
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File mongo_test.cpp     PNG File yyyyy.png    

 Description   

Summary

Got a coredump when compile with a high version g+. eg: g+73

 

here is the test code.

// code placeholder
// Copyright 2016 MongoDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.#include <cstdlib>
#include <memory>#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/string/to_string.hpp>
#include <bsoncxx/types.hpp>#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/client.hpp>using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;namespace {// The mongocxx::instance constructor and destructor initialize and shut down the driver,
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
// must remain alive for as long as the driver is in use.
//
// This example demonstrates how one might keep a heap allocated mongocxx::instance and
// mongocxx::pool object associated in a way that allows dynamic configuration. Most of the examples
// simply create a stack allocated mongocxx::instance object, which is fine for small examples, but
// real programs will typically require shared access to a commonly configured instance and
// connection pool across different translation units and components. By providing a singleton which
// owns the instance and pool objects, we can defer configuration until we are ready to use MongoDB,
// and share the instance and pool objects between multiple functions.class mongo_access {
   public:
    static mongo_access& instance() {
        static mongo_access instance;
        return instance;
    }    void configure(std::unique_ptr<mongocxx::instance> instance,
                   std::unique_ptr<mongocxx::pool> pool) {
        _instance = std::move(instance);
        _pool = std::move(pool);
    }    using connection = mongocxx::pool::entry;    connection get_connection() {
        return _pool->acquire();
    }    bsoncxx::stdx::optional<connection> try_get_connection() {
        return _pool->try_acquire();
    }   private:
    mongo_access() = default;    std::unique_ptr<mongocxx::instance> _instance = nullptr;
    std::unique_ptr<mongocxx::pool> _pool = nullptr;
};}  // namespace// The 'configure' and 'do_work' functions use the same mongocxx::instance and mongocxx::pool
// objects by way of the mongo_access singleton.void configure(mongocxx::uri uri) {
    class noop_logger : public mongocxx::logger {
       public:
        virtual void operator()(mongocxx::log_level,
                                bsoncxx::stdx::string_view,
                                bsoncxx::stdx::string_view) noexcept {}
    };    auto instance =
        bsoncxx::stdx::make_unique<mongocxx::instance>(bsoncxx::stdx::make_unique<noop_logger>());    mongo_access::instance().configure(std::move(instance),
                                       bsoncxx::stdx::make_unique<mongocxx::pool>(std::move(uri)));
}bool do_work() {
    auto conn = mongo_access::instance().get_connection();
    if (!conn)
        return false;
    
    auto db = (*conn)["session_db"];
    auto collection = db["dddd"];    return true;
}int main(int argc, char* argv[]) {
    auto uri = mongocxx::uri{(argc >= 2) ? argv[1] : mongocxx::uri::k_default_uri};
    configure(std::move(uri));
    do_work();
    return EXIT_SUCCESS;
 
 
 
 

 

 

Coredump

Environment

Please provide the version of the C / CXX driver.

mongo-cxx-driver-r3.7.0

 

Please provide the host OS, version, and architecture (example: Windows 10 64-bit x86).

Linux 9.134.1.187 3.10.107-1-tlinux2_kvm_guest-0056 #1 SMP Wed Dec 29 14:35:09 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

 

Please provide the C / CXX compiler and version.

g++ : g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)

g+73: g+73 (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

 

If applicable, please attach the full output of the cmake command used to configure the C / CXX driver.

If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

How to Reproduce

compile the code with g++ version 4.8.5 , all things are OK, no coredump.

but when compiling with g++73, mongo_test would get a coredump.

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by PM Bot [ 29/Mar/23 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by PM Bot [ 14/Mar/23 ]

Hey firewiki2022@gmail.com, We need additional details to investigate the problem. If this is still an issue for you, please provide the requested information.

Comment by Kevin Albertson [ 06/Mar/23 ]

This example produces a segfault a similar stack trace:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000031 in ?? ()
(gdb) bt
#0  0x0000000000000031 in ?? ()
#1  0x00007ffff7b5d267 in ~_Function_base (this=0x647388, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/functional:2030
#2  ~function (this=0x647388, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/functional:2174
#3  ~apm (this=0x647248, __in_chrg=<optimized out>) at /root/mongo-cxx-driver-r3.7.0/src/mongocxx/../mongocxx/options/apm.hpp:41
#4  ~impl (this=0x647230, __in_chrg=<optimized out>) at /root/mongo-cxx-driver-r3.7.0/src/mongocxx/../mongocxx/private/client.hh:32
#5  operator() (this=<optimized out>, __ptr=0x647230) at /usr/include/c++/4.8.2/bits/unique_ptr.h:67
#6  ~unique_ptr (this=0x7fffffffdb90, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/unique_ptr.h:184
#7  mongocxx::v_noabi::client::~client (this=0x7fffffffdb90, __in_chrg=<optimized out>) at /root/mongo-cxx-driver-r3.7.0/src/mongocxx/../mongocxx/client.hpp:58
#8  0x00007ffff7bb878f in mongocxx::v_noabi::pool::_release (this=0x6471a0, client=0x7fffffffdb90) at /root/mongo-cxx-driver-r3.7.0/src/mongocxx/pool.cpp:40
#9  0x000000000040bb0d in ?? ()
#10 0x0000000000647230 in ?? ()
#11 0x00007fffffffdc20 in ?? ()
#12 0x00007fffffffdbd0 in ?? ()
#13 0x0000000000000001 in ?? ()
#14 0x00007fffffffdbe0 in ?? ()
#15 0x000000000040b2d9 in ?? ()
#16 0x00007fffffffde00 in ?? ()
#17 0x00007fffffffdc20 in ?? ()
#18 0x0000000000000000 in ?? ()

Building the application with g+7.3.0 and linking to the driver built with g+4.8.5 resulted in this error:

CMakeFiles/main.out.dir/main.cpp.o: In function `main':
    /root/cxx-bootstrap/investigations/CXX2652/main.cpp:125: undefined reference to `mongocxx::v_noabi::uri::k_default_uri[abi:cxx11]'
    collect2: error: ld returned 1 exit status

https://stackoverflow.com/questions/55406770/gcc-undefined-references-with-abicxx11 suggested configuring with -D_GLIBCXX_USE_CXX11_ABI=0 to work around. This is the cmake command used in the repro:

CMAKE=/root/cmake-3.25.2-linux-x86_64/bin/cmake
$CMAKE \
    -DCMAKE_PREFIX_PATH=/root/install/mongo-cxx-driver-3.7.0 \
    -DCMAKE_BUILD_TYPE="Debug" \
    -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" \
    -DCMAKE_CXX_STANDARD=17 \
    -DCMAKE_CXX_COMPILER=/root/GCC-7.3.0/bin/g++ \
    -B./cmake-build-g++7.3.0
    -S./ \

https://stackoverflow.com/questions/55406770/gcc-undefined-references-with-abicxx11 notes "Mixing object code compiled by different versions of GCC is fraught with issues.". I am not sure if this is expected to work.

Comment by Kevin Albertson [ 02/Mar/23 ]

Thank you for the report firewiki2022@gmail.com.

Answers to these questions may help us attempt to reproduce this issue:

  • What version of the C driver and C++ driver is installed?
  • How is g++73 installed?

mongo_test.cpp closely resembles the instance_management.cpp example included in the C++ driver.

Generated at Wed Feb 07 22:06:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.