Skip to contentSkip to conversation

erofs-utils: Fix cross compile with autoconf

PATCH In review Sandeep Dhavale via Linux-erofs 2 participants 6 messages Oct 5, 2023 – Oct 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: Fix cross compile with autoconf

AC_RUN_IFELSE expects the action if cross compiling. If not provided cross compilation fails with error "configure: error: cannot run test program while cross compiling".
Use 4096 as the buest guess PAGESIZE if cross compiling as it is still the most common page size.

Reported-in: https://lore.kernel.org/all/0101018aec71b531-0a354b1a-0b70-47a1-8efc-fea8c439304c-000000@us-west-2.amazonses.com/

Fixes 8ee2e591dfd6 ("erofs-utils: support detecting maximum block size")
---
 configure.ac | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +2 -2
index 13ee616..a546310 100644
@@ -284,8 +284,8 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
     return 0;
 ]])],
                              [erofs_cv_max_block_size=`cat conftest.out`],
-                             [],
-                             []))
+                             [erofs_cv_max_block_size=4096],
+                             [erofs_cv_max_block_size=4096]))
 ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
 
 # Configure debug mode
Signature · 1 line
2.42.0.609.gbb76f46606-goog
#1 lore raw

Hi Sandeep!

Quoted 5 lines · Sandeep Dhavale

AC_RUN_IFELSE expects the action if cross compiling. If not provided cross compilation fails with error "configure: error: cannot run test program while cross compiling".
Use 4096 as the buest guess PAGESIZE if cross compiling as it is still the most common page size.

Thanks for your report!

Quoted 13 lines

Reported-in: https://lore.kernel.org/all/0101018aec71b531-0a354b1a-0b70-47a1-8efc-fea8c439304c-000000@us-west-2.amazonses.com/

Fixes 8ee2e591dfd6 ("erofs-utils: support detecting maximum block size")
---
  configure.ac | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
configure.ac +0 -0
index 13ee616..a546310 100644

configure.ac AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [ · line 289

Quoted 8 lines
configure.ac +2 -2
@@ -284,8 +284,8 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
      return 0;
  ]])],
                               [erofs_cv_max_block_size=`cat conftest.out`],
-                             [],
-                             []))
+                             [erofs_cv_max_block_size=4096],
+                             [erofs_cv_max_block_size=4096]))
  ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])

Actually the following check will reset erofs_cv_max_block_size to 4096 if needed. But it seems that it has syntax errors.

I wonder if the following diff could fix the issue too?

Thanks,
Gao Xiang

configure.ac +3 -3
index 13ee616..94eec01 100644
@@ -288,6 +288,9 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
                              []))
 ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
 
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],
+      [erofs_cv_max_block_size=4096], [])
+
 # Configure debug mode
 AS_IF([test "x$enable_debug" != "xno"], [], [
   dnl Turn off all assert checking.
@@ -501,9 +504,6 @@ if test "x$have_libdeflate" = "xyes"; then
 fi
 
 # Dump maximum block size
-AS_IF([test "x$erofs_cv_max_block_size" = "x"],
-      [$erofs_cv_max_block_size = 4096], [])
-
 AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
 		   [The maximum block size which erofs-utils supports])
#2 lore raw
Quoted 20 lines · Gao Xiang

Hi Sandeep!

Quoted 5 lines · Sandeep Dhavale

AC_RUN_IFELSE expects the action if cross compiling. If not provided cross compilation fails with error "configure: error: cannot run test program while cross compiling".
Use 4096 as the buest guess PAGESIZE if cross compiling as it is still the most common page size.

Thanks for your report!

Quoted 8 lines

Reported-in: https://lore.kernel.org/all/0101018aec71b531-0a354b1a-0b70-47a1-8efc-fea8c439304c-000000@us-west-2.amazonses.com/

Fixes 8ee2e591dfd6 ("erofs-utils: support detecting maximum block size")
---
  configure.ac | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines

configure.ac AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [ · line 289

Quoted 13 lines
configure.ac +2 -2
index 13ee616..a546310 100644
@@ -284,8 +284,8 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
      return 0;
  ]])],
                               [erofs_cv_max_block_size=`cat conftest.out`],
-                             [],
-                             []))
+                             [erofs_cv_max_block_size=4096],
+                             [erofs_cv_max_block_size=4096]))
  ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])

Actually the following check will reset erofs_cv_max_block_size to 4096 if needed. But it seems that it has syntax errors.

Hi Gao,
If I understand this correctly, the problem here is not having defined action if we are cross compiling for AC_RUN_IFELSE(). The cross compilation will fail until we have an action defined.

