Skip to contentSkip to conversation

build: Move TARGET_* assignments earlier

PATCH In review Matt Turner 4 participants 8 messages Feb 20, 2020 – Feb 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 build: Move TARGET_* assignments earlier

From: Mike Gilbert <[email protected]>

On a 32-bit SPARC userland, configure fails to compile assembly and the build fails:

checking for options to compile assembly... configure: error: could not compile assembly

config.log shows:

    asm-tests/sparc64.S: Assembler messages:
    asm-tests/sparc64.S:5: Error: Architecture mismatch on "lduw [%o4+4],%o4".
    asm-tests/sparc64.S:5: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
    asm-tests/sparc64.S:7: Error: Architecture mismatch on "stw %o5,[%o3]".
    asm-tests/sparc64.S:7: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
    asm-tests/sparc64.S:8: Error: Architecture mismatch on "bne,pt %icc,1b ,pt %icc,1b".
    asm-tests/sparc64.S:8: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)

Simply moving these blocks earlier in configure.ac is sufficient to ensure that the tests are executed with the appropriate flags (specifically -m64 in this case).

---
 configure.ac | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
configure.ac +18 -18
index e07ba4b56..b5e31c787 100644
@@ -562,6 +562,24 @@ CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"
 LIBS=""
 
+if test "x$target_m32" = x1; then
+  # Force 32-bit mode.
+  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
+  TARGET_MODULE_FORMAT="elf32"
+fi
+
+if test "x$target_m64" = x1; then
+  # Force 64-bit mode.
+  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
+  TARGET_MODULE_FORMAT="elf64"
+fi
+
 # debug flags.
 TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
@@ -750,24 +768,6 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
-if test "x$target_m32" = x1; then
-  # Force 32-bit mode.
-  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
-  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
-  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
-  TARGET_MODULE_FORMAT="elf32"
-fi
-
-if test "x$target_m64" = x1; then
-  # Force 64-bit mode.
-  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
-  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
-  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
-  TARGET_MODULE_FORMAT="elf64"
-fi
-
 if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
    TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
 fi
Signature · 1 line
2.24.1
#1 lore raw

PATCH 2/2 build: Disable PIE in TARGET_CCASFLAGS if needed

From: Mike Gilbert <[email protected]>

PIE should be disabled in assembly sources as well, or else grub will fail to boot.

---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)
configure.ac +1 -0
index b5e31c787..e2c783652 100644
@@ -1263,6 +1263,7 @@ grub_CHECK_LINK_PIE
 # `-fPIE' or '-fpie' and '-pie' in the default specs.
 if [ x"$pie_possible" = xyes ]; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -fno-PIE -fno-pie"
 fi
 
 if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then
Signature · 1 line
2.24.1
#2 lore raw

Re: [PATCH 2/2] build: Disable PIE in TARGET_CCASFLAGS if needed

Hi Mike!

Quoted 2 lines · Matt Turner

PIE should be disabled in assembly sources as well, or else grub will fail to boot.

Indeed. We have always passed -fno-PIE on Debian/sparc64 in the debian/rules file to TARGET_CCASFLAGS, but it makes more sense to fix the issue in the configure.ac.

Quoted 10 lines
---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)
configure.ac +0 -0
index b5e31c787..e2c783652 100644

configure.ac grub_CHECK_LINK_PIE · line 1269

Quoted 7 lines
configure.ac +1 -0
@@ -1263,6 +1263,7 @@ grub_CHECK_LINK_PIE
 # `-fPIE' or '-fpie' and '-pie' in the default specs.
 if [ x"$pie_possible" = xyes ]; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -fno-PIE -fno-pie"
 fi
 
 if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then

I have not verified yet that fix yet but it makes sense for the aforementioned reasons.

Thanks for fixing this.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
Reviewed-by on v1 1/2
#6 lore raw
In reply to Matt Turner

Adding John and Eric...

Quoted 17 lines · Matt Turner

From: Mike Gilbert <[email protected]>

On a 32-bit SPARC userland, configure fails to compile assembly and the build fails:

checking for options to compile assembly... configure: error: could not compile assembly

config.log shows:

    asm-tests/sparc64.S: Assembler messages:
    asm-tests/sparc64.S:5: Error: Architecture mismatch on "lduw [%o4+4],%o4".
    asm-tests/sparc64.S:5: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
    asm-tests/sparc64.S:7: Error: Architecture mismatch on "stw %o5,[%o3]".
    asm-tests/sparc64.S:7: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
    asm-tests/sparc64.S:8: Error: Architecture mismatch on "bne,pt %icc,1b ,pt %icc,1b".
    asm-tests/sparc64.S:8: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
Quoted 5 lines

Simply moving these blocks earlier in configure.ac is sufficient to ensure that the tests are executed with the appropriate flags (specifically -m64 in this case).

If there are no objections I will push these patches next week.

Daniel

Quoted 60 lines
---
 configure.ac | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
configure.ac +18 -19
index e07ba4b56..b5e31c787 100644
@@ -562,6 +562,24 @@ CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"
 LIBS=""
 
