From 1b9818519d19ae297e76639aafebc9d7400bb279 Mon Sep 17 00:00:00 2001
From: Pavel Chupin <pavel.v.chupin@intel.com>
Date: Tue, 2 Apr 2013 12:11:56 +0400
Subject: [PATCH] Fix LIB_SPEC for systems without libpthread

Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
---
 gcc/config/arm/linux-eabi.h    | 2 +-
 gcc/config/gnu-user.h          | 5 ++---
 gcc/config/i386/linux-common.h | 2 +-
 gcc/config/mips/gnu-user.h     | 2 +-
 gcc/config/mips/linux-common.h | 2 +-
 5 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
index cb0aad1..f4e0ec1 100644
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -98,7 +98,7 @@
 
 #undef  LIB_SPEC
 #define LIB_SPEC							\
-  LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC,			\
+  LINUX_OR_ANDROID_LD ("%{pthread:-lpthread} " GNU_USER_TARGET_LIB_SPEC, \
 		       GNU_USER_TARGET_LIB_SPEC " " ANDROID_LIB_SPEC)
 
 #undef	STARTFILE_SPEC
diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index 2c48c18..e2181e0 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -83,11 +83,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
 
 #define GNU_USER_TARGET_LIB_SPEC \
-  "%{pthread:-lpthread} \
-   %{shared:-lc} \
+  "%{shared:-lc} \
    %{!shared:%{mieee-fp:-lieee} %{profile:-lc_p}%{!profile:-lc}}"
 #undef  LIB_SPEC
-#define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
+#define LIB_SPEC "%{pthread:-lpthread} " GNU_USER_TARGET_LIB_SPEC
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
 #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
diff --git a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h
index 1e8bf6b..3f416af 100644
--- a/gcc/config/i386/linux-common.h
+++ b/gcc/config/i386/linux-common.h
@@ -39,7 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef  LIB_SPEC
 #define LIB_SPEC \
-  LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
+  LINUX_OR_ANDROID_LD ("%{pthread:-lpthread} " GNU_USER_TARGET_LIB_SPEC, \
 		       GNU_USER_TARGET_LIB_SPEC " " ANDROID_LIB_SPEC)
 
 #undef  STARTFILE_SPEC
diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h
index aa3cc37..ffef0f7 100644
--- a/gcc/config/mips/gnu-user.h
+++ b/gcc/config/mips/gnu-user.h
@@ -91,7 +91,7 @@ along with GCC; see the file COPYING3.  If not see
 #undef ASM_OUTPUT_REG_POP
 
 #undef LIB_SPEC
-#define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
+#define LIB_SPEC "%{pthread:-lpthread} " GNU_USER_TARGET_LIB_SPEC
 
 #ifdef HAVE_AS_NO_SHARED
 /* Default to -mno-shared for non-PIC.  */
diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
index ca4ea07..386e641 100644
--- a/gcc/config/mips/linux-common.h
+++ b/gcc/config/mips/linux-common.h
@@ -43,7 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #undef  LIB_SPEC
 #define LIB_SPEC							\
-  LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC,			\
+  LINUX_OR_ANDROID_LD ("%{pthread:-lpthread} " GNU_USER_TARGET_LIB_SPEC, \
 		       GNU_USER_TARGET_LIB_SPEC " " ANDROID_LIB_SPEC)
 
 #undef  STARTFILE_SPEC
-- 
1.7.11.4

