← Back to team overview

maria-developers team mailing list archive

Re: crosscompiling in buildroot: cannot find -laio and other link error

 

Hi Sergei!

Thanks for your help.

On 01/10/15 16:16, Sergei Golubchik wrote:
> Why would you build host variant for ha_connect.so with the library
> paths for the target architecture? 

I don't actually, I don't know why this happened.

> How do you invoke cmake?

In my case cmake is invoked by buildroot. I passed a number of options
for disabling some modules or working with galera:

-DWITH_WSREP=1
-DWITH_INNODB_DISALLOW_WRITES=1
-DWITH_UNIT_TESTS=0
-DGRN_WITH_MESSAGE_PACK=0
-DWITHOUT_MROONGA=1
-DWITHOUT_XTRADB=1
-DWITH_JEMALLOC=0
-DWITHOUT_TOKUDB=1
-DSTACK_DIRECTION=-1

But then buildroot adds some more magic concerning the toolchain. But...:

> Did you check
> https://mariadb.com/kb/en/mariadb/cross-compiling-mariadb/ ? Regards,
> Sergei 

Ooops. For some reason I completely missed this page. Building only the
host variant of  import_executables target eases cross-compilation a lot
indeed... and fixes my problems.

Appart from that I had figured most of this out, or buildroot was taking
care of it. I still have a remark: I don't think I can hardcode the
value of HAVE_IB_GCC_ATOMIC_BUILTINS as suggested in
https://lists.launchpad.net/maria-discuss/msg02911.html because if I
want this package accepted in buildroot it must build on all kind of
architectures. Therefore:

1. I disabled building xtradb. I also had to patch
storage/xtradb/CMakeLists.txt (patch attached) otherwise XTRADB_OK=0
would abort the build even if the module is not requested.

2. I patched storage/innobase/CMakeLists.txt (also attached) in order to
use CHECK_C_SOURCE_COMPILES instead of CHECK_C_SOURCE_RUNS, which fails
when cross compiling.

I'd be happy to have your opinion on these patches.

However, I'm currently investigating whether or not the value of
HAVE_IB_GCC_ATOMIC_BUILTINS could be guessed from that of
BR2_ARCH_HAS_ATOMICS.

Cheers,

-- 
Sylvain Raybaud
www.green-communications.fr

Use CHECK_C_SOURCE_COMPILES instead of CHECK_C_SOURCE_RUNS in order to be
cross-compile friendly.
In buildroot another solution (maybe better, maybe not) could be to use
BR2_ARCH_HAS_ATOMICS in order to determine the value of HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
and likes.

--- a/storage/innobase/CMakeLists.txt	2014-11-07 17:05:48.853208487 +0100
+++ b/storage/innobase/CMakeLists.txt	2014-11-07 17:11:38.061217839 +0100
@@ -58,100 +58,99 @@
 
 IF(NOT MSVC)
 # either define HAVE_IB_GCC_ATOMIC_BUILTINS or not
-IF(NOT CMAKE_CROSSCOMPILING)
-  # workaround for gcc 4.1.2 RHEL5/x86, gcc atomic ops only work under -march=i686
-  IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
-     CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3")
-    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
-    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
-  ENDIF()
-  CHECK_C_SOURCE_RUNS(
-  "
-  int main()
-  {
-    long	x;
-    long	y;
-    long	res;
-
-    x = 10;
-    y = 123;
-    res = __sync_bool_compare_and_swap(&x, x, y);
-    if (!res || x != y) {
-      return(1);
-    }
-
-    x = 10;
-    y = 123;
-    res = __sync_bool_compare_and_swap(&x, x + 1, y);
-    if (res || x != 10) {
-      return(1);
-    }
-    x = 10;
-    y = 123;
-    res = __sync_add_and_fetch(&x, y);
-    if (res != 123 + 10 || x != 123 + 10) {
-      return(1);
-    }
-    return(0);
-  }"
-  HAVE_IB_GCC_ATOMIC_BUILTINS
-  )
-  CHECK_C_SOURCE_RUNS(
-  "
-  int main()
-  {
-    long	res;
-    char	c;
-
-    c = 10;
-    res = __sync_lock_test_and_set(&c, 123);
-    if (res != 10 || c != 123) {
-      return(1);
-    }
-    return(0);
-  }"
-  HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
-  )
-  CHECK_C_SOURCE_RUNS(
-  "#include<stdint.h>
-  int main()
-  {
-    int64_t	x,y,res;
-
-    x = 10;
-    y = 123;
-    res = __sync_sub_and_fetch(&y, x);
-    if (res != y || y != 113) {
-      return(1);
-    }
-    res = __sync_add_and_fetch(&y, x);
-    if (res != y || y != 123) {
-      return(1);
-    }
-    return(0);
-  }"
-  HAVE_IB_GCC_ATOMIC_BUILTINS_64
-  )
-  CHECK_C_SOURCE_RUNS(
-  "#include<stdint.h>
-  int main()
-  {
-    __sync_synchronize();
-    return(0);
-  }"
-  HAVE_IB_GCC_SYNC_SYNCHRONISE
-  )
-  CHECK_C_SOURCE_RUNS(
-  "#include<stdint.h>
-  int main()
-  {
-    __atomic_thread_fence(__ATOMIC_ACQUIRE);
-    __atomic_thread_fence(__ATOMIC_RELEASE);
-    return(0);
-  }"
-  HAVE_IB_GCC_ATOMIC_THREAD_FENCE
-  )
-ENDIF()
+
+# workaround for gcc 4.1.2 RHEL5/x86, gcc atomic ops only work under -march=i686
+IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" AND CMAKE_COMPILER_IS_GNUCC AND
+   CMAKE_C_COMPILER_VERSION VERSION_LESS "4.1.3")
+  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686")
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
+ENDIF()
+CHECK_C_SOURCE_COMPILES(
+"
+int main()
+{
+  long	x;
+  long	y;
+  long	res;
+
+  x = 10;
+  y = 123;
+  res = __sync_bool_compare_and_swap(&x, x, y);
+  if (!res || x != y) {
+    return(1);
+  }
+
+  x = 10;
+  y = 123;
+  res = __sync_bool_compare_and_swap(&x, x + 1, y);
+  if (res || x != 10) {
+    return(1);
+  }
+  x = 10;
+  y = 123;
+  res = __sync_add_and_fetch(&x, y);
+  if (res != 123 + 10 || x != 123 + 10) {
+    return(1);
+  }
+  return(0);
+}"
+HAVE_IB_GCC_ATOMIC_BUILTINS
+)
+CHECK_C_SOURCE_COMPILES(
+"
+int main()
+{
+  long	res;
+  char	c;
+
+  c = 10;
+  res = __sync_lock_test_and_set(&c, 123);
+  if (res != 10 || c != 123) {
+    return(1);
+  }
+  return(0);
+}"
+HAVE_IB_GCC_ATOMIC_BUILTINS_BYTE
+)
+CHECK_C_SOURCE_COMPILES(
+"#include<stdint.h>
+int main()
+{
+  int64_t	x,y,res;
+
+  x = 10;
+  y = 123;
+  res = __sync_sub_and_fetch(&y, x);
+  if (res != y || y != 113) {
+    return(1);
+  }
+  res = __sync_add_and_fetch(&y, x);
+  if (res != y || y != 123) {
+    return(1);
+  }
+  return(0);
+}"
+HAVE_IB_GCC_ATOMIC_BUILTINS_64
+)
+CHECK_C_SOURCE_COMPILES(
+"#include<stdint.h>
+int main()
+{
+  __sync_synchronize();
+  return(0);
+}"
+HAVE_IB_GCC_SYNC_SYNCHRONISE
+)
+CHECK_C_SOURCE_COMPILES(
+"#include<stdint.h>
+int main()
+{
+  __atomic_thread_fence(__ATOMIC_ACQUIRE);
+  __atomic_thread_fence(__ATOMIC_RELEASE);
+return(0);
+}"
+HAVE_IB_GCC_ATOMIC_THREAD_FENCE
+)
 
 IF(HAVE_IB_GCC_ATOMIC_BUILTINS)
  ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_BUILTINS=1)
