leonardt / pycoreir

Python bindings for coreir
BSD 3-Clause "New" or "Revised" License
10 stars 6 forks source link

Compiling with gcc/g++ 7 #87

Closed makaimann closed 4 years ago

makaimann commented 5 years ago

It looks like there's an issue compiling with g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0. Using clang++ 6.0.0-1 instead works fine. I'm able to compile coreir with g++-7and run the binary with no problems. But, if I install pycoreir with pip install -e . from the repository using g++-7 then run it with gdb I get the following:

gdb --args python3 -c 'import coreir'
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/makai/.virtualenvs/test3/bin/python3 -c import\ coreir
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff7a24801 in __GI_abort () at abort.c:79
#2  0x00007ffff4b95bc5 in __gnu_cxx::__verbose_terminate_handler() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#3  0x00007ffff4b04cd6 in __cxxabiv1::__terminate(void (*)()) () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#4  0x00007ffff4b04d21 in std::terminate() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#5  0x00007ffff4b04994 in __cxa_throw () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#6  0x00007ffff4b04dc2 in __cxa_bad_cast () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#7  0x00007ffff4b19d2c in std::__cxx11::collate<char> const& std::use_facet<std::__cxx11::collate<char> >(std::locale const&) () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#8  0x00007ffff4a5f086 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::__cxx11::regex_traits<char>::transform<char*>(char*, char*) const ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#9  0x00007ffff4a5ca0b in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::__cxx11::regex_traits<char>::transform_primary<char const*>(char const*, char const*) const
    () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#10 0x00007ffff4a57ea8 in std::__detail::_BracketMatcher<std::__cxx11::regex_traits<char>, false, false>::_M_apply(char, std::integral_constant<bool, false>) const::{lambda()#1}::operator()() const ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#11 0x00007ffff4a5803b in std::__detail::_BracketMatcher<std::__cxx11::regex_traits<char>, false, false>::_M_apply(char, std::integral_constant<bool, false>) const ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#12 0x00007ffff4a5323a in std::__detail::_BracketMatcher<std::__cxx11::regex_traits<char>, false, false>::_M_make_cache(std::integral_constant<bool, true>) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#13 0x00007ffff4a4eb23 in std::__detail::_BracketMatcher<std::__cxx11::regex_traits<char>, false, false>::_M_ready() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#14 0x00007ffff4a4f7a5 in void std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_insert_bracket_matcher<false, false>(bool) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#15 0x00007ffff4a4b5c7 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_bracket_expression() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#16 0x00007ffff4a45429 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_atom() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#17 0x00007ffff4a40261 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_term() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#18 0x00007ffff4a3c4ca in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_alternative() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#19 0x00007ffff4a390d2 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_disjunction() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#20 0x00007ffff4a45386 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_atom() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#21 0x00007ffff4a40261 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_term() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#22 0x00007ffff4a3c4ca in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_alternative() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#23 0x00007ffff4a3c4ed in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_alternative() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#24 0x00007ffff4a3c4ed in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_alternative() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#25 0x00007ffff4a390d2 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_M_disjunction() () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#26 0x00007ffff4a36d25 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_Compiler(char const*, char const*, std::locale const&, std::regex_constants::syntax_option_type) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#27 0x00007ffff4a33dea in std::enable_if<std::__detail::__is_contiguous_normal_iter<char const*>::value, std::shared_ptr<std::__detail::_NFA<std::__cxx11::regex_traits<char> > const> >::type std::__detail::__compile_nfa<char const*, std::__cxx11::regex_traits<char> >(char const*, char const*, std::__cxx11::regex_traits<char>::locale_type const&, std::regex_constants::syntax_option_type) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#28 0x00007ffff4a30cc4 in std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >::basic_regex<char const*>(char const*, char const*, std::locale, std::regex_constants::syntax_option_type) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#29 0x00007ffff4a2edcd in std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >::basic_regex<char const*>(char const*, char const*, std::regex_constants::syntax_option_type) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#30 0x00007ffff4a2d9a4 in std::__cxx11::basic_regex<char, std::__cxx11::regex_traits<char> >::basic_regex(char const*, std::regex_constants::syntax_option_type) ()
   from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#31 0x00007ffff4a289a2 in __static_initialization_and_destruction_0 () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#32 0x00007ffff4a28fdf in _GLOBAL__sub_I_verifyconnectivity.cpp () from /home/makai/repos/pycoreir/coreir-cpp/build/lib/libcoreirsim.so
#33 0x00007ffff7de5733 in call_init (env=0x7fffffffddd8, argv=0x7fffffffddb8, argc=3, l=<optimized out>) at dl-init.c:72
#34 _dl_init (main_map=main_map@entry=0xbce400, argc=3, argv=0x7fffffffddb8, env=0x7fffffffddd8) at dl-init.c:119
#35 0x00007ffff7dea1ff in dl_open_worker (a=a@entry=0x7fffffff8fe0) at dl-open.c:522
#36 0x00007ffff7b4b2df in __GI__dl_catch_exception (exception=0x7fffffff8fc0, operate=0x7ffff7de9dc0 <dl_open_worker>, args=0x7fffffff8fe0) at dl-error-skeleton.c:196
#37 0x00007ffff7de97ca in _dl_open (file=0x7ffff5ca84c8 "/home/makai/repos/pycoreir/coreir/libcoreirsim-c.so", mode=-2147483646, caller_dlopen=0x7ffff5ff2cda, nsid=<optimized out>, argc=3, 
    argv=<optimized out>, env=0x7fffffffddd8) at dl-open.c:605
#38 0x00007ffff75c1f96 in dlopen_doit (a=a@entry=0x7fffffff9210) at dlopen.c:66
#39 0x00007ffff7b4b2df in __GI__dl_catch_exception (exception=exception@entry=0x7fffffff91b0, operate=0x7ffff75c1f40 <dlopen_doit>, args=0x7fffffff9210) at dl-error-skeleton.c:196
#40 0x00007ffff7b4b36f in __GI__dl_catch_error (objname=0xaca140, errstring=0xaca148, mallocedp=0xaca138, operate=<optimized out>, args=<optimized out>) at dl-error-skeleton.c:215
Kuree commented 5 years ago

Maybe related: https://gcc.gnu.org/bugzilla//show_bug.cgi?id=82366

I only have gcc-8.3.0 and I can confirm the issue. It seems to be an ABI related problem with string since they upgrade the it aftergcc-7. Due to the manylinux python wheel requirement, if the compiler is newer than gcc4.8, the binaries have to be statically linked with glic/glic++.

Here is a hot fix:

(env) keyi@batman:~/workspace/pycoreir/coreir-cpp$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2c8adef2..d05bc077 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,8 @@ endif()

 set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -fPIC -Werror ${STATIC_FLAGS}")

+add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
+
 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
 set(INCLUDE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include)

@makaimann if it's very important for you to use, I can try to verify the new ABI change won't break the manylinux wheel. If so, I can send a PR to CoreIR.

makaimann commented 5 years ago

Thanks @Kuree! It's not a priority for me, clang is fine.

I'm wondering now if it actually is a g++ 7+ issue or not though. This build for CoSA failed with CXX=g++-4.9: https://travis-ci.org/cristian-mattarei/CoSA/builds/524180955

And if I revert that change as so: https://github.com/cristian-mattarei/CoSA/commit/ed2cdff46e3676b3cfa7146151fcb7d62ad0541a then it's fine.

Has anyone else observed this? I just looked at the Travis logs for pycoreir and it looks like it's using g++-4.9, so I'm not sure what the difference is.

leonardt commented 4 years ago

Resolved upstream in coreir