From patchwork Wed Jan 28 05:05:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David 'equinox' Lamparter X-Patchwork-Id: 2190040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=WSYpH2zT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4f1RyM56Dsz1xqm for ; Thu, 29 Jan 2026 03:08:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wxZ9CAg/3O84UmseTByFbpAOFIeoD4r5U5w/hfEtkBQ=; b=WSYpH2zT71uSqb UYrdg1Z4K5xR7AAQHFTu8iJuYH4H59Rnz9x2kYTmoOaOxMJufA+0Vs6paUUP/fksvvsX0QOm7kr9P ocdgoCWwfGV1FO8JUEUbkxG9+K/IqylmZpxLYu4akFj+bQIdATyjmVj3kG43JBCclymcjdrD0DqIw 8NO5OTygYL8y8F90Z9zN1cmVJLjCeuU3PQjI9MQrVnzySHGzsqiQ5zYkmtdiZzd3WAFH/YA4IRf23 r7WQz1AwFYHhPIbwGj6PIy/pfmplR2//y6/U5LcR1l/inv3J2jQeyWS52ULeDqsbGcY2zJxpR0+2W ypFRpPwtF5DxTGip7gYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vl83U-0000000GLK2-0G2F; Wed, 28 Jan 2026 16:06:08 +0000 Received: from eidolon.nox.tf ([2a07:2ec0:2185::]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vl83R-0000000GLJI-0r4U for openwrt-devel@lists.openwrt.org; Wed, 28 Jan 2026 16:06:06 +0000 Received: from equinox by eidolon.nox.tf with local (Exim 4.98.2) (envelope-from ) id 1vl83P-00000003JqJ-2TBU; Wed, 28 Jan 2026 17:06:03 +0100 From: David 'equinox' Lamparter To: openwrt-devel@lists.openwrt.org Cc: David 'equinox' Lamparter Subject: [PATCH] toolchain: gcc: MIPS: fix emitted .size for VLAs Date: Wed, 28 Jan 2026 17:05:49 +0100 Message-ID: <20260128160554.791201-1-equinox@diac24.net> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260128_080605_403394_9511C926 X-CRM114-Status: GOOD ( 17.65 ) X-Spam-Score: -1.9 (-) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From the patch files: GCC was emitting the size of the constant part of VLA structures, e.g. something like: struct foo { int a, b[]; } bar = { 1, { 2, 3, 4 } }; Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From the patch files: GCC was emitting the size of the constant part of VLA structures, e.g. something like: struct foo { int a, b[]; } bar = { 1, { 2, 3, 4 } }; Would get a .size 4 (for a), rather than 16 (a, and 3 items in b). This doesn't immediately break things, but one case where it matters is when the object is in a shared library and the linker creates a copy relocation - it'll only copy the first part of whatever we're looking at. Use the size of the decl (which will include the variable part) rather than the type (which has no idea what is about to be set up in terms of content) - same as all the other architectures. The "new" code in fact comes from gcc/config/elfos.h. References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102298 Signed-off-by: David 'equinox' Lamparter --- (dup of https://github.com/openwrt/openwrt/pull/21753) Tested on 25.12 on an TP-Link EAP-615-Wall; fixes the FRR problem and doesn't seem to cause any ill effect. --- ...tted-size-for-variably-sized-objects.patch | 64 +++++++++++++++++++ ...tted-size-for-variably-sized-objects.patch | 64 +++++++++++++++++++ ...tted-size-for-variably-sized-objects.patch | 64 +++++++++++++++++++ ...tted-size-for-variably-sized-objects.patch | 64 +++++++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 toolchain/gcc/patches-12.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch create mode 100644 toolchain/gcc/patches-13.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch create mode 100644 toolchain/gcc/patches-14.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch create mode 100644 toolchain/gcc/patches-15.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch diff --git a/toolchain/gcc/patches-12.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch b/toolchain/gcc/patches-12.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch new file mode 100644 index 000000000000..2371f4f044cd --- /dev/null +++ b/toolchain/gcc/patches-12.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch @@ -0,0 +1,64 @@ +From 3cbfc5374bc48494db3308eb1d0ef293f9f7b5e8 Mon Sep 17 00:00:00 2001 +From: David Lamparter +Date: Wed, 28 Jan 2026 16:29:06 +0100 +Subject: [PATCH] MIPS: fix emitted .size for variably sized objects + +GCC was emitting the size of the constant part of VLA structures, e.g. +something like: + + struct foo { + int a, b[]; + } bar = { 1, { 2, 3, 4 } }; + +Would get a .size 4 (for a), rather than 16 (a, and 3 items in b). This +doesn't immediately break things, but one case where it matters is when +the object is in a shared library and the linker creates a copy +relocation - it'll only copy the first part of whatever we're looking +at. + +Use the size of the decl (which will include the variable part) rather +than the type (which has no idea what is about to be set up in terms of +content) - same as all the other architectures. The "new" code in fact +comes from gcc/config/elfos.h. + +References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102298 +Cc: Andrew Pinski +Signed-off-by: David Lamparter +--- + gcc/config/mips/mips.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc +index d26630b20cef..163cc30c6f10 100644 +--- a/gcc/config/mips/mips.cc ++++ b/gcc/config/mips/mips.cc +@@ -9581,7 +9581,7 @@ mips_output_external (FILE *file, tree decl, const char *name) + fputs ("\t.extern\t", file); + assemble_name (file, name); + fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n", +- int_size_in_bytes (TREE_TYPE (decl))); ++ tree_to_uhwi (DECL_SIZE_UNIT (decl))); + } + } + } +@@ -9895,7 +9895,7 @@ mips_declare_object_name (FILE *stream, const char *name, + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + +@@ -9920,7 +9920,7 @@ mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end) + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + } +-- +2.52.0 + diff --git a/toolchain/gcc/patches-13.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch b/toolchain/gcc/patches-13.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch new file mode 100644 index 000000000000..2bff4d21badc --- /dev/null +++ b/toolchain/gcc/patches-13.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch @@ -0,0 +1,64 @@ +From e49eff5fc806e255028510de55d8d8ccac1dc99b Mon Sep 17 00:00:00 2001 +From: David Lamparter +Date: Wed, 28 Jan 2026 16:29:06 +0100 +Subject: [PATCH] MIPS: fix emitted .size for variably sized objects + +GCC was emitting the size of the constant part of VLA structures, e.g. +something like: + + struct foo { + int a, b[]; + } bar = { 1, { 2, 3, 4 } }; + +Would get a .size 4 (for a), rather than 16 (a, and 3 items in b). This +doesn't immediately break things, but one case where it matters is when +the object is in a shared library and the linker creates a copy +relocation - it'll only copy the first part of whatever we're looking +at. + +Use the size of the decl (which will include the variable part) rather +than the type (which has no idea what is about to be set up in terms of +content) - same as all the other architectures. The "new" code in fact +comes from gcc/config/elfos.h. + +References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102298 +Cc: Andrew Pinski +Signed-off-by: David Lamparter +--- + gcc/config/mips/mips.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc +index 9bc73b2e77db..de0c50904baa 100644 +--- a/gcc/config/mips/mips.cc ++++ b/gcc/config/mips/mips.cc +@@ -9588,7 +9588,7 @@ mips_output_external (FILE *file, tree decl, const char *name) + fputs ("\t.extern\t", file); + assemble_name (file, name); + fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n", +- int_size_in_bytes (TREE_TYPE (decl))); ++ tree_to_uhwi (DECL_SIZE_UNIT (decl))); + } + } + } +@@ -9898,7 +9898,7 @@ mips_declare_object_name (FILE *stream, const char *name, + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + +@@ -9923,7 +9923,7 @@ mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end) + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + } +-- +2.52.0 + diff --git a/toolchain/gcc/patches-14.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch b/toolchain/gcc/patches-14.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch new file mode 100644 index 000000000000..13d8a7700a8c --- /dev/null +++ b/toolchain/gcc/patches-14.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch @@ -0,0 +1,64 @@ +From 8217b98353ec987db36f54d1852664db0748f15f Mon Sep 17 00:00:00 2001 +From: David Lamparter +Date: Wed, 28 Jan 2026 16:29:06 +0100 +Subject: [PATCH] MIPS: fix emitted .size for variably sized objects + +GCC was emitting the size of the constant part of VLA structures, e.g. +something like: + + struct foo { + int a, b[]; + } bar = { 1, { 2, 3, 4 } }; + +Would get a .size 4 (for a), rather than 16 (a, and 3 items in b). This +doesn't immediately break things, but one case where it matters is when +the object is in a shared library and the linker creates a copy +relocation - it'll only copy the first part of whatever we're looking +at. + +Use the size of the decl (which will include the variable part) rather +than the type (which has no idea what is about to be set up in terms of +content) - same as all the other architectures. The "new" code in fact +comes from gcc/config/elfos.h. + +References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102298 +Cc: Andrew Pinski +Signed-off-by: David Lamparter +--- + gcc/config/mips/mips.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc +index 1156d212c1f9..ff27234c2c1b 100644 +--- a/gcc/config/mips/mips.cc ++++ b/gcc/config/mips/mips.cc +@@ -9755,7 +9755,7 @@ mips_output_external (FILE *file, tree decl, const char *name) + fputs ("\t.extern\t", file); + assemble_name (file, name); + fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n", +- int_size_in_bytes (TREE_TYPE (decl))); ++ tree_to_uhwi (DECL_SIZE_UNIT (decl))); + } + } + } +@@ -10065,7 +10065,7 @@ mips_declare_object_name (FILE *stream, const char *name, + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + +@@ -10090,7 +10090,7 @@ mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end) + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + } +-- +2.52.0 + diff --git a/toolchain/gcc/patches-15.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch b/toolchain/gcc/patches-15.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch new file mode 100644 index 000000000000..eea9563a70b9 --- /dev/null +++ b/toolchain/gcc/patches-15.x/150-MIPS-fix-emitted-size-for-variably-sized-objects.patch @@ -0,0 +1,64 @@ +From 56e3fdaf4d493673a97ce89121fb70a0afd9f1ed Mon Sep 17 00:00:00 2001 +From: David Lamparter +Date: Wed, 28 Jan 2026 16:29:06 +0100 +Subject: [PATCH] MIPS: fix emitted .size for variably sized objects + +GCC was emitting the size of the constant part of VLA structures, e.g. +something like: + + struct foo { + int a, b[]; + } bar = { 1, { 2, 3, 4 } }; + +Would get a .size 4 (for a), rather than 16 (a, and 3 items in b). This +doesn't immediately break things, but one case where it matters is when +the object is in a shared library and the linker creates a copy +relocation - it'll only copy the first part of whatever we're looking +at. + +Use the size of the decl (which will include the variable part) rather +than the type (which has no idea what is about to be set up in terms of +content) - same as all the other architectures. The "new" code in fact +comes from gcc/config/elfos.h. + +References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102298 +Cc: Andrew Pinski +Signed-off-by: David Lamparter +--- + gcc/config/mips/mips.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc +index 24a28dcf817f..5e5f0fe02eba 100644 +--- a/gcc/config/mips/mips.cc ++++ b/gcc/config/mips/mips.cc +@@ -9885,7 +9885,7 @@ mips_output_external (FILE *file, tree decl, const char *name) + fputs ("\t.extern\t", file); + assemble_name (file, name); + fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n", +- int_size_in_bytes (TREE_TYPE (decl))); ++ tree_to_uhwi (DECL_SIZE_UNIT (decl))); + } + } + } +@@ -10195,7 +10195,7 @@ mips_declare_object_name (FILE *stream, const char *name, + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + +@@ -10220,7 +10220,7 @@ mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end) + HOST_WIDE_INT size; + + size_directive_output = 1; +- size = int_size_in_bytes (TREE_TYPE (decl)); ++ size = tree_to_uhwi (DECL_SIZE_UNIT (decl)); + ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); + } + } +-- +2.52.0 +