]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Provide cmake test if alignment requirement is strict
authorVitaly Chikunov <vt@altlinux.org>
Thu, 17 Sep 2020 22:47:27 +0000 (01:47 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Fri, 18 Sep 2020 13:25:44 +0000 (16:25 +0300)
This is based on AX_CHECK_ALIGNED_ACCESS_REQUIRED from autoconf-archive.

Note, that on some arches unaligned access behavior could be changed at
runtime via prctl(1). Also, unaligned memory access is still slower (and
very slow on some arches) even if it's not strictly required.

CMakeLists.txt

index 1d4d65b86de17edf15ba656cb0b8dab578af5487..3b8891d0f991abba849721f6453bed81c0eed36d 100644 (file)
@@ -66,6 +66,18 @@ if (ADDCARRY_U64)
   add_definitions(-DHAVE_ADDCARRY_U64)
 endif()
 
+check_c_source_runs("
+  int main(void) {
+    char buf[16] = { 0, 1, 2 };
+    int *p = buf + 1;
+    int *q = buf + 2;
+    return (*p == *q);
+  }
+  " RELAXED_ALIGNMENT)
+if (NOT RELAXED_ALIGNMENT)
+  add_definitions(-DSTRICT_ALIGNMENT)
+endif()
+
 set(BIN_DIRECTORY bin)
 
 # Same soversion as OpenSSL