Bug 1776781 - g++ -D_GLIBCXX_USE_CXX11_ABI=0 compiles but executable crashes
Summary: g++ -D_GLIBCXX_USE_CXX11_ABI=0 compiles but executable crashes
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gcc
Version: 8.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.0
Assignee: Marek Polacek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-11-26 11:37 UTC by Piyush Bhoot
Modified: 2023-07-18 14:19 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-11-26 13:01:33 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Piyush Bhoot 2019-11-26 11:37:12 UTC
Description of problem:

An C++ executable compiled with -D_GLIBCXX_USE_CXX11_ABI=0 crashes whereas with -D_GLIBCXX_USE_CXX11_ABI=1 (RHEL 8.1 default) does not:


Version-Release number of selected component (if applicable):
gcc version 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC) 

Steps to Reproduce:
test.cpp:
#include <boost/filesystem/path.hpp>
#include <iostream>

int main(int argc, char* argv[]) {
    std::cout << "_GLIBCXX_USE_CXX11_ABI=" << _GLIBCXX_USE_CXX11_ABI << std::endl;
    std::cout << "sizeof(boost::filesystem::path)=" << sizeof(boost::filesystem::path) << std::endl;
    std::cout << boost::filesystem::path(argv[0]).filename().string() << std::endl;
    return 0;
}

$ g++ -D_GLIBCXX_USE_CXX11_ABI=1 -lboost_system -lboost_filesystem test.cpp; ./a.out 
_GLIBCXX_USE_CXX11_ABI=1
sizeof(boost::filesystem::path)=32
a.out
$ g++ -D_GLIBCXX_USE_CXX11_ABI=0 -lboost_system -lboost_filesystem test.cpp; ./a.out 
_GLIBCXX_USE_CXX11_ABI=0
sizeof(boost::filesystem::path)=8
Segmentation fault (core dumped)

Actual results:
Segmentation fault (core dumped)

Expected results:
No segfault

Comment 1 Jakub Jelinek 2019-11-26 11:43:28 UTC
-D_GLIBCXX_USE_CXX11_ABI=0 is an ABI changing option, so you can only use it in programs where all the C++ code has been compiled with that option, or with libraries like libstdc++.so.6 which do support both ABIs.
That is not the case in your testcase, the libboost_system.so and libboost_filesystem.so libraries are most likely built with the default C++ ABI on RHEL8, so -D_GLIBCXX_USE_CXX11_ABI=1.

Comment 2 Jonathan Wakely 2019-11-26 12:07:39 UTC
This is not a bug, for the reasons Jakub said. The RHEL8 system libraries (including Boost) use the new ABI, so you cannot expect them to work correctly when you use a different ABI.

Comment 3 Marek Polacek 2019-11-26 13:01:33 UTC
Invalid code, closing.


Note You need to log in before you can comment on or make changes to this bug.