diff mbox series

toolchain/gcc: set dialects for each version

Message ID 20220125170204.2012249-1-stijn@linux-ipv6.be
State Rejected
Delegated to: Stijn Tintel
Headers show
Series toolchain/gcc: set dialects for each version | expand

Commit Message

Stijn Tintel Jan. 25, 2022, 5:02 p.m. UTC
GCC has an option "-std=" to set the language standard for C and C++.
Newer GCC versions sometimes switch to newer standards by default. This
has the potential to break the OpenWrt toolchain build whenever a distro
introduces a new GCC version that uses a newer dialect by default.

Let's set the default dialects used for each of the GCC versions we
support, to avoid these toolchain build failures in the future.

Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
---
 toolchain/gcc/common.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Rosen Penev Jan. 25, 2022, 10:20 p.m. UTC | #1
On Tue, Jan 25, 2022 at 9:06 AM Stijn Tintel <stijn@linux-ipv6.be> wrote:
>
> GCC has an option "-std=" to set the language standard for C and C++.
> Newer GCC versions sometimes switch to newer standards by default. This
> has the potential to break the OpenWrt toolchain build whenever a distro
> introduces a new GCC version that uses a newer dialect by default.
>
> Let's set the default dialects used for each of the GCC versions we
> support, to avoid these toolchain build failures in the future.
>
> Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
> ---
>  toolchain/gcc/common.mk | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/toolchain/gcc/common.mk b/toolchain/gcc/common.mk
> index bef4fa37f8..3e31a139cd 100644
> --- a/toolchain/gcc/common.mk
> +++ b/toolchain/gcc/common.mk
> @@ -29,14 +29,20 @@ PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
>  PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
>
>  ifeq ($(PKG_VERSION),8.4.0)
> +  C_DIALECT=-std=gnu17
> +  CXX_DIALECT=-std=gnu++14
>    PKG_HASH:=e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4
>  endif
>
>  ifeq ($(PKG_VERSION),10.3.0)
> +  C_DIALECT=-std=gnu17
> +  CXX_DIALECT=-std=gnu++14
>    PKG_HASH:=64f404c1a650f27fc33da242e1f2df54952e3963a49e06e73f6940f3223ac344
>  endif
>
>  ifeq ($(PKG_VERSION),11.2.0)
> +  C_DIALECT=-std=gnu17
> +  CXX_DIALECT=-std=gnu++17
I mentioned this on IRC. GCC8 is the first version to support
std=c++17. prereq-build says GCC6 which supports c++1z.
>    PKG_HASH:=d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b
>  endif
>
> @@ -86,6 +92,8 @@ GCC_CONFIGURE:= \
>                 CFLAGS="-O2 -fbracket-depth=512 -pipe" \
>                 CXXFLAGS="-O2 -fbracket-depth=512 -pipe" \
>         ) \
> +       CFLAGS="$(CFLAGS) $(C_DIALECT)" \
> +       CXXFLAGS="$(CXXFLAGS) $(CXX_DIALECT)" \
>         $(HOST_SOURCE_DIR)/configure \
>                 --with-bugurl=$(BUGURL) \
>                 --with-pkgversion="$(PKGVERSION)" \
> --
> 2.34.1
>
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Bas Mevissen Jan. 27, 2022, 6:10 p.m. UTC | #2
The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.

To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.
On 1/25/22 18:02, Stijn Tintel wrote:
> GCC has an option "-std=" to set the language standard for C and C++.
> Newer GCC versions sometimes switch to newer standards by default. This
> has the potential to break the OpenWrt toolchain build whenever a distro
> introduces a new GCC version that uses a newer dialect by default.
> 
> Let's set the default dialects used for each of the GCC versions we
> support, to avoid these toolchain build failures in the future.
> 

Shouldn't the logic be different? It is the software that is to be 
compiled that is written in a certain version or versions of C or C++ 
language.

OpenWRT should set a default C and C++ language version and packages or 
any other software compiled with the OpenWRT build should override it 
when they need it.

A package might for example define that they can be compiled with 
version C++11 to C++20 or require at least C++17 (and hence require a 
minimum GCC version).

How does this currently work? Are packages assumed to be compilable with 
the default C or C++ language version of the default (host or target) 
GCC version?

Regards,

Bas.


> Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
> ---
>   toolchain/gcc/common.mk | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/toolchain/gcc/common.mk b/toolchain/gcc/common.mk
> index bef4fa37f8..3e31a139cd 100644
> --- a/toolchain/gcc/common.mk
> +++ b/toolchain/gcc/common.mk
> @@ -29,14 +29,20 @@ PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
>   PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
>   
>   ifeq ($(PKG_VERSION),8.4.0)
> +  C_DIALECT=-std=gnu17
> +  CXX_DIALECT=-std=gnu++14
>     PKG_HASH:=e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4
>   endif
>   
>   ifeq ($(PKG_VERSION),10.3.0)
> +  C_DIALECT=-std=gnu17
> +  CXX_DIALECT=-std=gnu++14
>     PKG_HASH:=64f404c1a650f27fc33da242e1f2df54952e3963a49e06e73f6940f3223ac344
>   endif
>   
>   ifeq ($(PKG_VERSION),11.2.0)
> +  C_DIALECT=-std=gnu17
> +  CXX_DIALECT=-std=gnu++17
>     PKG_HASH:=d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b
>   endif
>   
> @@ -86,6 +92,8 @@ GCC_CONFIGURE:= \
>   		CFLAGS="-O2 -fbracket-depth=512 -pipe" \
>   		CXXFLAGS="-O2 -fbracket-depth=512 -pipe" \
>   	) \
> +	CFLAGS="$(CFLAGS) $(C_DIALECT)" \
> +	CXXFLAGS="$(CXXFLAGS) $(CXX_DIALECT)" \
>   	$(HOST_SOURCE_DIR)/configure \
>   		--with-bugurl=$(BUGURL) \
>   		--with-pkgversion="$(PKGVERSION)" \
Stijn Tintel Jan. 27, 2022, 10:11 p.m. UTC | #3
On 27/01/2022 20:10, Bas Mevissen via openwrt-devel wrote:
>
> On 1/25/22 18:02, Stijn Tintel wrote:
>> GCC has an option "-std=" to set the language standard for C and C++.
>> Newer GCC versions sometimes switch to newer standards by default. This
>> has the potential to break the OpenWrt toolchain build whenever a distro
>> introduces a new GCC version that uses a newer dialect by default.
>>
>> Let's set the default dialects used for each of the GCC versions we
>> support, to avoid these toolchain build failures in the future.
>>
>
> Shouldn't the logic be different? It is the software that is to be
> compiled that is written in a certain version or versions of C or C++
> language.

In OpenWiFi we unfortunately use QSDK for the ipq6xxx/ipq8xxx platforms.
This comes with ancient GCC 5, which doesn't build on GCC 11, because
GCC 11 uses -std=gnu++17, causing this problem:

|/home/stijn/Development/TIP/wlan-ap/openwrt/build_dir/toolchain-arm_cortex-a7_gcc-5.5.0_musl_eabi/gcc-5.5.0/gcc/reload1.c:
In function 'void init_reload()':
||/home/stijn/Development/TIP/wlan-ap/openwrt/build_dir/toolchain-arm_cortex-a7_gcc-5.5.0_musl_eabi/gcc-5.5.0/gcc/reload1.c:115:24:
error: use of an operand of type 'bool' in 'operator++' is forbidden in
C++17 ||115 | (this_target_reload->x_spill_indirect_levels) |||
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~|

|Setting the dialects to build GCC 5, to the default dialect used by GCC
5, avoids this problem. However, since QSDK is obviously completely
irrelevant for OpenWrt, I tried finding a general way of avoiding these
kinds of problems. Setting the default dialects would avoid the same
problem in the future, e.g. once GCC 13 forbids some syntax that is used
in some of the GCC versions we still support.|

|Anyway, downstream answer was "won't fix, build on Ubuntu 20.04", so
I'm going to mark this patch as rejected and not waste any more time on it.|

|Stijn |
diff mbox series

Patch

diff --git a/toolchain/gcc/common.mk b/toolchain/gcc/common.mk
index bef4fa37f8..3e31a139cd 100644
--- a/toolchain/gcc/common.mk
+++ b/toolchain/gcc/common.mk
@@ -29,14 +29,20 @@  PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 
 ifeq ($(PKG_VERSION),8.4.0)
+  C_DIALECT=-std=gnu17
+  CXX_DIALECT=-std=gnu++14
   PKG_HASH:=e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4
 endif
 
 ifeq ($(PKG_VERSION),10.3.0)
+  C_DIALECT=-std=gnu17
+  CXX_DIALECT=-std=gnu++14
   PKG_HASH:=64f404c1a650f27fc33da242e1f2df54952e3963a49e06e73f6940f3223ac344
 endif
 
 ifeq ($(PKG_VERSION),11.2.0)
+  C_DIALECT=-std=gnu17
+  CXX_DIALECT=-std=gnu++17
   PKG_HASH:=d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b
 endif
 
@@ -86,6 +92,8 @@  GCC_CONFIGURE:= \
 		CFLAGS="-O2 -fbracket-depth=512 -pipe" \
 		CXXFLAGS="-O2 -fbracket-depth=512 -pipe" \
 	) \
+	CFLAGS="$(CFLAGS) $(C_DIALECT)" \
+	CXXFLAGS="$(CXXFLAGS) $(CXX_DIALECT)" \
 	$(HOST_SOURCE_DIR)/configure \
 		--with-bugurl=$(BUGURL) \
 		--with-pkgversion="$(PKGVERSION)" \