diff options
author | Jeffrey Walton <noloader@gmail.com> | 2022-08-24 23:00:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 23:00:04 -0400 |
commit | 0b5747421b279283fc6d1b1065dc01fb5d1ec997 (patch) | |
tree | 3bc490e2e4f80f3c2ff907f35d48112da44a46b7 | |
parent | 307ada58d618eb05c89b6e4a6bc55ac4026a7e9a (diff) | |
download | cryptopp-git-0b5747421b279283fc6d1b1065dc01fb5d1ec997.tar.gz |
Add -fno-devirtualize when using GCC 12 (GH #1134, GH #1141, PR #1147)
This is not a fix since it only treats the symptom of GCC removing live code. We do not know why GCC is doing it.
-rw-r--r-- | Filelist.txt | 3 | ||||
-rw-r--r-- | GNUmakefile | 16 | ||||
-rw-r--r-- | TestPrograms/test_nodevirtualize.cpp | 19 | ||||
-rw-r--r-- | validat9.cpp | 23 |
4 files changed, 45 insertions, 16 deletions
diff --git a/Filelist.txt b/Filelist.txt index 0543ac8f..0639e16e 100644 --- a/Filelist.txt +++ b/Filelist.txt @@ -608,12 +608,12 @@ TestPrograms/test_cxx11_auto.cpp TestPrograms/test_cxx11_constexpr.cpp
TestPrograms/test_cxx11.cpp
TestPrograms/test_cxx11_deletefn.cpp
-TestPrograms/test_cxx11_staticinit.cpp
TestPrograms/test_cxx11_enumtype.cpp
TestPrograms/test_cxx11_initializer.cpp
TestPrograms/test_cxx11_lambda.cpp
TestPrograms/test_cxx11_noexcept.cpp
TestPrograms/test_cxx11_nullptr.cpp
+TestPrograms/test_cxx11_staticinit.cpp
TestPrograms/test_cxx11_sync.cpp
TestPrograms/test_cxx11_vartemplates.cpp
TestPrograms/test_cxx14.cpp
@@ -624,6 +624,7 @@ TestPrograms/test_cxx98_exception.cpp TestPrograms/test_cxx.cpp
TestPrograms/test_glibc.cpp
TestPrograms/test_newlib.cpp
+TestPrograms/test_nodevirtualize.cpp
TestPrograms/test_ppc_aes.cpp
TestPrograms/test_ppc_altivec.cpp
TestPrograms/test_ppc_power7.cpp
diff --git a/GNUmakefile b/GNUmakefile index 0f849fc6..deffca90 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -846,6 +846,18 @@ ifeq ($(IS_X86)$(IS_CYGWIN)$(IS_MINGW),000) endif endif +# Fix for GH #1134 and GH #1141. We need to add -fno-devirtualize because GCC is removing +# code we are using. https://github.com/weidai11/cryptopp/issues/1134 and +# https://github.com/weidai11/cryptopp/issues/1141 +ifeq ($(findstring -fno-devirtualize,$(CXXFLAGS)),) + TPROG = TestPrograms/test_nodevirtualize.cpp + TOPT = -fno-devirtualize + HAVE_OPT = $(shell $(TCOMMAND) 2>&1 | wc -w) + ifeq ($(strip $(HAVE_OPT)),0) + CRYPTOPP_CXXFLAGS += -fno-devirtualize + endif # CRYPTOPP_CXXFLAGS +endif # -fno-devirtualize + # Use -pthread whenever it is available. See http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf # http://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling ifeq ($(DETECT_FEATURES),1) @@ -857,7 +869,7 @@ ifeq ($(DETECT_FEATURES),1) ifeq ($(strip $(HAVE_OPT)),0) CRYPTOPP_CXXFLAGS += -qthreaded endif # CRYPTOPP_CXXFLAGS - endif # qthreaded + endif # -qthreaded else ifeq ($(findstring -pthread,$(CXXFLAGS)),) TPROG = TestPrograms/test_pthreads.cpp @@ -866,7 +878,7 @@ ifeq ($(DETECT_FEATURES),1) ifeq ($(strip $(HAVE_OPT)),0) CRYPTOPP_CXXFLAGS += -pthread endif # CRYPTOPP_CXXFLAGS - endif # pthread + endif # -pthread endif # XLC/GCC and friends endif # DETECT_FEATURES diff --git a/TestPrograms/test_nodevirtualize.cpp b/TestPrograms/test_nodevirtualize.cpp new file mode 100644 index 00000000..ad4489a4 --- /dev/null +++ b/TestPrograms/test_nodevirtualize.cpp @@ -0,0 +1,19 @@ +#include <string>
+
+// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
+#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+
+int main(int argc, char* argv[])
+{
+ // GCC 12 is removing live code. We don't know why.
+ // https://github.com/weidai11/cryptopp/issues/1134 and
+ // https://github.com/weidai11/cryptopp/issues/1141
+#if defined(__linux__) && (GCC_VERSION >= 120000)
+ // On successful compile -fno-devirtualize will be used
+ // to work around the problem.
+ ;;
+#else
+ int x[-1];
+#endif
+ return 0;
+}
diff --git a/validat9.cpp b/validat9.cpp index 23530ccc..e00af4eb 100644 --- a/validat9.cpp +++ b/validat9.cpp @@ -652,20 +652,17 @@ bool ValidateECGDSA(bool thorough) {
std::cout << "\nECGDSA validation suite running...\n\n";
- // 'thorough' forced to false due to GH #1134. There is something sideways
- // with GCC 12 and ECGDSA+RIPEMD. The problem is present with
- // CRYPTOPP_DISABLE_ASM, which indicates a C++ problem. However, Asan,
- // UBsan and Valgrind fail to produce a finding. The program simply crashes
- // with a junk backtrace. And GCC 11 (and earlier), Clang, MSVC, xlC are Ok.
- // This is likely a compiler bug.
-#if CRYPTOPP_GCC_VERSION >= 120000
- thorough = false;
-#endif
+ bool pass = true, fail;
+
+ fail = !ValidateECGDSAStandard();
+ pass = pass && !fail;
- if (thorough)
- return ValidateECGDSAStandard() && ValidateECGDSAThorough();
- else
- return ValidateECGDSAStandard();
+ if (thorough) {
+ fail = !ValidateECGDSAThorough();
+ pass = pass && !fail;
+ }
+
+ return pass;
}
bool ValidateESIGN()
|