Skip to contentSkip to conversation

package/gmp: fix target build with host gcc 4.9

PATCH Superseded Brandon Maier via buildroot 2 participants 6 messages Mar 12, 2024 – Mar 25, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/gmp: fix target build with host gcc 4.9

GMP does not build if the host gcc is v4.9 due to the following error

gen-sieve.c: In function 'setmask':
gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode

     for (unsigned i = 0; i < 2 * a * b; ++i)
     ^

gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

The gen-sieve utility was added in GMP v6.3.0. It is built using CC_FOR_BUILD (host compiler) during cross compilation as it generates build files. Autoconf does not have a macro for add -std=c99 to CC_FOR_BUILD, so it must be set manually.

---
 package/gmp/gmp.mk | 5 +++++
 1 file changed, 5 insertions(+)
package/gmp/gmp.mk +5 -0
index bd401c6a80..85836a8c72 100644
@@ -14,6 +14,11 @@ GMP_CPE_ID_VENDOR = gmplib
 GMP_DEPENDENCIES = host-m4
 HOST_GMP_DEPENDENCIES = host-m4
 
+# The compiler for build requires C99 but GCC 4.9 defaults to C89
+ifeq ($(BR2_HOST_GCC_AT_LEAST_5),)
+GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"
+endif
+
 # GMP doesn't support assembly for coldfire or mips r6 ISA yet
 # Disable for ARM v7m since it has different asm constraints
 ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)
Signature · 6 lines
2.44.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 1 line · Brandon Maier via buildroot

GMP does not build if the host gcc is v4.9 due to the following error

Oh boy, are you still using host GCC 4.9? Poor man...

Quoted 22 lines

gen-sieve.c: In function 'setmask':
gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode

      for (unsigned i = 0; i < 2 * a * b; ++i)
      ^

gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

The gen-sieve utility was added in GMP v6.3.0. It is built using CC_FOR_BUILD (host compiler) during cross compilation as it generates build files. Autoconf does not have a macro for add -std=c99 to CC_FOR_BUILD, so it must be set manually.

---
  package/gmp/gmp.mk | 5 +++++
  1 file changed, 5 insertions(+)
package/gmp/gmp.mk +0 -0
index bd401c6a80..85836a8c72 100644

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 17

Quoted 4 lines
package/gmp/gmp.mk +1 -0
@@ -14,6 +14,11 @@ GMP_CPE_ID_VENDOR = gmplib
  GMP_DEPENDENCIES = host-m4
  HOST_GMP_DEPENDENCIES = host-m4
 
+# The compiler for build requires C99 but GCC 4.9 defaults to C89

I don't think the comment is really needed.

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 18

Quoted 1 line
package/gmp/gmp.mk +1 -0
+ifeq ($(BR2_HOST_GCC_AT_LEAST_5),)

In all the other places where we pass -std=c99, we do that unconditionally. So
I'd do the same here.

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 19

Quoted 1 line
package/gmp/gmp.mk +1 -0
+GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"

Don't you need something similar for host-gmp as well? All the rest I could
have fixed up while applying, but I don't have a host gcc 4.9 with which to test host-gmp :-)

Regards,
Arnout

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 24

Quoted 5 lines
package/gmp/gmp.mk +2 -0
+endif
+
  # GMP doesn't support assembly for coldfire or mips r6 ISA yet
  # Disable for ARM v7m since it has different asm constraints
  ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw

Hi Arnout,

Quoted 11 lines

-----Original Message-----
From: Arnout Vandecappelle <[email protected]>
Sent: Friday, March 15, 2024 3:44 PM
To: Maier, Brandon Collins <[email protected]>; [email protected]
Cc: Thomas Petazzoni <[email protected]>
Subject: [External] Re: [Buildroot] [PATCH 1/1] package/gmp: fix target build with host gcc 4.9

Quoted 4 lines
Quoted 1 line · Brandon Maier via buildroot

GMP does not build if the host gcc is v4.9 due to the following error

Oh boy, are you still using host GCC 4.9? Poor man...

Yeah, it's not great

Quoted 34 lines
Quoted 4 lines

gen-sieve.c: In function 'setmask':
gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or

C11 mode

Quoted 3 lines
      for (unsigned i = 0; i < 2 * a * b; ++i)
      ^

gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -

std=gnu11 to compile your code

Quoted 16 lines

The gen-sieve utility was added in GMP v6.3.0. It is built using CC_FOR_BUILD (host compiler) during cross compilation as it generates build files. Autoconf does not have a macro for add -std=c99 to CC_FOR_BUILD, so it must be set manually.

---
  package/gmp/gmp.mk | 5 +++++
  1 file changed, 5 insertions(+)
package/gmp/gmp.mk +0 -0
index bd401c6a80..85836a8c72 100644

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 17

