From 348c3af966da52db55c20b37222e6f95de2627a4 Mon Sep 17 00:00:00 2001
From: Imre Kaloz <kaloz@openwrt.org>
Date: Wed, 11 Sep 2013 13:18:23 +0000
Subject: [PATCH] add support for Linaro binutils 2.23.2-2013.06

Signed-off-by: Imre Kaloz <kaloz@openwrt.org>

SVN-Revision: 37944
---
 toolchain/binutils/Config.in                  |  5 +++
 toolchain/binutils/Makefile                   | 33 ++++++++++-------
 .../112-arm-uclibc-gas-needs-libm.patch       | 35 +++++++++++++++++++
 .../binutils/patches/linaro/120-sh-conf.patch | 22 ++++++++++++
 .../binutils/patches/linaro/200-musl.patch    | 10 ++++++
 .../linaro/300-001_ld_makefile_patch.patch    | 22 ++++++++++++
 .../300-012_check_ldrunpath_length.patch      | 20 +++++++++++
 .../400-mips_no_dynamic_linking_sym.patch     | 18 ++++++++++
 8 files changed, 153 insertions(+), 12 deletions(-)
 create mode 100644 toolchain/binutils/patches/linaro/112-arm-uclibc-gas-needs-libm.patch
 create mode 100644 toolchain/binutils/patches/linaro/120-sh-conf.patch
 create mode 100644 toolchain/binutils/patches/linaro/200-musl.patch
 create mode 100644 toolchain/binutils/patches/linaro/300-001_ld_makefile_patch.patch
 create mode 100644 toolchain/binutils/patches/linaro/300-012_check_ldrunpath_length.patch
 create mode 100644 toolchain/binutils/patches/linaro/400-mips_no_dynamic_linking_sym.patch

diff --git a/toolchain/binutils/Config.in b/toolchain/binutils/Config.in
index 03e9b811f5..e2d0d20be6 100644
--- a/toolchain/binutils/Config.in
+++ b/toolchain/binutils/Config.in
@@ -19,6 +19,10 @@ choice
 		depends on !avr32 || (avr32 && BROKEN)
 		bool "binutils 2.23.1"
 
+	config BINUTILS_VERSION_LINARO
+		depends on !avr32 || (avr32 && BROKEN)
+		bool "Linaro binutils 2.23.2"
+
 endchoice
 
 config EXTRA_BINUTILS_CONFIG_OPTIONS
@@ -34,5 +38,6 @@ config BINUTILS_VERSION
 	default "2.20.1"          if BINUTILS_VERSION_2_20_1
 	default "2.22"            if BINUTILS_VERSION_2_22
 	default "2.23.1"	  if BINUTILS_VERSION_2_23_1
+	default "linaro"          if BINUTILS_VERSION_LINARO
 	default "2.20.1"          if avr32
 	default "2.22"
diff --git a/toolchain/binutils/Makefile b/toolchain/binutils/Makefile
index 4b52aa526f..0eb884d1c1 100644
--- a/toolchain/binutils/Makefile
+++ b/toolchain/binutils/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2012 OpenWrt.org
+# Copyright (C) 2006-2013 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -10,17 +10,26 @@ PKG_NAME:=binutils
 PKG_VERSION:=$(call qstrip,$(CONFIG_BINUTILS_VERSION))
 BIN_VERSION:=$(PKG_VERSION)
 
-PKG_SOURCE_URL:=@GNU/binutils/
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
-
-ifeq ($(PKG_VERSION),2.20.1)
-  PKG_MD5SUM:=9cdfb9d6ec0578c166d3beae5e15c4e5
-endif
-ifeq ($(PKG_VERSION),2.22)
-  PKG_MD5SUM:=ee0f10756c84979622b992a4a61ea3f5
-endif
-ifeq ($(PKG_VERSION),2.23.1)
-  PKG_MD5SUM:=33adb18c3048d057ac58d07a3f1adb38
+ifeq ($(findstring linaro, $(CONFIG_BINUTILS_VERSION)),linaro)
+  PKG_SOURCE_URL:=https://releases.linaro.org/13.06/components/toolchain/binutils-linaro/
+  PKG_REV:=2.23.2-2013.06
+  PKG_SOURCE:=$(PKG_NAME)-linaro-$(PKG_REV).tar.bz2
+  PKG_MD5SUM:=73ad2a91f17b7e4fd41d49db5a541d2d
+  BINUTILS_DIR:=$(PKG_NAME)-2.23.2
+  HOST_BUILD_DIR:=$(BUILD_DIR_TOOLCHAIN)/$(BINUTILS_DIR)
+else
+  PKG_SOURCE_URL:=@GNU/binutils/
+  PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+
+  ifeq ($(PKG_VERSION),2.20.1)
+    PKG_MD5SUM:=9cdfb9d6ec0578c166d3beae5e15c4e5
+  endif
+  ifeq ($(PKG_VERSION),2.22)
+    PKG_MD5SUM:=ee0f10756c84979622b992a4a61ea3f5
+  endif
+  ifeq ($(PKG_VERSION),2.23.1)
+    PKG_MD5SUM:=33adb18c3048d057ac58d07a3f1adb38
+  endif
 endif
 
 HOST_BUILD_PARALLEL:=1
diff --git a/toolchain/binutils/patches/linaro/112-arm-uclibc-gas-needs-libm.patch b/toolchain/binutils/patches/linaro/112-arm-uclibc-gas-needs-libm.patch
new file mode 100644
index 0000000000..5d0e5ff8ef
--- /dev/null
+++ b/toolchain/binutils/patches/linaro/112-arm-uclibc-gas-needs-libm.patch
@@ -0,0 +1,35 @@
+Source: Khem Raj <raj.khem@gmail.com>
+Disposition: submit upstream.
+
+Description:
+
+We do not need to have the libtool patch anymore for binutils after
+libtool has been updated upstream it include support for it. However
+for building gas natively on uclibc systems we have to link it with
+-lm so that it picks up missing symbols.
+
+/local/build_area/BUILD/arm_v5t_le_uclibc/binutils-2.17.50/objdir/libiberty/pic/libiberty.a(floatformat.o): In function `floatformat_from_double':
+floatformat.c:(.text+0x1ec): undefined reference to `frexp'
+floatformat.c:(.text+0x2f8): undefined reference to `ldexp'
+/local/build_area/BUILD/arm_v5t_le_uclibc/binutils-2.17.50/objdir/libiberty/pic/libiberty.a(floatformat.o): In function `floatformat_to_double':
+floatformat.c:(.text+0x38a): undefined reference to `ldexp'
+floatformat.c:(.text+0x3d2): undefined reference to `ldexp'
+floatformat.c:(.text+0x43e): undefined reference to `ldexp'                     floatformat.c:(.text+0x4e2): undefined reference to `ldexp'
+collect2: ld returned 1 exit status
+make[4]: *** [as-new] Error 1
+
+--- a/gas/configure.tgt
++++ b/gas/configure.tgt
+@@ -450,6 +450,12 @@ case ${generic_target} in
+   *-*-netware)				fmt=elf em=netware ;;
+ esac
+ 
++case ${generic_target} in
++  arm-*-*uclibc*)
++    need_libm=yes
++    ;;
++esac
++
+ case ${cpu_type} in
+   aarch64 | alpha | arm | i386 | ia64 | microblaze | mips | ns32k | pdp11 | ppc | sparc | z80 | z8k)
+     bfd_gas=yes
diff --git a/toolchain/binutils/patches/linaro/120-sh-conf.patch b/toolchain/binutils/patches/linaro/120-sh-conf.patch
new file mode 100644
index 0000000000..ce0ec81b89
--- /dev/null
+++ b/toolchain/binutils/patches/linaro/120-sh-conf.patch
@@ -0,0 +1,22 @@
+--- a/configure
++++ b/configure
+@@ -3595,7 +3595,7 @@ case "${target}" in
+   mips*-*-*)
+     noconfigdirs="$noconfigdirs gprof"
+     ;;
+-  sh-*-* | sh64-*-*)
++  sh*-*-* | sh64-*-*)
+     case "${target}" in
+       sh*-*-elf)
+          ;;
+--- a/configure.ac
++++ b/configure.ac
+@@ -1021,7 +1021,7 @@ case "${target}" in
+   mips*-*-*)
+     noconfigdirs="$noconfigdirs gprof"
+     ;;
+-  sh-*-* | sh64-*-*)
++  sh*-*-* | sh64-*-*)
+     case "${target}" in
+       sh*-*-elf)
+          ;;
diff --git a/toolchain/binutils/patches/linaro/200-musl.patch b/toolchain/binutils/patches/linaro/200-musl.patch
new file mode 100644
index 0000000000..40fe76d34d
--- /dev/null
+++ b/toolchain/binutils/patches/linaro/200-musl.patch
@@ -0,0 +1,10 @@
+--- a/config.sub
++++ b/config.sub
+@@ -125,6 +125,7 @@ esac
+ maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+ case $maybe_os in
+   nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
++  linux-musl* | \
+   linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+   knetbsd*-gnu* | netbsd*-gnu* | \
+   kopensolaris*-gnu* | \
diff --git a/toolchain/binutils/patches/linaro/300-001_ld_makefile_patch.patch b/toolchain/binutils/patches/linaro/300-001_ld_makefile_patch.patch
new file mode 100644
index 0000000000..323655a01c
--- /dev/null
+++ b/toolchain/binutils/patches/linaro/300-001_ld_makefile_patch.patch
@@ -0,0 +1,22 @@
+--- a/ld/Makefile.am
++++ b/ld/Makefile.am
+@@ -37,7 +37,7 @@ endif
+ # We put the scripts in the directory $(scriptdir)/ldscripts.
+ # We can't put the scripts in $(datadir) because the SEARCH_DIR
+ # directives need to be different for native and cross linkers.
+-scriptdir = $(tooldir)/lib
++scriptdir = $(libdir)
+ 
+ EMUL = @EMUL@
+ EMULATION_OFILES = @EMULATION_OFILES@
+--- a/ld/Makefile.in
++++ b/ld/Makefile.in
+@@ -367,7 +367,7 @@ AM_CFLAGS = $(WARN_CFLAGS)
+ # We put the scripts in the directory $(scriptdir)/ldscripts.
+ # We can't put the scripts in $(datadir) because the SEARCH_DIR
+ # directives need to be different for native and cross linkers.
+-scriptdir = $(tooldir)/lib
++scriptdir = $(libdir)
+ BASEDIR = $(srcdir)/..
+ BFDDIR = $(BASEDIR)/bfd
+ INCDIR = $(BASEDIR)/include
diff --git a/toolchain/binutils/patches/linaro/300-012_check_ldrunpath_length.patch b/toolchain/binutils/patches/linaro/300-012_check_ldrunpath_length.patch
new file mode 100644
index 0000000000..61324d1119
--- /dev/null
+++ b/toolchain/binutils/patches/linaro/300-012_check_ldrunpath_length.patch
@@ -0,0 +1,20 @@
+--- a/ld/emultempl/elf32.em
++++ b/ld/emultempl/elf32.em
+@@ -1278,6 +1278,8 @@ fragment <<EOF
+ 	      && command_line.rpath == NULL)
+ 	    {
+ 	      lib_path = (const char *) getenv ("LD_RUN_PATH");
++	      if ((lib_path) && (strlen (lib_path) == 0))
++	      	lib_path = NULL;
+ 	      if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
+ 						      force))
+ 		break;
+@@ -1505,6 +1507,8 @@ gld${EMULATION_NAME}_before_allocation (
+   rpath = command_line.rpath;
+   if (rpath == NULL)
+     rpath = (const char *) getenv ("LD_RUN_PATH");
++  if ((rpath) && (strlen (rpath) == 0))
++  	rpath = NULL;
+ 
+   for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
+     if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
diff --git a/toolchain/binutils/patches/linaro/400-mips_no_dynamic_linking_sym.patch b/toolchain/binutils/patches/linaro/400-mips_no_dynamic_linking_sym.patch
new file mode 100644
index 0000000000..241477d9b9
--- /dev/null
+++ b/toolchain/binutils/patches/linaro/400-mips_no_dynamic_linking_sym.patch
@@ -0,0 +1,18 @@
+--- a/bfd/elfxx-mips.c
++++ b/bfd/elfxx-mips.c
+@@ -7331,6 +7331,7 @@ _bfd_mips_elf_create_dynamic_sections (b
+ 
+       name = SGI_COMPAT (abfd) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
+       bh = NULL;
++      if (0) {
+       if (!(_bfd_generic_link_add_one_symbol
+ 	    (info, abfd, name, BSF_GLOBAL, bfd_abs_section_ptr, 0,
+ 	     NULL, FALSE, get_elf_backend_data (abfd)->collect, &bh)))
+@@ -7343,6 +7344,7 @@ _bfd_mips_elf_create_dynamic_sections (b
+ 
+       if (! bfd_elf_link_record_dynamic_symbol (info, h))
+ 	return FALSE;
++      }
+ 
+       if (! mips_elf_hash_table (info)->use_rld_obj_head)
+ 	{
-- 
2.34.1