This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/78475] New: Mixing objects form different g++ versions can crash a program


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78475

            Bug ID: 78475
           Summary: Mixing objects form different g++ versions can crash a
                    program
           Product: gcc
           Version: 6.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jengelh at inai dot de
                CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

Is mixing "finalized" object files (ET_EXEC, ET_DYN) produced by different g++
versions a supported scenario? If so, consider this:

$ cat all.h 
#include <memory>
#include <cstdio>
struct handler { virtual ~handler() {} };
extern std::shared_ptr<handler> get_handler(void);
$ cat g48.cpp
#include "all.h"
std::shared_ptr<handler> get_handler(void)
{
        printf("%zu\n", sizeof(std::_Sp_counted_ptr_inplace<handler,
        std::allocator<handler>, (__gnu_cxx::_Lock_policy)2 >));
        return std::make_shared<handler>();
}
$ cat main.cpp 
#include "all.h"
int main(void)
{
        printf("%zu\n", sizeof(std::_Sp_counted_ptr_inplace<handler,
        std::allocator<handler>, (__gnu_cxx::_Lock_policy)2 >));
        get_handler();
        std::make_shared<handler>();
        return 0;
}
$ g++-4.8 g48.cpp -fPIC -shared -o g48.so -std=gnu++11
$ g++-6 main.cpp -o main ./g48.so -std=gnu++11
$ ./main
24
32
Segmentation fault (core dumped)

The reason, as I have found, is that there was an ABI change in
Sp_counted_ptr_inplace which made it grow in size. Furthermore, if you
single-step through g48.cpp's make_shared, you will notice it jumps between
functions from /usr/include/c++/4.8 and /usr/include/c++/6, which I suppose is
a result of symbols
(_ZNSt23_Sp_counted_ptr_inplaceI7handlerSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE14_M_get_deleterERKSt9type_info)
not being sufficiently versioned, causing weak symbols from main(.o) and
g48(.o) to trample on one another. That is to say, to remedy the problem,
_Sp_counted_ptr_inplace would need something like __attribute__((__abi_tag__
("GLIBCXX_3.4.22"))) maybe.



Compilers used:
> gcc-4.8 -v
Using built-in specs.
COLLECT_GCC=gcc-4.8
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.8/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.8
--enable-ssp --disable-libssp --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib
--enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --enable-linker-build-id
--enable-linux-futex --program-suffix=-4.8 --without-system-libunwind
--with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
--host=x86_64-suse-linux
Thread model: posix
gcc version 4.8.5 (SUSE Linux) [openSUSE Leap 42.1 base compiler]
$ gcc-6 -v
Using built-in specs.
Reading specs from /usr/lib64/gcc/x86_64-suse-linux/6/defaults.spec
COLLECT_GCC=gcc-6
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/6/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada,go
--enable-offload-targets=hsa --enable-checking=release
--with-gxx-include-dir=/usr/include/c++/6 --enable-ssp --disable-libssp
--disable-libvtv --disable-libcc1 --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--with-default-libstdcxx-abi=gcc4-compatible
--enable-version-specific-runtime-libs --enable-linker-build-id
--enable-linux-futex --enable-gnu-indirect-function --program-suffix=-6
--without-system-libunwind --enable-multilib --with-arch-32=x86-64
--with-tune=generic --build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
gcc version 6.2.1 20161121 [gcc-6-branch revision 242657] (SUSE Linux)
[devel:gcc for 42.1] 
(Both compilers are using _GLIBCXX_USE_CXX11_ABI=0 in all cases)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]