summaryrefslogblamecommitdiffstats
path: root/patches/source/glibc/glibc-2.17_gcc48-unsafe-optim.diff
blob: 4de9fe583b21411dd5236258bef1489ef9d79cdd (plain) (tree)
















































                                                                        
From ea723210a76778c7e86b8df21cb284fc2665ee4f Mon Sep 17 00:00:00 2001
From: mancha <mancha1 AT zoho DOT com>
Date: Wed, 22 Oct 2014
Subject: Fix unsafe compiler optimization

GCC 4.8 enables -ftree-loop-distribute-patterns at -O3 by default and
this optimization may transform loops into memset/memmove calls. Without
proper handling this may generate unexpected PLT calls on GLIBC.
This patch fixes by creating memset/memmove aliases to internal GLIBC
__GI_memset/__GI_memmove symbols.

This fix for use on glibc 2.17 is based on the following upstream
commits:

https://sourceware.org/git/?p=glibc.git;h=6a97b62a5b4f
https://sourceware.org/git/?p=glibc.git;h=4959e284ca9c

---
 sysdeps/generic/symbol-hacks.h     |    7 ++++++-
 sysdeps/wordsize-32/symbol-hacks.h |    2 ++
 sysdeps/x86_64/x32/symbol-hacks.h  |    2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -1 +1,6 @@
-/* Fortunately nothing to do.  */
+/* Some compiler optimizations may transform loops into memset/memmove
+   calls and without proper declaration it may generate PLT calls.  */
+#if !defined __ASSEMBLER__ && !defined NOT_IN_libc && defined SHARED
+asm ("memmove = __GI_memmove");
+asm ("memset = __GI_memset");
+#endif
--- a/sysdeps/wordsize-32/symbol-hacks.h
+++ b/sysdeps/wordsize-32/symbol-hacks.h
@@ -16,6 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include_next "symbol-hacks.h"
+
 /* A very dirty trick: gcc emits references to __divdi3, __udivdi3,
    __moddi3, and __umoddi3.  These functions are exported and
    therefore we get PLTs.  Unnecessarily so.  Changing gcc is a big
--- a/sysdeps/x86_64/x32/symbol-hacks.h
+++ b/sysdeps/x86_64/x32/symbol-hacks.h
@@ -1 +1 @@
-/* Fortunately nothing to do.  */
+#include <sysdeps/generic/symbol-hacks.h>