Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when include "influxdb.hpp" and "string" at the same time with gcc option "-fmodules-ts" #41

Open
ChihHao-Su opened this issue May 11, 2022 · 0 comments

Comments

@ChihHao-Su
Copy link

ChihHao-Su commented May 11, 2022

It's weird, I cannot figure out why.

Situation

  • When with option "-fmodules-ts"
    • If include any one of "influxdb.hpp" and "string", the minimal code example will compile and run successfully.
    • If include "influxdb.hpp" and "string" at the same time, it will compile without error. when running, segmentation fault.
  • When without option "-fmodules-ts"
    • No matter how they are included, the minimal code example will compile and run successfully.

Minimal code example

//main.cxx
#include <string>
#include "influxdb.hpp"

int main(){
  std::string a{"asdfasdf"};
}
$ g++ -Wall -Wextra -fmodules-ts -g main.cxx
$ ./a.out
[1]    60926 segmentation fault (core dumped)  ./a.out

# Run with GDB:
(gdb) r
Starting program: /home/chihhao-su/Proj/json_import_to_influxdb/a.out 

This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.fedoraproject.org/ 
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider::_Alloc_hider (this=0x7ffff7b27e22 <_int_malloc+3682>, __dat=0x7ffff7b27e32 <_int_malloc+3698> "\377H\215\rf\334\025", __a=...) at /usr/src/debug/gcc-11.3.1-2.fc35.x86_64/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ext/new_allocator.h:82
82	      new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { }
(gdb) bt
#0  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider::_Alloc_hider (this=0x7ffff7b27e22 <_int_malloc+3682>, 
    __dat=0x7ffff7b27e32 <_int_malloc+3698> "\377H\215\rf\334\025", __a=...)
    at /usr/src/debug/gcc-11.3.1-2.fc35.x86_64/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/ext/new_allocator.h:82
#1  0x000000000040150a in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> > (
    this=0x7fffffffddf0, __s=0x40203a "asdfasdf", __a=...)
    at /usr/include/c++/11/bits/basic_string.h:534
#2  0x0000000000401280 in main () at main.cxx:6
(gdb) 

I suspected it might be some limitations(or bugs) in GCC which doesn't allow users to include a c++ header(e.g. use a header-only-third-party library) that uses the header-file-version of c++ standard library when enable option "-fmodules-ts". But I wrote a simple .hpp file including a class, which uses std::string that in header-file-version of c++ standard library:

#include <string>
namespace Foo
{
class Bar
{
private:
    std::string bar;
public:
    Bar(std::string foo): bar(foo) { }
};
};

And I try to include both of it and "string" in main.cxx, it can still compile and run sucessfully. I'm wondering if it's some thing with influxdb-cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant