From d4c2c6b2459d8878a925e62b5b528d31b708034b Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 4 Jan 2025 16:57:39 -0500 Subject: [PATCH] Add patch for strict weak ordering in type comparison Fixes Windows Debug builds --- .../0001-Fix-UBSAN-errors-in-decompiler.patch | 6 ++-- ...ead-of-stroul-to-parse-address-offse.patch | 6 ++-- ...Use-string-resize-instead-of-reserve.patch | 6 ++-- ...point-test-due-to-compilation-differ.patch | 6 ++-- ...r-negative-NAN-in-decompiler-floatin.patch | 6 ++-- ...nconsistency-in-type-comparison-oper.patch | 30 +++++++++++++++++++ 6 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 src/patches/HEAD/0006-decompiler-Fix-inconsistency-in-type-comparison-oper.patch diff --git a/src/patches/HEAD/0001-Fix-UBSAN-errors-in-decompiler.patch b/src/patches/HEAD/0001-Fix-UBSAN-errors-in-decompiler.patch index c5e6dc136..ed55ca8f5 100644 --- a/src/patches/HEAD/0001-Fix-UBSAN-errors-in-decompiler.patch +++ b/src/patches/HEAD/0001-Fix-UBSAN-errors-in-decompiler.patch @@ -1,7 +1,7 @@ -From 5b07c4118a9c6fe8f9d240419aaf5b8ce49becdf Mon Sep 17 00:00:00 2001 +From 7c6e51dd1234387b98e1ad61d3f88a0565364b28 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Mon, 12 Aug 2024 12:02:35 -0400 -Subject: [PATCH 1/5] Fix UBSAN errors in decompiler +Subject: [PATCH 1/6] Fix UBSAN errors in decompiler Co-authored-by: Alex Cameron --- @@ -220,5 +220,5 @@ index 2571f55f1a..fe40e22b1b 100644 uintb true_result = ((uintb)(int32_t)f) & 0xffffffff; uintb encoding = format.getEncoding(f); -- -2.47.0 +2.47.1 diff --git a/src/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch b/src/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch index afa63584c..99253c6c9 100644 --- a/src/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch +++ b/src/patches/HEAD/0002-Use-stroull-instead-of-stroul-to-parse-address-offse.patch @@ -1,7 +1,7 @@ -From 4da4a99471f73c3962b8c9d89d9a593896366a58 Mon Sep 17 00:00:00 2001 +From 5e37c51ebc8a3ae0f32a3cb0049aaebafec48d7d Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Wed, 3 Aug 2022 20:01:18 +1000 -Subject: [PATCH 2/5] Use `stroull` instead of `stroul` to parse address +Subject: [PATCH 2/6] Use `stroull` instead of `stroul` to parse address offsets --- @@ -34,5 +34,5 @@ index dbaa2e775f..72927bf379 100644 enddata = (const char *) tmpdata; if (enddata - s.c_str() == s.size()) { // If no size or offset override -- -2.47.0 +2.47.1 diff --git a/src/patches/HEAD/0003-Use-string-resize-instead-of-reserve.patch b/src/patches/HEAD/0003-Use-string-resize-instead-of-reserve.patch index bbc302377..e233b8fc4 100644 --- a/src/patches/HEAD/0003-Use-string-resize-instead-of-reserve.patch +++ b/src/patches/HEAD/0003-Use-string-resize-instead-of-reserve.patch @@ -1,7 +1,7 @@ -From d2b0eaec8477ddaf7a1a971e45a6ebf8dceb57da Mon Sep 17 00:00:00 2001 +From 0feb881ef1cbc9aa4639e16914b7d9ed863baadf Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 29 Oct 2024 15:30:57 -0400 -Subject: [PATCH 3/5] Use string resize instead of reserve +Subject: [PATCH 3/6] Use string resize instead of reserve assign will fix up the size to hold all of what's copied --- @@ -32,5 +32,5 @@ index 5f5fa0c7b3..4cd77156f2 100644 } data.isTruncated = (numChars >= maximumChars); -- -2.47.0 +2.47.1 diff --git a/src/patches/HEAD/0004-Ignore-floating-point-test-due-to-compilation-differ.patch b/src/patches/HEAD/0004-Ignore-floating-point-test-due-to-compilation-differ.patch index eac1e92ae..b4587e7cc 100644 --- a/src/patches/HEAD/0004-Ignore-floating-point-test-due-to-compilation-differ.patch +++ b/src/patches/HEAD/0004-Ignore-floating-point-test-due-to-compilation-differ.patch @@ -1,7 +1,7 @@ -From fc506c1da2adc3fb249d7721f3c4a16c3c319056 Mon Sep 17 00:00:00 2001 +From 2a8f30f31c24ecc7bd499648b97bb8b0c2705b78 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Tue, 29 Oct 2024 17:51:09 -0400 -Subject: [PATCH 4/5] Ignore floating point test due to compilation differences +Subject: [PATCH 4/6] Ignore floating point test due to compilation differences This test fails on macOS and Windows. I'm unsure whether it's an OS or compiler issue. @@ -24,5 +24,5 @@ index fe40e22b1b..91440e2510 100644 ASSERT_EQUALS(ff.printDecimal(f2, false), "0.33333334"); double f3 = doubleFromRawBits(0x3fd0000000000000); -- -2.47.0 +2.47.1 diff --git a/src/patches/HEAD/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch b/src/patches/HEAD/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch index e02f1d790..c8699cc90 100644 --- a/src/patches/HEAD/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch +++ b/src/patches/HEAD/0005-Allow-positive-or-negative-NAN-in-decompiler-floatin.patch @@ -1,7 +1,7 @@ -From 59254803a80df713860817b05fdc4c4487dd984f Mon Sep 17 00:00:00 2001 +From 04cca72897d9088713a6e2dadb2774ad20ae7703 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Wed, 30 Oct 2024 14:26:57 -0400 -Subject: [PATCH 5/5] Allow positive or negative NAN in decompiler floating +Subject: [PATCH 5/6] Allow positive or negative NAN in decompiler floating point test At least on Apple Silicon, this test reports positive NAN. @@ -33,5 +33,5 @@ index f8108d3d32..1060a3e193 100644 double7 = 3.1415926535897933e-06; -- -2.47.0 +2.47.1 diff --git a/src/patches/HEAD/0006-decompiler-Fix-inconsistency-in-type-comparison-oper.patch b/src/patches/HEAD/0006-decompiler-Fix-inconsistency-in-type-comparison-oper.patch new file mode 100644 index 000000000..9d98a60f6 --- /dev/null +++ b/src/patches/HEAD/0006-decompiler-Fix-inconsistency-in-type-comparison-oper.patch @@ -0,0 +1,30 @@ +From 6b57f1fc8e23c2e72afb05750d6ca11e94af9812 Mon Sep 17 00:00:00 2001 +From: Eric Kilmer +Date: Sat, 4 Jan 2025 16:50:52 -0500 +Subject: [PATCH 6/6] decompiler: Fix inconsistency in type comparison operator + +More specific class implementations straight return res instead of +returning the comparison to zero + +This fixes an error in a Debug build on Windows for a strict weak +ordering error at runtime in the tests. +--- + Ghidra/Features/Decompiler/src/decompile/cpp/type.hh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh +index 95ceaf9bb1..d677e63bee 100644 +--- a/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh ++++ b/Ghidra/Features/Decompiler/src/decompile/cpp/type.hh +@@ -306,7 +306,7 @@ struct DatatypeCompare { + /// Comparison operator + bool operator()(const Datatype *a,const Datatype *b) const { + int4 res = a->compareDependency(*b); +- if (res != 0) return (res<0); ++ if (res != 0) return res; + return a->getId() < b->getId(); } + }; + +-- +2.47.1 +