[PATCH] Fix build of jitterentropy-base.c with clang

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Fix build of jitterentropy-base.c with clang

GnuPG - Libgcrypt - Dev mailing list
Clang has a slightly different pragma to disable optimizations.
---
 random/jitterentropy-base.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/random/jitterentropy-base.c b/random/jitterentropy-base.c
index 32fdea46..2c198ef5 100644
--- a/random/jitterentropy-base.c
+++ b/random/jitterentropy-base.c
@@ -50,6 +50,14 @@
  */
 
 #undef _FORTIFY_SOURCE
+#ifdef __clang__
+#pragma clang optimize off
+
+/* clang does not undefine the __OPTIMIZE__ macro after using the
+ * clang optimize off pragma, so the same __OPTIMIZE__ check below that
+ * is used for gcc won't work.
+ */
+#else
 #pragma GCC optimize ("O0")
 
 #include "jitterentropy.h"
@@ -60,6 +68,7 @@
   #error "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy-base.c."
  #endif
 #endif
+#endif
 
 #define MAJVERSION 2 /* API / ABI incompatible changes, functional changes that
       * require consumer to be updated (as long as this number
--
2.26.2


_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH] Fix build of jitterentropy-base.c with clang v2

GnuPG - Libgcrypt - Dev mailing list
Clang has a slightly different pragma to disable optimizations.

v2: Make sure jitterentropy.h is included when buiding with clang.
---
 random/jitterentropy-base.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/random/jitterentropy-base.c b/random/jitterentropy-base.c
index 32fdea46..cd5af22b 100644
--- a/random/jitterentropy-base.c
+++ b/random/jitterentropy-base.c
@@ -50,9 +50,16 @@
  */
 
 #undef _FORTIFY_SOURCE
+#ifdef __clang__
+#pragma clang optimize off
+
+/* clang does not undefine the __OPTIMIZE__ macro after using the
+ * clang optimize off pragma, so the same __OPTIMIZE__ check below that
+ * is used for gcc won't work.
+ */
+#else
 #pragma GCC optimize ("O0")
 
-#include "jitterentropy.h"
 
 #ifndef CONFIG_CRYPTO_CPU_JITTERENTROPY_STAT
  /* only check optimization in a compilation for real work */
@@ -60,6 +67,9 @@
   #error "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy-base.c."
  #endif
 #endif
+#endif
+
+#include "jitterentropy.h"
 
 #define MAJVERSION 2 /* API / ABI incompatible changes, functional changes that
       * require consumer to be updated (as long as this number
--
2.26.2


_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Fix build of jitterentropy-base.c with clang v2

GnuPG - Libgcrypt - Dev mailing list
Hi!

Thanbks for the patch.  However the problem is that it is too easy to
build with optimization - there really should be an #error in case
optimization is accidently enabled (broken pragma etc.).  Do you know a
macro or other mechanism in Clang so that we can check that optimization
has been disabled?


Shalom-Salam,

   Werner

--
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.

_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

signature.asc (233 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Fix build of jitterentropy-base.c with clang v2

GnuPG - Libgcrypt - Dev mailing list
On 8/3/20 2:35 AM, Werner Koch wrote:
> Hi!
>
> Thanbks for the patch.  However the problem is that it is too easy to
> build with optimization - there really should be an #error in case
> optimization is accidently enabled (broken pragma etc.).  Do you know a
> macro or other mechanism in Clang so that we can check that optimization
> has been disabled?
>

I don't know of any other way to check if optimizations are disabled.
Is the goal with the check to prevent someone accidentally removing the
pragma?

-Tom

>
> Shalom-Salam,
>
>     Werner
>


_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Fix build of jitterentropy-base.c with clang v2

Stephan Mueller
Am Montag, den 23.11.2020, 16:58 -0800 schrieb Tom Stellard via Gcrypt-devel:
> On 8/3/20 2:35 AM, Werner Koch wrote:
> > Hi!

Hi,

> >
> > Thanbks for the patch.  However the problem is that it is too easy to
> > build with optimization - there really should be an #error in case
> > optimization is accidently enabled (broken pragma etc.).  Do you know a
> > macro or other mechanism in Clang so that we can check that optimization
> > has been disabled?
> >
>
> I don't know of any other way to check if optimizations are disabled.
> Is the goal with the check to prevent someone accidentally removing the
> pragma?

Just as a side note: I am in the process of finishing up version 3.0 of the
Jitter RNG code base. This now is able to run with full optimizations and has
a fallback if no high-res timer is available.

It is also SP800-90B compliant.

Ciao
Stephan

>
> -Tom
>
> >
> > Shalom-Salam,
> >
> >     Werner
> >
>
>
> _______________________________________________
> Gcrypt-devel mailing list
> [hidden email]
> http://lists.gnupg.org/mailman/listinfo/gcrypt-devel



_______________________________________________
Gcrypt-devel mailing list
[hidden email]
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel