Browse Source

glibc: add sh fixes, allows to use gcc 7.1

Waldemar Brodkorb 7 years ago
parent
commit
fd9e8c2007

+ 0 - 1
target/config/Config.in.compiler

@@ -22,7 +22,6 @@ default ADK_TOOLCHAIN_GCC_NDS32 if ADK_TARGET_ARCH_NDS32
 default ADK_TOOLCHAIN_GCC_4_2 if ADK_TARGET_ARCH_METAG
 default ADK_TOOLCHAIN_GCC_4_4 if ADK_TARGET_ARCH_AVR32
 default ADK_TOOLCHAIN_GCC_4_9 if ADK_TARGET_ARCH_LM32 && !ADK_TARGET_LIB_NEWLIB
-default ADK_TOOLCHAIN_GCC_4_9 if ADK_TARGET_LIB_GLIBC && ADK_TARGET_ARCH_SH
 default ADK_TOOLCHAIN_GCC_4_9 if ADK_TARGET_SYSTEM_KINETIS_K70
 default ADK_TOOLCHAIN_GCC_7
 

+ 56 - 0
toolchain/glibc/patches/2.25/sh.patch

@@ -0,0 +1,56 @@
+From 3840d4c2add1dd282f5f01fa51720b2d5b8fd8d2 Mon Sep 17 00:00:00 2001
+From: Alexey Neyman <stilor@att.net>
+Date: Wed, 8 Feb 2017 16:00:57 -0200
+Subject: [PATCH] sh: Fix building with gcc5/6
+
+Build glibc for sh4-unknown-linux-gnu currently fails if one's
+using GCC5/6: in dl-conflict.c, the elf_machine_rela() function
+is called with NULL as its 3rd argument, sym. The implementation
+of that function in sysdeps/sh/dl-machine.h dereferences that pointer:
+
+const Elf32_Sym *const refsym = sym;
+...
+if (map == &GL(dl_rtld_map))
+  value -= map->l_addr + refsym->st_value + reloc->r_addend;
+
+GCC discovers a null pointer dereference, and in accordance with
+-fdelete-null-pointer-checks (which is enabled in -O2) replaces this
+code with a trap - which, as SH does not implement a trap pattern in
+GCC, evaluates to an abort() call. This abort() call pulls many more
+objects from libc_nonshared.a, eventually resulting in link failure
+due to multiple definitions for a number of symbols.
+
+As far as I see, the conditional before this code is always false in
+rtld: _dl_resolve_conflicts() is called with main_map as the first
+argument, not GL(_dl_rtld_map), but since that call is in yet another
+compilation unit, GCC does not know about it. Patch that wraps this
+conditional into !defined RESOLVE_CONFLICT_FIND_MAP attached.
+
+	* sysdeps/sh/dl-machine.h (elf_machine_rela): The condition
+	in R_SH_DIR32 case is always false when inlined from
+	dl-conflict.c. Ifdef out to prevent GCC from insertin an
+	abort() call.
+
+[Waldemar: backport of
+https://sourceware.org/git/?p=glibc.git;a=commit;h=d40dbe722f004f999b589de776f7e57e564dda01.]
+Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
+---
+ sysdeps/sh/dl-machine.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
+index 449deea..2b468af 100644
+--- a/sysdeps/sh/dl-machine.h
++++ b/sysdeps/sh/dl-machine.h
+@@ -389,7 +389,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
+ 	  break;
+ 	case R_SH_DIR32:
+ 	  {
+-#ifndef RTLD_BOOTSTRAP
++#if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
+ 	   /* This is defined in rtld.c, but nowhere in the static
+ 	      libc.a; make the reference weak so static programs can
+ 	      still link.  This declaration cannot be done when
+-- 
+2.7.4
+

+ 340 - 0
toolchain/glibc/patches/2.25/sh4-trap.patch

@@ -0,0 +1,340 @@
+commit db3d848e154b00071f4a5e729d5884efad410109
+Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
+Date:   Wed Mar 15 15:44:59 2017 -0300
+
+    Build divdi3 only for architecture that required it
+    
+    As noted in [1], divdi3 object is only exported in a handful ABIs
+    (i386, m68k, powerpc32, s390-32, and ia64), however it is built
+    for all current architectures regardless.
+    
+    This patch refact the make rules for this object to so only the
+    aforementioned architectures that actually require it builds it.
+    
+    Also, to avoid internal PLT calls to the exported symbol from the
+    module, glibc uses an internal header (symbol-hacks.h) which is
+    unrequired (and in fact breaks the build for architectures that
+    intend to get symbol definitions from libgcc.a).  The patch also
+    changes it to create its own header (divdi3-symbol-hacks.h) and
+    adjust the architectures that require it accordingly.
+    
+    I checked the build/check (with run-built-tests=no) on the
+    following architectures (which I think must cover all supported
+    ABI/builds) using GCC 6.3:
+    
+    aarch64-linux-gnu
+    alpha-linux-gnu
+    arm-linux-gnueabihf
+    hppa-linux-gnu
+    ia64-linux-gnu
+    m68k-linux-gnu
+    microblaze-linux-gnu
+    mips64-n32-linux-gnu
+    mips-linux-gnu
+    mips64-linux-gnu
+    nios2-linux-gnu
+    powerpc-linux-gnu
+    powerpc-linux-gnu-power4
+    powerpc64-linux-gnu
+    powerpc64le-linux-gnu
+    s390x-linux-gnu
+    s390-linux-gnu
+    sh4-linux-gnu
+    sh4-linux-gnu-soft
+    sparc64-linux-gnu
+    sparcv9-linux-gnu
+    tilegx-linux-gnu
+    tilegx-linux-gnu-32
+    tilepro-linux-gnu
+    x86_64-linux-gnu
+    x86_64-linux-gnu-x32
+    i686-linux-gnu
+    
+    I only saw one regression on sparcv9-linux-gnu (extra PLT call to
+    .udiv) which I address in next patch in the set.  It also correctly
+    build SH with GCC 7.0.1 (without any regression from c89721e25d).
+    
+    [1] https://sourceware.org/ml/libc-alpha/2017-03/msg00243.html
+    
+            * sysdeps/i386/symbol-hacks.h: New file.
+            * sysdeps/m68k/symbol-hacks.h: New file.
+            * sysdeps/powerpc/powerpc32/symbol-hacks.h: New file.
+            * sysdeps/s390/s390-32/symbol-hacks.h: New file.
+            * sysdeps/unix/sysv/linux/i386/Makefile
+            [$(subdir) = csu] (sysdep_routines): New rule: divdi3 object.
+            [$(subdir) = csu] (sysdep-only-routines): Likewise.
+            [$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
+            * sysdeps/unix/sysv/linux/m68k/Makefile
+            [$(subdir) = csu] (sysdep_routines): Likewise.
+            [$(subdir) = csu] (sysdep-only-routines): Likewise.
+            [$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
+            * sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
+            [$(subdir) = csu] (sysdep_routines): Likewise.
+            [$(subdir) = csu] (sysdep-only-routines): Likewise.
+            [$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
+            * sysdeps/unix/sysv/linux/s390/s390-32/Makefile
+            [$(subdir) = csu] (sysdep_routines): Likewise.
+            [$(subdir) = csu] (sysdep-only-routines): Likewise.
+            [$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
+            * sysdeps/wordsize-32/Makefile: Remove file.
+            * sysdeps/wordsize-32/symbol-hacks.h: Definitions move to ...
+            * sysdeps/wordsize-32/divdi3-symbol-hacks.h: ... here.
+
+diff --git a/sysdeps/i386/symbol-hacks.h b/sysdeps/i386/symbol-hacks.h
+new file mode 100644
+index 0000000000..36a13c83f7
+--- /dev/null
++++ b/sysdeps/i386/symbol-hacks.h
+@@ -0,0 +1,21 @@
++/* Hacks needed for symbol manipulation.  i386 version.
++   Copyright (C) 2017 Free Software Foundation, Inc.
++   This file is part of the GNU C Library.
++
++   The GNU C Library is free software; you can redistribute it and/or
++   modify it under the terms of the GNU Lesser General Public
++   License as published by the Free Software Foundation; either
++   version 2.1 of the License, or (at your option) any later version.
++
++   The GNU C Library is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   Lesser General Public License for more details.
++
++   You should have received a copy of the GNU Lesser General Public
++   License along with the GNU C Library; if not, see
++   <http://www.gnu.org/licenses/>.  */
++
++#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
++
++#include_next "symbol-hacks.h"
+diff --git a/sysdeps/m68k/symbol-hacks.h b/sysdeps/m68k/symbol-hacks.h
+new file mode 100644
+index 0000000000..e449d29810
+--- /dev/null
++++ b/sysdeps/m68k/symbol-hacks.h
+@@ -0,0 +1,21 @@
++/* Hacks needed for symbol manipulation.  m68k version.
++   Copyright (C) 2017 Free Software Foundation, Inc.
++   This file is part of the GNU C Library.
++
++   The GNU C Library is free software; you can redistribute it and/or
++   modify it under the terms of the GNU Lesser General Public
++   License as published by the Free Software Foundation; either
++   version 2.1 of the License, or (at your option) any later version.
++
++   The GNU C Library is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   Lesser General Public License for more details.
++
++   You should have received a copy of the GNU Lesser General Public
++   License along with the GNU C Library; if not, see
++   <http://www.gnu.org/licenses/>.  */
++
++#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
++
++#include_next "symbol-hacks.h"
+diff --git a/sysdeps/powerpc/powerpc32/symbol-hacks.h b/sysdeps/powerpc/powerpc32/symbol-hacks.h
+new file mode 100644
+index 0000000000..dbb3141621
+--- /dev/null
++++ b/sysdeps/powerpc/powerpc32/symbol-hacks.h
+@@ -0,0 +1,21 @@
++/* Hacks needed for symbol manipulation.  powerpc version.
++   Copyright (C) 2017 Free Software Foundation, Inc.
++   This file is part of the GNU C Library.
++
++   The GNU C Library is free software; you can redistribute it and/or
++   modify it under the terms of the GNU Lesser General Public
++   License as published by the Free Software Foundation; either
++   version 2.1 of the License, or (at your option) any later version.
++
++   The GNU C Library is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   Lesser General Public License for more details.
++
++   You should have received a copy of the GNU Lesser General Public
++   License along with the GNU C Library; if not, see
++   <http://www.gnu.org/licenses/>.  */
++
++#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
++
++#include_next "symbol-hacks.h"
+diff --git a/sysdeps/s390/s390-32/symbol-hacks.h b/sysdeps/s390/s390-32/symbol-hacks.h
+new file mode 100644
+index 0000000000..585c42365a
+--- /dev/null
++++ b/sysdeps/s390/s390-32/symbol-hacks.h
+@@ -0,0 +1,21 @@
++/* Hacks needed for symbol manipulation.  s390 version.
++   Copyright (C) 2017 Free Software Foundation, Inc.
++   This file is part of the GNU C Library.
++
++   The GNU C Library is free software; you can redistribute it and/or
++   modify it under the terms of the GNU Lesser General Public
++   License as published by the Free Software Foundation; either
++   version 2.1 of the License, or (at your option) any later version.
++
++   The GNU C Library is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   Lesser General Public License for more details.
++
++   You should have received a copy of the GNU Lesser General Public
++   License along with the GNU C Library; if not, see
++   <http://www.gnu.org/licenses/>.  */
++
++#include <sysdeps/wordsize-32/divdi3-symbol-hacks.h>
++
++#include_next "symbol-hacks.h"
+diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
+index 6aac0dfe15..4080b8c966 100644
+--- a/sysdeps/unix/sysv/linux/i386/Makefile
++++ b/sysdeps/unix/sysv/linux/i386/Makefile
+@@ -26,6 +26,11 @@ endif
+ 
+ ifeq ($(subdir),csu)
+ sysdep-dl-routines += sysdep
++ifeq (yes,$(build-shared))
++sysdep_routines += divdi3
++shared-only-routines += divdi3
++CPPFLAGS-divdi3.c = -Din_divdi3_c
++endif
+ endif
+ 
+ ifeq ($(subdir),nptl)
+diff --git a/sysdeps/unix/sysv/linux/m68k/Makefile b/sysdeps/unix/sysv/linux/m68k/Makefile
+index 5c50ce6927..ce1f696a6f 100644
+--- a/sysdeps/unix/sysv/linux/m68k/Makefile
++++ b/sysdeps/unix/sysv/linux/m68k/Makefile
+@@ -4,6 +4,11 @@ m68k-syntax-flag = -DMOTOROLA_SYNTAX
+ 
+ ifeq ($(subdir),csu)
+ sysdep_routines += m68k-helpers
++ifeq (yes,$(build-shared))
++sysdep_routines += divdi3
++shared-only-routines += divdi3
++CPPFLAGS-divdi3.c = -Din_divdi3_c
++endif
+ endif
+ 
+ ifeq ($(subdir),misc)
+diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
+index 3d6c150582..1f45659ed1 100644
+--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
++++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
+@@ -1,2 +1,10 @@
+ # See Makeconfig regarding the use of default-abi.
+ default-abi := 32
++
++ifeq ($(subdir),csu)
++ifeq (yes,$(build-shared))
++sysdep_routines += divdi3
++shared-only-routines += divdi3
++CPPFLAGS-divdi3.c = -Din_divdi3_c
++endif
++endif
+diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
+index da3b3c76b4..fd8cf92633 100644
+--- a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
++++ b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile
+@@ -21,3 +21,11 @@ endif
+ ifeq ($(subdir),stdlib)
+ sysdep_routines += __makecontext_ret
+ endif
++
++ifeq ($(subdir),csu)
++ifeq (yes,$(build-shared))
++sysdep_routines += divdi3
++shared-only-routines += divdi3
++CPPFLAGS-divdi3.c = -Din_divdi3_c
++endif
++endif
+diff --git a/sysdeps/wordsize-32/Makefile b/sysdeps/wordsize-32/Makefile
+deleted file mode 100644
+index 82beac44ed..0000000000
+--- a/sysdeps/wordsize-32/Makefile
++++ /dev/null
+@@ -1,7 +0,0 @@
+-ifeq ($(subdir),csu)
+-ifeq (yes,$(build-shared))
+-sysdep_routines += divdi3
+-shared-only-routines += divdi3
+-CPPFLAGS-divdi3.c = -Din_divdi3_c
+-endif
+-endif
+diff --git a/sysdeps/wordsize-32/divdi3-symbol-hacks.h b/sysdeps/wordsize-32/divdi3-symbol-hacks.h
+new file mode 100644
+index 0000000000..6c90cb796d
+--- /dev/null
++++ b/sysdeps/wordsize-32/divdi3-symbol-hacks.h
+@@ -0,0 +1,31 @@
++/* Hacks needed for divdi3 symbol manipulation.
++   Copyright (C) 2004-2017 Free Software Foundation, Inc.
++   This file is part of the GNU C Library.
++
++   The GNU C Library is free software; you can redistribute it and/or
++   modify it under the terms of the GNU Lesser General Public
++   License as published by the Free Software Foundation; either
++   version 2.1 of the License, or (at your option) any later version.
++
++   The GNU C Library is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++   Lesser General Public License for more details.
++
++   You should have received a copy of the GNU Lesser General Public
++   License along with the GNU C Library; if not, see
++   <http://www.gnu.org/licenses/>.  */
++
++/* 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
++   task which might not be worth it so we play tricks with the
++   assembler.
++   Note: in_divdi3_c is only used to avoid symbol alias on divdi3
++   build itself.  */
++#if !defined __ASSEMBLER__ && !defined in_divdi3_c && IS_IN (libc) && defined SHARED
++asm ("__divdi3 = __divdi3_internal");
++asm ("__udivdi3 = __udivdi3_internal");
++asm ("__moddi3 = __moddi3_internal");
++asm ("__umoddi3 = __umoddi3_internal");
++#endif
+diff --git a/sysdeps/wordsize-32/symbol-hacks.h b/sysdeps/wordsize-32/symbol-hacks.h
+deleted file mode 100644
+index 0aec1e0b97..0000000000
+--- a/sysdeps/wordsize-32/symbol-hacks.h
++++ /dev/null
+@@ -1,31 +0,0 @@
+-/* Hacks needed for symbol manipulation.
+-   Copyright (C) 2004-2017 Free Software Foundation, Inc.
+-   This file is part of the GNU C Library.
+-
+-   The GNU C Library is free software; you can redistribute it and/or
+-   modify it under the terms of the GNU Lesser General Public
+-   License as published by the Free Software Foundation; either
+-   version 2.1 of the License, or (at your option) any later version.
+-
+-   The GNU C Library is distributed in the hope that it will be useful,
+-   but WITHOUT ANY WARRANTY; without even the implied warranty of
+-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+-   Lesser General Public License for more details.
+-
+-   You should have received a copy of the GNU Lesser General Public
+-   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
+-   task which might not be worth it so we play tricks with the
+-   assembler.  */
+-#if !defined __ASSEMBLER__ && !defined in_divdi3_c && IS_IN (libc) && defined SHARED
+-asm ("__divdi3 = __divdi3_internal");
+-asm ("__udivdi3 = __udivdi3_internal");
+-asm ("__moddi3 = __moddi3_internal");
+-asm ("__umoddi3 = __umoddi3_internal");
+-#endif