From: Sandra Loosemore Date: Thu, 21 Nov 2019 02:10:40 +0000 (-0700) Subject: Compile elf/rtld.c with -fno-tree-loop-distribute-patterns. X-Git-Tag: glibc-2.31~222 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c72e5cd87dcb075782f9b6beea024b984f2e1130;p=thirdparty%2Fglibc.git Compile elf/rtld.c with -fno-tree-loop-distribute-patterns. In GCC 10, the default at -O2 is now -ftree-loop-distribute-patterns. This optimization causes GCC to "helpfully" convert the hand-written loop in _dl_start into a call to memset, which is not available that early in program startup. Similar problems in other places in GLIBC have been addressed by explicitly building with -fno-tree-loop-distribute-patterns, but this one may have been overlooked previously because it only affects targets where HAVE_BUILTIN_MEMSET is not defined. This patch fixes a bug observed on nios2-linux-gnu target that caused all programs to segv on startup. --- diff --git a/elf/Makefile b/elf/Makefile index 06688181e3e..b05af5ce3a2 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -65,6 +65,12 @@ CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-dl-lookup.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-dl-iterate-phdr.c += $(uses-callbacks) +# On targets without __builtin_memset, rtld.c uses a hand-coded loop +# in _dl_start. Make sure this isn't turned into a call to regular memset. +ifeq (yes,$(have-loop-to-function)) +CFLAGS-rtld.c += -fno-tree-loop-distribute-patterns +endif + # Compile rtld itself without stack protection. # Also compile all routines in the static library that are elided from # the shared libc because they are in libc.a in the same way.