Quoted 4 lines
package/gmp/gmp.mk +1 -0
@@ -14,6 +14,11 @@ GMP_CPE_ID_VENDOR = gmplib
  GMP_DEPENDENCIES = host-m4
  HOST_GMP_DEPENDENCIES = host-m4
 
+# The compiler for build requires C99 but GCC 4.9 defaults to C89

I don't think the comment is really needed.

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 18

Quoted 1 line
package/gmp/gmp.mk +1 -0
+ifeq ($(BR2_HOST_GCC_AT_LEAST_5),)
Quoted 8 lines

In all the other places where we pass -std=c99, we do that unconditionally. So
I'd do the same here.

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 19

Quoted 1 line
package/gmp/gmp.mk +1 -0
+GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"

Don't you need something similar for host-gmp as well? All the rest I could
have fixed up while applying, but I don't have a host gcc 4.9 with which to test host-gmp :-)

The issue only occurs when cross-compiling because Autoconf does not set -std=c99 for the host compiler. When host compiling, Autoconf uses the same compiler for target as host, and target it does correctly enable -std=c99 using AC_PROG_CC_C99. As far as I could find, there is no AC_PROG_CC_C99 equivalent for the host compiler.

That's my understanding anyway, I have very little experience dealing with Autotools.

Agree with the other comments, I can resend with those fixed.

Thanks,
Brandon
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

PATCH v2 1/1 package/gmp: fix target build with host gcc 4.9

In reply to Brandon Maier via buildroot

GMP does not build if the host gcc is v4.9 due to the following error

gen-sieve.c: In function 'setmask':
gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode

     for (unsigned i = 0; i < 2 * a * b; ++i)
     ^

gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

The gen-sieve utility was added in GMP v6.3.0. It is built using CC_FOR_BUILD (host compiler) during cross compilation as it generates build files. Autoconf does not have a macro for add -std=c99 to CC_FOR_BUILD, so it must be set manually.

---
v1: https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

v2:
- remove unnecessary comment and ifdef check

---
 package/gmp/gmp.mk | 2 ++
 1 file changed, 2 insertions(+)
package/gmp/gmp.mk +2 -0
index bd401c6a80..7e8da9025c 100644
@@ -14,6 +14,8 @@ GMP_CPE_ID_VENDOR = gmplib
 GMP_DEPENDENCIES = host-m4
 HOST_GMP_DEPENDENCIES = host-m4
 
+GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"
+
 # GMP doesn't support assembly for coldfire or mips r6 ISA yet
 # Disable for ARM v7m since it has different asm constraints
 ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)
Signature · 6 lines
2.44.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Hi Brandon,

Quoted 4 lines · Brandon Maier

GMP does not build if the host gcc is v4.9 due to the following error

gen-sieve.c: In function 'setmask':
gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode

Quoted 8 lines
      for (unsigned i = 0; i < 2 * a * b; ++i)
      ^

gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

The gen-sieve utility was added in GMP v6.3.0. It is built using CC_FOR_BUILD (host compiler) during cross compilation as it generates build files. Autoconf does not have a macro for add -std=c99 to CC_FOR_BUILD, so it must be set manually.

I've added the explanation you gave why this is not needed for the target.

Applied to master, thanks.

Regards,
Arnout

Quoted 16 lines

---
v1: https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

v2:
- remove unnecessary comment and ifdef check

---
  package/gmp/gmp.mk | 2 ++
  1 file changed, 2 insertions(+)
package/gmp/gmp.mk +0 -0
index bd401c6a80..7e8da9025c 100644

package/gmp/gmp.mk GMP_CPE_ID_VENDOR = gmplib · line 21

Quoted 8 lines
package/gmp/gmp.mk +2 -0
@@ -14,6 +14,8 @@ GMP_CPE_ID_VENDOR = gmplib
  GMP_DEPENDENCIES = host-m4
  HOST_GMP_DEPENDENCIES = host-m4
 
+GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"
+
  # GMP doesn't support assembly for coldfire or mips r6 ISA yet
  # Disable for ARM v7m since it has different asm constraints
  ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#5 lore raw
In reply to Brandon Maier via buildroot
Quoted 14 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Brandon" == Brandon Maier via buildroot <[email protected]> writes:

GMP does not build if the host gcc is v4.9 due to the following error
gen-sieve.c: In function 'setmask':
gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode

     for (unsigned i = 0; i < 2 * a * b; ++i)
     ^

gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

The gen-sieve utility was added in GMP v6.3.0. It is built using CC_FOR_BUILD (host compiler) during cross compilation as it generates build files. Autoconf does not have a macro for add -std=c99 to CC_FOR_BUILD, so it must be set manually.

Quoted 6 lines

---
v1: https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/

v2:
- remove unnecessary comment and ifdef check

Committed to 2024.02.x and 2023.11.x, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot