[11/11] Prevent turning memset into self-recursion

Message ID 20250123134308.1785777-13-aleksandar.rakic@htecgroup.com (mailing list archive)
State New
Headers
Series Improve Mips target |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 fail Patch failed to apply
redhat-pt-bot/TryBot-32bit fail Patch series failed to apply

Commit Message

Aleksandar Rakic Jan. 23, 2025, 1:43 p.m. UTC
  Prevent GCC 11 from turning memset into self-recursion.
GCC11 transforms byte-by-byte set loop pattern in memset.c into
a memset call, causing runtime failures. Apply -fno-builtin for
both the memset.c and memcpy.c to prevent similar bugs in future.

Cherry-picked 31906b3556bc18cfdb7a3d84a669d95486450704
from https://github.com/MIPS/glibc

Signed-off-by: Dragan Mladjenovic <dragan.mladjenovic@syrmia.com>
Signed-off-by: Aleksandar Rakic <aleksandar.rakic@htecgroup.com>
---
 sysdeps/mips/Makefile | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Joseph Myers Jan. 23, 2025, 4:19 p.m. UTC | #1
On Thu, 23 Jan 2025, Aleksandar Rakic wrote:

> Prevent GCC 11 from turning memset into self-recursion.
> GCC11 transforms byte-by-byte set loop pattern in memset.c into
> a memset call, causing runtime failures. Apply -fno-builtin for
> both the memset.c and memcpy.c to prevent similar bugs in future.

We use inhibit_loop_to_libcall to provide __attribute__ ((__optimize__ 
("-fno-tree-loop-distribute-patterns"))) in such cases.
  

Patch

diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
index 17ddc2a97c..4464d73902 100644
--- a/sysdeps/mips/Makefile
+++ b/sysdeps/mips/Makefile
@@ -24,6 +24,9 @@  ASFLAGS-.o += $(pie-default)
 ASFLAGS-.op += $(pie-default)
 ASFLAGS += -O2
 
+CFLAGS-memset.c += -fno-builtin
+CFLAGS-memcpy.c += -fno-builtin
+
 ifeq ($(subdir),elf)
 
 # These tests fail on all mips configurations (BZ 29404)