@@ -173,28 +172,26 @@
  ADD_DEFINITIONS(-DHAVE_IB_GCC_ATOMIC_THREAD_FENCE=1)
 ENDIF()
 
- # either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
-IF(NOT CMAKE_CROSSCOMPILING)
-  CHECK_C_SOURCE_RUNS(
-  "
-  #include <pthread.h>
-  #include <string.h>
-
-  int main() {
-    pthread_t       x1;
-    pthread_t       x2;
-    pthread_t       x3;
-
-    memset(&x1, 0x0, sizeof(x1));
-    memset(&x2, 0x0, sizeof(x2));
-    memset(&x3, 0x0, sizeof(x3));
-
-    __sync_bool_compare_and_swap(&x1, x2, x3);
-
-    return(0);
-  }"
-  HAVE_IB_ATOMIC_PTHREAD_T_GCC)
-ENDIF()
+# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not
+CHECK_C_SOURCE_COMPILES(
+"
+#include <pthread.h>
+#include <string.h>
+
+int main() {
+  pthread_t       x1;
+  pthread_t       x2;
+  pthread_t       x3;
+
+  memset(&x1, 0x0, sizeof(x1));
+  memset(&x2, 0x0, sizeof(x2));
+  memset(&x3, 0x0, sizeof(x3));
+  __sync_bool_compare_and_swap(&x1, x2, x3);
+
+  return(0);
+}"
+HAVE_IB_ATOMIC_PTHREAD_T_GCC)
+
 IF(HAVE_IB_ATOMIC_PTHREAD_T_GCC)
   ADD_DEFINITIONS(-DHAVE_IB_ATOMIC_PTHREAD_T_GCC=1)
 ENDIF()
--- a/storage/xtradb/CMakeLists.txt.orig	2015-10-02 17:20:37.342468629 +0200
+++ b/storage/xtradb/CMakeLists.txt	2015-10-02 17:21:12.246469563 +0200
@@ -480,12 +480,13 @@
   SET(WITH_INNOBASE_STORAGE_ENGINE TRUE)
 ENDIF()
 
-IF(XTRADB_OK)
-  MYSQL_ADD_PLUGIN(xtradb ${INNOBASE_SOURCES} STORAGE_ENGINE
-    DEFAULT
-    RECOMPILE_FOR_EMBEDDED
-    LINK_LIBRARIES ${ZLIB_LIBRARY} ${LINKER_SCRIPT})
-ELSE()
-  MESSAGE(FATAL_ERROR "Percona XtraDB is not supported on this platform")
+IF(NOT WITHOUT_XTRADB)
+  IF(XTRADB_OK)
+	MYSQL_ADD_PLUGIN(xtradb ${INNOBASE_SOURCES} STORAGE_ENGINE
+	  DEFAULT
+	  RECOMPILE_FOR_EMBEDDED
+	  LINK_LIBRARIES ${ZLIB_LIBRARY} ${LINKER_SCRIPT})
+  ELSE()
+	MESSAGE(FATAL_ERROR "Percona XtraDB is not supported on this platform")
+  ENDIF()
 ENDIF()
-

Follow ups

References