cmu-sei / pharos

Automated static analysis tools for binary programs
Other
1.56k stars 192 forks source link

Build error running make on CentOS 7 (error: constructor required before non-static data member) #257

Closed swoolbean closed 10 months ago

swoolbean commented 1 year ago

Hi! Hoping this is the right place to ask about this. I followed the installation guide for manually building from source to get Pharos working on my CentOS 7 virtual machine. As far as I can tell, I've managed to get all the dependencies built and installed, but when I run make -j4 in Pharos' build directory, I get this error about halfway through the build:

/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:878:48: error: constructor required before non-static data member for ‘pharos::PathFinder::SolverDeleter::owned’ has been parsed
     template<typename _Tp, typename = decltype(_Tp())>

with make finishing with this output:

make[2]: *** [libpharos/CMakeFiles/pharos.dir/options.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [libpharos/CMakeFiles/pharos.dir/path.cpp.o] Error 1
make[1]: *** [libpharos/CMakeFiles/pharos.dir/all] Error 2
make: *** [all] Error 2

Because I previously had an issue with CMake targeting an older version of C++, I also tried running it with extra flags to lock the version down, but I got the same error:

sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_STANDARD_REQUIRED=ON

I know that CentOS 7 isn't in your list of supported distributions for manually building, but RHEL 7 is, and in my experience that's a good indicator that CentOS 7 should be fine as well.

Please let me know if you need any more info or if I should be posting this somewhere else. Thanks!

sei-eschwartz commented 1 year ago

What version of g++ are you using? This is the right place to ask!

Sent from my T-Mobile 5G Device Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: SwoolBean @.> Sent: Friday, September 15, 2023 3:24:11 AM To: cmu-sei/pharos @.> Cc: Subscribed @.***> Subject: [cmu-sei/pharos] Build error running make on CentOS 7 (error: constructor required before non-static data member) (Issue #257)

Hi! Hoping this is the right place to ask about this. I followed the installation guide for manually building from source to get Pharos working on my CentOS 7 virtual machine. As far as I can tell, I've managed to get all the dependencies built and installed, but when I run make -j4 in Pharos' build directory, I get this error about halfway through the build:

/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:878:48: error: constructor required before non-static data member for ‘pharos::PathFinder::SolverDeleter::owned’ has been parsed template<typename _Tp, typename = decltype(_Tp())>

with make finishing with this output:

make[2]: [libpharos/CMakeFiles/pharos.dir/options.cpp.o] Error 1 make[2]: Waiting for unfinished jobs.... make[2]: [libpharos/CMakeFiles/pharos.dir/path.cpp.o] Error 1 make[1]: [libpharos/CMakeFiles/pharos.dir/all] Error 2 make: *** [all] Error 2

Because I previously had an issue with CMake targeting an older version of C++, I also tried running it with extra flags to lock the version down, but I got the same error:

sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_STANDARD_REQUIRED=ON

I know that CentOS 7 isn't in your list of supported distributions for manually building, but RHEL 7 is, and in my experience that's a good indicator that CentOS 7 should be fine as well.

Please let me know if you need any more info or if I should be posting this somewhere else. Thanks!

— Reply to this email directly, view it on GitHubhttps://github.com/cmu-sei/pharos/issues/257, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AL6ZAVDJPC2K7IWLJOCREUDX2P7BXANCNFSM6AAAAAA4ZMCK3E. You are receiving this because you are subscribed to this thread.Message ID: @.***>

swoolbean commented 1 year ago

I want to say 7.2.4, but my host machine actually bricked itself this morning, so I won't be able to check for a few weeks until it's repaired 😅

If I have some time this coming week, I'll try getting it set up on a different PC.

sei-ccohen commented 1 year ago

I know that we've had to upgrade our compiler in the RedHat environment a couple of times. We're currently using devtoolset-11 in our build environment. I'm not certain what our minimum version requirement for the compiler is, but I know that we need C++14 support. I encourage you to upgrade the compiler for your next build.

sei-mwd commented 1 year ago

C++14 is supposedly available from gcc 6.1 and up, but we haven't tested with versions of gcc that old in some time. It is possible that we accidentally have some code that is not C++14 compliant, but that compiles on later versions of gcc anyway. I could look at what is going on, but I would need more context from your original error message to trace down what is happening.

sei-mwd commented 1 year ago

Did not mean to close this issue.

sei-eschwartz commented 1 year ago

I was able to reproduce this with gcc 7.3.1 on centos 7 using the commands in this notebook: https://colab.research.google.com/drive/1RsbkTSUjuIlrdR4T73vo4mC-K0Adifq0?usp=sharing

But the notebook is slow because it uses udocker, so it's still catching up. This is from my machine:

[3/29] Building CXX object libpharos/CMakeFiles/pharos.dir/options.cpp.o
FAILED: libpharos/CMakeFiles/pharos.dir/options.cpp.o 
/opt/rh/devtoolset-7/root/usr/bin/c++ -Dpharos_EXPORTS -I/root/pharos/scripts/build/libpharos -isystem /usr/local/include/rose -isystem /usr/local/lib/swipl/include -pedantic -pedantic-errors -Wall -Wextra -Wshadow -Wstrict-aliasing -Wno-misleading-indentation -ftemplate-depth=1024 -ftrack-macro-expansion=0 -O3 -DNDEBUG -std=c++14 -fPIC -pthread -Winvalid-pch -include /root/pharos/scripts/build/libpharos/CMakeFiles/pharos.dir/cmake_pch.hxx -MD -MT libpharos/CMakeFiles/pharos.dir/options.cpp.o -MF libpharos/CMakeFiles/pharos.dir/options.cpp.o.d -o libpharos/CMakeFiles/pharos.dir/options.cpp.o -c /root/pharos/libpharos/options.cpp
In file included from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/move.h:54:0,
                 from /opt/rh/devtoolset-7/root/usr/include/c++/7/bits/nested_exception.h:40,
                 from /opt/rh/devtoolset-7/root/usr/include/c++/7/exception:143,
                 from /opt/rh/devtoolset-7/root/usr/include/c++/7/ios:39,
                 from /opt/rh/devtoolset-7/root/usr/include/c++/7/ostream:38,
                 from /usr/local/include/boost/system/error_code.hpp:19,
                 from /usr/local/include/boost/filesystem/path_traits.hpp:23,
                 from /usr/local/include/boost/filesystem/path.hpp:25,
                 from /usr/local/include/boost/filesystem.hpp:16,
                 from /usr/local/include/rose/sage3basic.h:42,
                 from /usr/local/include/rose/sage3basic.hhh:4,
                 from /usr/local/include/rose/rose.h:10,
                 from /root/pharos/scripts/build/libpharos/CMakeFiles/pharos.dir/cmake_pch.hxx:5,
                 from <command-line>:0:
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits: In substitution of 'template<class _Tp, class> static std::true_type std::__do_is_default_constructible_impl::__test(int) [with _Tp = pharos::PathFinder::SolverDeleter; <template-parameter-1-2> = <missing>]':
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:889:35:   required from 'struct std::__is_default_constructible_impl<pharos::PathFinder::SolverDeleter>'
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:143:12:   required from 'struct std::__and_<std::__not_<std::is_void<pharos::PathFinder::SolverDeleter> >, std::__is_default_constructible_impl<pharos::PathFinder::SolverDeleter> >'
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:893:12:   required from 'struct std::__is_default_constructible_atom<pharos::PathFinder::SolverDeleter>'
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:914:12:   required from 'struct std::__is_default_constructible_safe<pharos::PathFinder::SolverDeleter, false>'
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:920:12:   required from 'struct std::is_default_constructible<pharos::PathFinder::SolverDeleter>'
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:143:12:   required from 'struct std::__and_<std::__not_<std::is_pointer<pharos::PathFinder::SolverDeleter> >, std::is_default_constructible<pharos::PathFinder::SolverDeleter> >'
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/unique_ptr.h:135:47:   required from 'class std::__uniq_ptr_impl<pharos::PharosZ3Solver, pharos::PathFinder::SolverDeleter>'
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/unique_ptr.h:163:33:   required from 'class std::unique_ptr<pharos::PharosZ3Solver, pharos::PathFinder::SolverDeleter>'
/root/pharos/libpharos/path.hpp:303:0:   required from here
/opt/rh/devtoolset-7/root/usr/include/c++/7/type_traits:878:48: error: constructor required before non-static data member for 'pharos::PathFinder::SolverDeleter::owned' has been parsed
     template<typename _Tp, typename = decltype(_Tp())>
sei-eschwartz commented 1 year ago

https://stackoverflow.com/a/17436088

sei-eschwartz commented 1 year ago

This fixed it for me, but @sei-mwd might have a more elegant solution:

[root@ed-Precision-7540 libpharos]# git diff
diff --git a/libpharos/path.hpp b/libpharos/path.hpp
index a89b20a..2b31766 100644
--- a/libpharos/path.hpp
+++ b/libpharos/path.hpp
@@ -297,6 +297,8 @@ class PathFinder : public Z3PathAnalyzer {
   struct SolverDeleter {
     bool owned = true;
     void operator()(PharosZ3Solver *s) const { if (owned) delete s; }
+    SolverDeleter() {}
+    explicit SolverDeleter(bool owned_) : owned(owned_) {}
   };

   // We will need Z3 for this analysis

The default constructor is needed for unique_ptr, and the second one is needed because we use SolverDeleter{false} somewhere.

turol commented 1 year ago

Single-parameter constructor should probably be marked explicit.

sei-mwd commented 1 year ago

Okay. This looks like a bug in the C++ standard library in that version of gcc. The fix that @sei-eschwartz posted is harmless, so I'll commit a variant of it shortly.

sei-eschwartz commented 10 months ago

@sei-mwd Can you make sure this is committed?

sei-mwd commented 10 months ago

I pushed before testing, and there was a typo. Should be fixed in eeb1b52aac12e357db61f38ee0de022f1df881f8.