---
 libgcc/Makefile.in  |  4 +++-
 libgcc/configure    | 34 ++++++++++++++++++++++++++++++++++
 libgcc/configure.ac | 21 +++++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index ea390a5..1a4cafc 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -50,6 +50,7 @@ unwind_header = @unwind_header@
 md_unwind_header = @md_unwind_header@
 sfp_machine_header = @sfp_machine_header@
 thread_header = @thread_header@
+LIBGCC_LIBM = @LIBGCC_LIBM@
 
 host_noncanonical = @host_noncanonical@
 real_host_noncanonical = @real_host_noncanonical@
@@ -993,9 +994,10 @@ libgcc_s$(SHLIB_EXT): $(libgcc-s-objects) $(extra-parts) libgcc.a
 		@multilib_dir@,$(MULTIDIR),$(subst \
 		@shlib_objs@,$(objects) libgcc.a,$(subst \
 		@shlib_base_name@,libgcc_s,$(subst \
+		@libgcc_libm@,$(LIBGCC_LIBM),$(subst \
 		@shlib_map_file@,$(mapfile),$(subst \
 		@shlib_slibdir_qual@,$(MULTIOSSUBDIR),$(subst \
-		@shlib_slibdir@,$(shlib_slibdir),$(SHLIB_LINK))))))))
+		@shlib_slibdir@,$(shlib_slibdir),$(SHLIB_LINK)))))))))
 
 libunwind$(SHLIB_EXT): $(libunwind-s-objects) $(extra-parts)
 	# @multilib_flags@ is still needed because this may use
diff --git a/libgcc/configure b/libgcc/configure
index 36dbbc1..d33d97c 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -599,6 +599,7 @@ tm_file
 tmake_file
 sfp_machine_header
 set_use_emutls
+LIBGCC_LIBM
 set_have_cc_tls
 vis_hide
 solaris_ld_v2_maps
@@ -5515,6 +5516,39 @@ if test -z "${sfp_machine_header}"; then
 fi
 
 
+# On powerpc libgcc_s references copysignl which is a libm function but
+# glibc apparently also provides it via libc as opposed to uClibc where
+# it lives in libm.
+echo "$as_me:$LINENO: checking for library containing copysignl" >&5
+echo $ECHO_N "checking for library containing copysignl... $ECHO_C" >&6
+if test "${libgcc_cv_copysignl_lib+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+    echo '#include <features.h>' > conftest.c
+    echo 'int the_libc = __UCLIBC__ + __powerpc__;' >> conftest.c
+    libgcc_cv_copysignl_lib="-lc"
+    if { ac_try='${CC-cc} -S conftest.c -o conftest.s 1>&5'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }
+    then
+	libgcc_cv_copysignl_lib="-lm"
+    fi
+    rm -f conftest.*
+
+fi
+echo "$as_me:$LINENO: result: $libgcc_cv_copysignl_lib" >&5
+echo "${ECHO_T}$libgcc_cv_copysignl_lib" >&6
+
+case /${libgcc_cv_copysignl_lib}/ in
+  /-lm/) LIBGCC_LIBM="$LIBGCC_LIBM -lm" ;;
+  *) LIBGCC_LIBM= ;;
+esac
+
+
 # Conditionalize the makefile for this target machine.
 tmake_file_=
 for f in ${tmake_file}
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 8e96caf..9539445 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -585,6 +585,27 @@ if test -z "${sfp_machine_header}"; then
 fi
 AC_SUBST(sfp_machine_header)
 
+# On powerpc libgcc_s references copysignl which is a libm function but
+# glibc apparently also provides it via libc as opposed to uClibc where
+# it lives in libm.
+AC_CACHE_CHECK([for library containing copysignl],
+  libgcc_cv_copysignl_lib, [
+    echo '#include <features.h>' > conftest.c
+    echo 'int the_libc = __UCLIBC__ + __powerpc__;' >> conftest.c
+    libgcc_cv_copysignl_lib="-lc"
+    if AC_TRY_COMMAND(${CC-cc} -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD)
+    then
+	libgcc_cv_copysignl_lib="-lm"
+    fi
+    rm -f conftest.*
+  ])
+
+case /${libgcc_cv_copysignl_lib}/ in
+  /-lm/) LIBGCC_LIBM="$LIBGCC_LIBM -lm" ;;
+  *) LIBGCC_LIBM= ;;
+esac
+AC_SUBST(LIBGCC_LIBM)
+
 # Conditionalize the makefile for this target machine.
 tmake_file_=
 for f in ${tmake_file}
-- 
2.7.4