While at it I specified erofs_cv_max_block_size=4096 for the second action which will be the value if the test program fails to detect the page size.

With your suggested patch, cross compilation still fails with the error

Quoted 2 lines

configure: error: cannot run test program while cross compiling See `config.log' for more details

Thanks,
Sandeep.

Quoted 28 lines

I wonder if the following diff could fix the issue too?

Thanks,
Gao Xiang

configure.ac +3 -3
index 13ee616..94eec01 100644
@@ -288,6 +288,9 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
                               []))
  ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
 
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],
+      [erofs_cv_max_block_size=4096], [])
+
  # Configure debug mode
  AS_IF([test "x$enable_debug" != "xno"], [], [
    dnl Turn off all assert checking.
@@ -501,9 +504,6 @@ if test "x$have_libdeflate" = "xyes"; then
  fi
 
  # Dump maximum block size
-AS_IF([test "x$erofs_cv_max_block_size" = "x"],
-      [$erofs_cv_max_block_size = 4096], [])
-
  AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
                   [The maximum block size which erofs-utils supports])
#3 lore raw
Quoted 38 lines · Sandeep Dhavale
Quoted 20 lines · Gao Xiang

Hi Sandeep!

Quoted 5 lines · Sandeep Dhavale

AC_RUN_IFELSE expects the action if cross compiling. If not provided cross compilation fails with error "configure: error: cannot run test program while cross compiling".
Use 4096 as the buest guess PAGESIZE if cross compiling as it is still the most common page size.

Thanks for your report!

Quoted 8 lines

Reported-in: https://lore.kernel.org/all/0101018aec71b531-0a354b1a-0b70-47a1-8efc-fea8c439304c-000000@us-west-2.amazonses.com/

Fixes 8ee2e591dfd6 ("erofs-utils: support detecting maximum block size")
---
   configure.ac | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines

configure.ac AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [ · line 289

Quoted 13 lines
configure.ac +2 -2
index 13ee616..a546310 100644
@@ -284,8 +284,8 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
       return 0;
   ]])],
                                [erofs_cv_max_block_size=`cat conftest.out`],
-                             [],
-                             []))
+                             [erofs_cv_max_block_size=4096],
+                             [erofs_cv_max_block_size=4096]))
   ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])

Actually the following check will reset erofs_cv_max_block_size to 4096 if needed. But it seems that it has syntax errors.

Quoted 8 lines

Hi Gao,
If I understand this correctly, the problem here is not having defined action if we are cross compiling for AC_RUN_IFELSE(). The cross compilation will fail until we have an action defined.

While at it I specified erofs_cv_max_block_size=4096 for the second action which will be the value if the test program fails to detect the page size.

Oh, thanks! got it. How about updating erofs_cv_max_block_size to $MAX_BLOCK_SIZE first, and fallback to 4096 if MAX_BLOCK_SIZE is not defined? (We need to use $MAX_BLOCK_SIZE if defined anyway...)

I mean applying the following diff in addition to the previous diff too?

+ [erofs_cv_max_block_size=$MAX_BLOCK_SIZE],
+ [erofs_cv_max_block_size=$MAX_BLOCK_SIZE]))

    ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])

If it works, I could apply this version.

Thanks,
Gao Xiang

Quoted 36 lines

With your suggested patch, cross compilation still fails with the error

Quoted 2 lines

configure: error: cannot run test program while cross compiling See `config.log' for more details

Thanks,
Sandeep.

Quoted 28 lines

I wonder if the following diff could fix the issue too?

Thanks,
Gao Xiang

configure.ac +3 -3
index 13ee616..94eec01 100644
@@ -288,6 +288,9 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
                                []))
   ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
 
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],
+      [erofs_cv_max_block_size=4096], [])
+
   # Configure debug mode
   AS_IF([test "x$enable_debug" != "xno"], [], [
     dnl Turn off all assert checking.
@@ -501,9 +504,6 @@ if test "x$have_libdeflate" = "xyes"; then
   fi
 
   # Dump maximum block size
-AS_IF([test "x$erofs_cv_max_block_size" = "x"],
-      [$erofs_cv_max_block_size = 4096], [])
-
   AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
                    [The maximum block size which erofs-utils supports])
#4 lore raw
Quoted 58 lines · Gao Xiang
Quoted 38 lines · Sandeep Dhavale
Quoted 20 lines · Gao Xiang

Hi Sandeep!

Quoted 5 lines · Sandeep Dhavale

AC_RUN_IFELSE expects the action if cross compiling. If not provided cross compilation fails with error "configure: error: cannot run test program while cross compiling".
Use 4096 as the buest guess PAGESIZE if cross compiling as it is still the most common page size.

Thanks for your report!

Quoted 8 lines

Reported-in: https://lore.kernel.org/all/0101018aec71b531-0a354b1a-0b70-47a1-8efc-fea8c439304c-000000@us-west-2.amazonses.com/

Fixes 8ee2e591dfd6 ("erofs-utils: support detecting maximum block size")
---
   configure.ac | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 17 lines

configure.ac AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [ · line 289

Quoted 13 lines
configure.ac +2 -2
index 13ee616..a546310 100644
@@ -284,8 +284,8 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
       return 0;
   ]])],
                                [erofs_cv_max_block_size=`cat conftest.out`],