+if test "x$target_m32" = x1; then
+  # Force 32-bit mode.
+  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
+  TARGET_MODULE_FORMAT="elf32"
+fi
+
+if test "x$target_m64" = x1; then
+  # Force 64-bit mode.
+  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
+  TARGET_MODULE_FORMAT="elf64"
+fi
+
 # debug flags.
 TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
@@ -750,24 +768,6 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
-if test "x$target_m32" = x1; then
-  # Force 32-bit mode.
-  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
-  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
-  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
-  TARGET_MODULE_FORMAT="elf32"
-fi
-
-if test "x$target_m64" = x1; then
-  # Force 64-bit mode.
-  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
-  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
-  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
-  TARGET_MODULE_FORMAT="elf64"
-fi
-
 if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
    TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
 fi
--

2.24.1

Tested-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] build: Disable PIE in TARGET_CCASFLAGS if needed

In reply to Matt Turner
Quoted 16 lines · Matt Turner

From: Mike Gilbert <[email protected]>

PIE should be disabled in assembly sources as well, or else grub will fail to boot.

---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)
configure.ac +0 -0
index b5e31c787..e2c783652 100644

configure.ac grub_CHECK_LINK_PIE · line 1269

Quoted 7 lines
configure.ac +1 -0
@@ -1263,6 +1263,7 @@ grub_CHECK_LINK_PIE
 # `-fPIE' or '-fpie' and '-pie' in the default specs.
 if [ x"$pie_possible" = xyes ]; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -fno-PIE -fno-pie"
 fi
 
 if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then

This fixes the issue for me on sparc64 (Debian unstable).

Thanks,
Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
Tested-by on v1 1/2
#7 lore raw
In reply to Matt Turner
Quoted 71 lines · Matt Turner

From: Mike Gilbert <[email protected]>

On a 32-bit SPARC userland, configure fails to compile assembly and the build fails:

checking for options to compile assembly... configure: error: could not compile assembly

config.log shows:

    asm-tests/sparc64.S: Assembler messages:
    asm-tests/sparc64.S:5: Error: Architecture mismatch on "lduw [%o4+4],%o4".
    asm-tests/sparc64.S:5: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
    asm-tests/sparc64.S:7: Error: Architecture mismatch on "stw %o5,[%o3]".
    asm-tests/sparc64.S:7: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
    asm-tests/sparc64.S:8: Error: Architecture mismatch on "bne,pt %icc,1b ,pt %icc,1b".
    asm-tests/sparc64.S:8: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)

Simply moving these blocks earlier in configure.ac is sufficient to ensure that the tests are executed with the appropriate flags (specifically -m64 in this case).

---
 configure.ac | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
configure.ac +18 -11
index e07ba4b56..b5e31c787 100644
@@ -562,6 +562,24 @@ CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"
 LIBS=""
 
+if test "x$target_m32" = x1; then
+  # Force 32-bit mode.
+  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
+  TARGET_MODULE_FORMAT="elf32"
+fi
+
+if test "x$target_m64" = x1; then
+  # Force 64-bit mode.
+  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
+  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
+  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
+  TARGET_MODULE_FORMAT="elf64"
+fi
+
 # debug flags.
 TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
@@ -750,24 +768,6 @@ if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
 fi
 
-if test "x$target_m32" = x1; then
-  # Force 32-bit mode.
-  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
-  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
-  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
-  TARGET_MODULE_FORMAT="elf32"
-fi
-
-if test "x$target_m64" = x1; then
-  # Force 64-bit mode.

configure.ac if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then · line 773

Quoted 10 lines
configure.ac +0 -7
-  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
-  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
-  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
-  TARGET_MODULE_FORMAT="elf64"
-fi
-
 if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
    TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
 fi

While I cannot say whether this fixes the issue reported as we are building grub with a 64-bit SPARC userland, I can confirm that these changes don't break the build on sparc64.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
#4 lore raw

Re: [PATCH 2/2] build: Disable PIE in TARGET_CCASFLAGS if needed

In reply to Matt Turner

Dear Matt,

Thank you for upstreaming the patches.

Quoted 4 lines · Matt Turner

From: Mike Gilbert <[email protected]>

PIE should be disabled in assembly sources as well, or else grub will fail to boot.

Could you please extend this with the list, on what architectures it fails to boot? It seems to work on x86, doesn’t it?

Quoted 10 lines
---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)
configure.ac +0 -0
index b5e31c787..e2c783652 100644

configure.ac grub_CHECK_LINK_PIE · line 1269

Quoted 7 lines
configure.ac +1 -0
@@ -1263,6 +1263,7 @@ grub_CHECK_LINK_PIE
 # `-fPIE' or '-fpie' and '-pie' in the default specs.
 if [ x"$pie_possible" = xyes ]; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
+  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -fno-PIE -fno-pie"
 fi
 
 if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then

Kind regards,

Paul

#5 lore raw

Re: [PATCH 2/2] build: Disable PIE in TARGET_CCASFLAGS if needed

Quoted 5 lines · Paul Menzel
Quoted 2 lines

PIE should be disabled in assembly sources as well, or else grub will fail to boot.

Could you please extend this with the list, on what architectures it fails to boot? It seems to work on x86, doesn’t it?

This issue has been observed on SPARC only, correct. But it generally sense to include the no-PIE/no-pie flags in ASFLAGS as well.

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913