-                             [],
-                             []))
+                             [erofs_cv_max_block_size=4096],
+                             [erofs_cv_max_block_size=4096]))
   ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])

Actually the following check will reset erofs_cv_max_block_size to 4096 if needed. But it seems that it has syntax errors.

Quoted 8 lines

Hi Gao,
If I understand this correctly, the problem here is not having defined action if we are cross compiling for AC_RUN_IFELSE(). The cross compilation will fail until we have an action defined.

While at it I specified erofs_cv_max_block_size=4096 for the second action which will be the value if the test program fails to detect the page size.

Oh, thanks! got it. How about updating erofs_cv_max_block_size to $MAX_BLOCK_SIZE first, and fallback to 4096 if MAX_BLOCK_SIZE is not defined? (We need to use $MAX_BLOCK_SIZE if defined anyway...)

I mean applying the following diff in addition to the previous diff too?

Review

Quoted 3 lines
(quoted diff) +2 -0
+                             [erofs_cv_max_block_size=$MAX_BLOCK_SIZE],
+                             [erofs_cv_max_block_size=$MAX_BLOCK_SIZE]))
     ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])

Hi Gao,
That cannot work because AS_RUN_IFELSE() is only invoked if MAX_BLOCK_SIZE is not set.

# Detect maximum block size if necessary
AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [

    AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
                 AC_RUN_IFELSE([AC_LANG_PROGRAM(

[[
#include <unistd.h>
#include <stdio.h>
...

Cross compilation works if MAX_BLOCK_SIZE is set today as is without any fix. Cross compilation only fails when MAX_BLOCK_SIZE is not set AND the configure script tries to detect because there is no action defined regarding what should be erofs_cv_max_block_size.

Thanks,
Sandeep.

Quoted 41 lines

If it works, I could apply this version.

Thanks,
Gao Xiang

Quoted 36 lines

With your suggested patch, cross compilation still fails with the error

Quoted 2 lines

configure: error: cannot run test program while cross compiling See `config.log' for more details

Thanks,
Sandeep.

Quoted 28 lines

I wonder if the following diff could fix the issue too?

Thanks,
Gao Xiang

configure.ac +3 -3
index 13ee616..94eec01 100644
@@ -288,6 +288,9 @@ AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
                                []))
   ], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
 
+AS_IF([test "x$erofs_cv_max_block_size" = "x"],
+      [erofs_cv_max_block_size=4096], [])
+
   # Configure debug mode
   AS_IF([test "x$enable_debug" != "xno"], [], [
     dnl Turn off all assert checking.
@@ -501,9 +504,6 @@ if test "x$have_libdeflate" = "xyes"; then
   fi
 
   # Dump maximum block size
-AS_IF([test "x$erofs_cv_max_block_size" = "x"],
-      [$erofs_cv_max_block_size = 4096], [])
-
   AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
                    [The maximum block size which erofs-utils supports])
#5 lore raw

Hi Sandeep,

Quoted 1 line · Sandeep Dhavale

On Sat, Oct 7, 2023 at 1:25 AM Gao Xiang <[email protected]> wrote:

...

Quoted 12 lines
Quoted 1 line

Hi Gao,
That cannot work because AS_RUN_IFELSE() is only invoked if MAX_BLOCK_SIZE is not set.

   # Detect maximum block size if necessary
   AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
     AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
                  AC_RUN_IFELSE([AC_LANG_PROGRAM(
   [[
   #include <unistd.h>
   #include <stdio.h>
Quoted 6 lines

...

Cross compilation works if MAX_BLOCK_SIZE is set today as is without any fix. Cross compilation only fails when MAX_BLOCK_SIZE is not set AND the configure script tries to detect because there is no action defined regarding what should be erofs_cv_max_block_size.

Yes, I know MAX_BLOCK_SIZE is not set here. My only concern is that hardcoded 4096 is involved many times.

I've applied this original version. But I think we might need to clean up multiple 4096 later...

Thanks,
Gao Xiang

Quoted 3 lines

Thanks,
Sandeep.