On Thu, 15 Jun 2006 23:21:24 -0400
Robert Connolly <[EMAIL PROTECTED]> wrote:

> Hi. I'm having problems getting ssp working with uclibc-20060613 and 
> gcc-4.1.1. Anything I build with -fstack-protector-all does a
> Segmentation fault, but -fstack-protector seems to be okay. This
> happens after the second gcc is installed. I have tried everything I
> can think of, and I'm out of ideas.
> 
> In the second gcc I'm using 'make gcc_cv_libc_provides_ssp=yes', with
I am unfamiliar with gcc_cv_libc_provides_ssp=yes, I might try that
sometime and return results.
> and without --disable-libssp. When I rebuild uClibc with the second
> gcc then everything in /tools segfaults, so it looks like the
> segfault is coming from libuClibc.so (because our uClibc config file
> builds uClibc with -fstack-protector*).
> 
> I have my non-working uclibc differences here:
> http://www.linuxfromscratch.org/~robert/new/uclibc_gcc-4.1.1-HLFS.txt
> 
> P.S.
> I have had the same results with binutils-2.16.93 and 2.16.94.
> 2.16.93 is known to be working with uClibc, 2.16.94 was released this
> week but seems to be okay.
I'll look into 2.16.94 as well.
> 
> robert

Okay, I have been finally getting around to re-enabling SSP into my
systems, so it is helping me identify SSP problems.

My system is currently compiled with (in this order):

uClibc pass_1 0.9.28
gcc pass_1 4.1.1 
uClibc pass_2 0.9.28 (problems with -fstack-protector)
gcc pass_2 4.1.1 (can we build ssp safely into this?)
binutils pass_1 2.16.1 (problems with -fstack-protector)
zlib pass_1 1.2.3 (ssp enabled)
ncurses turtle-kevux-core_pass_1 5.5 (problems with -fstack-protector)

My -fstack-protector problems:
  undefined reference to `__stack_chk_guard'
  undefined reference to `__stack_chk_fail'
  These problems have something to do with gcc/targhooks.c and
  get_identifier(..). The only things that will not work are dealing
  with the get_identifier calls. I donot know enough about
  get_identifier to safeley touch anything with it.

The following patches were applied on all passes mentioned:
(NOTE: my previous gcc-4.1.0 system, I used my own patches, but
overall, Robert's was much better than mine, so I switched over to
his, where possible)
uClibc-0.9.28-add_round-2
uClibc-0.9.28-libc_stack_end-1
gcc-4.1.0-uClibc_conf-1
gcc-4.1.0-specs_x86-1
gcc-4.1.1-no_locale-1
gcc-4.1.0-index_macro-1
gcc-4.1.0-uClibc_libstdc++-1
gcc-4.1.1-no_static_ssp-1
binutils-2.16.1-uClibc_conf-1

Notes on patches:
  - gcc-4.1.1-no_locale-1, does not disable locale, it instead applies
a fix so that a system compiled with --disable-locale will properly
compile.
  - gcc-4.1.1-no_static_ssp-1, this needs to be cleaned up, but it is
the result of fixes some problems with hardened flags on things like
binutils.  It contains three fixes (one hack, one tweak, and one actual
fix)
    - The hack: __stack_chk_fail_local causes problems with binutils,
not being able to leak. I suspect this is not gcc itself, but the fact
that I may be using a binutils-2.16.1, but I cannot confirm exactly
whats wrong.  zlib is another of the three to six packages I've tested
thusfar.
    - The fix: somebody screwed up big time in the libssp coding.  In
the file gcc/targhooks.c, __stack_chk_fail_local is called, only when
HAVE_HIDDEN_VISIBILITY is NOT defined.  However, the only time
HAVE_HIDDEN_VISIBILITY is define in libssp/ssp.c and libssp/ssp-local.c
is when HAVE_HIDDEN_VISIBILITY is defined. WTF!? So I changed the
__stack_chk_fail_local to __stack_chk_fail inside of gcc/targhooks.c
file. (The __stack_chk_fail_local is just wrapper function to
__stack_chk_fail, but this may be some method of security I am unaware
of; nevertheless, I cannot get things to compile properly without this
fix.  Hopefuly this may fix your segfaulting problems.
  - uClibc-0.9.28-add_round-2, is the second pass of my patch to add
round and trunc support to uClibc.  Unlike the previous one, this patch
provides everything needed, so only the patch is needed. (works
flawlessly for me)

How everything was compiled:
  (NOTE: I am doing numerous experiments on file-system structure and
security thereof by moving away from the insecurely designed FHS
standard, and these are the EXACT commands I used, but you can safely
ignore the --prefix, --bindir, and friends)
  (NOTE: I supplied in this mail, my linux-2.6.16.20 headers, than have
had one or two fixes to them. I donot remember if I applied the
arc4random patches.., but these headers work flawlessly for me on an
i686)
  (NOTE: $PR = path to my pre-made files, such as the uClibc
configuration files, TA=target system path (say../mnt/hda/3/), TO =
path to the /tools directory, $WO = path to were all extraction and
compilation is done)
  (NOTE: /toolchain is my path for all compilation stuff for my target
system, so that when I need to squeeze things on an embeded device I
can easily safely add/remove the compilation tools.  I can even mount
them back on using a cd without changing any other files and not
having the toolchain files on a system will probably make it even more
secure)

uClibc_pass1:
  cp -v $PR/uc-1.conf .config
  sed -i -e 's|check_gcc,-Os|check_gcc|' test/Rules.mak Rules.mak
  sed -i -e 's|-Os ||' ldso/ldso/Makefile
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SOURCE=/toolchain LIBGCC=-lgcc_s all
  rm include/asm include/asm-generic include/linux
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SOURCE=/toolchain LIBGCC=-lgcc_s install
  mv -v /usr/lib/* /lib
  rm -Rf /usr/lib /lib/*.a

(NOTE: LIBGCC=-lgcc_s was added on later in the install, as I was
removing all static files, even in the lib/gcc/$target/*.a
It looks like libgcc.a and libgcc_s.so are the same, except gcc
continues the bad practice of naming their static libraries and their
identical shared twin file with seperate name, thus screwing up the
linker when you want either ONLY static or ONLY shared systems.  The
original value for LIBGCC=-lgcc.
 IMPORTANT NOTE: it may be better to just symlink libgcc.a to
libgcc_s.so, once this is done libgcc.a can be removed and no other
projects have to have libgcc tests changed to libgcc_s tests: "ln -vs
libgcc_s.so /lib/libgcc.a", assuming that libgcc_s.so is in /lib )

gcc_pass1:
  sed -i -e 's|\(^CROSS_SYSTEM_HEADER_DIR=\).*|\1 /toolchain/include|g'\
gcc/Makefile.in
  echo -e "\n#undef STARTFILE_PREFIX_SPEC\n#define \
STARTFILE_PREFIX_SPEC \"/lib/\"" >> gcc/config/linux.h
  touch $ldso
  mkdir -vp $WO/build-gcc
  cd $WO/build-gcc
  ../gcc-$VERSION/configure --prefix=/toolchain --disable-static \
--enable-shared --disable-nls --with-local-prefix=/toolchain \
--with-nostdinc --enable-languages=c --with-dynamic-linker=$ldso \
--libexecdir=/toolchain/lib --with-pic --enable-long-long \
--target=$target --build=$target --host=$target --enable-libssp
  make
  make install
  cd $WO
  rm -Rf build-gcc
  ln -vsf gcc /toolchain/bin/cc
  mv -v /toolchain/lib/*.so* /lib
  rm -Rf /toolchain/{info,man} /toolchain/bin/${target}* \
/toolchain/lib/libiberty.a /toolchain/lib/$target/*/*.a
  chmod +x /lib/*.so

  It turns out to be safer to NOT install binutils until uClibc and gcc
BOTH get bootstrapped, to work around the hardcoded specs file issues.
  Also, here is a warning: I am not using locale/NLS, so my
uc-{1,2}.conf donot have locale supported, don't forget to add those as
most other people need them

uClibc_pass2:
 cp -v $PR/uc-2.conf .config
  sed -i -e 's|check_gcc,-Os|check_gcc|' test/Rules.mak Rules.mak
  sed -i -e 's|-Os ||' ldso/ldso/Makefile
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SOURCE=/toolchain LIBGCC=-lgcc_s all
  rm include/asm include/asm-generic include/linux
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SOURCE=/toolchain LIBGCC=-lgcc_s install
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SOURCE=/toolchain LIBGCC=-lgcc_s headers
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SORUCE=/toolchain LIBGCC=-lgcc_s CC="gcc \
-Wl,--dynamic-linker,/lib/ld-uClibc.so.0 /lib/ld-uClibc.so.0" -C utils
  make DEVEL_PREFIX=/usr/ SHARED_LIB_LOADER_PREFIX=/lib \
RUNTIME_PREFIX=/ KERNEL_SOURCE=/toolchain LIBGCC=-lgcc_s -C utils \
install
  ldconfig
  mkdir -vp /etc/sysconfig
  echo "CST6CDT" > /etc/sysconfig/timezone
  rm -Rf /lib/*.a /usr/lib/*.{a,so,0}
  chmod +x /lib/*.so*
  ln -vsf libc.so.0 /lib/libc.so
  ln -vsf libcrypt.so.0 /lib/libcrypt.so
  ln -vsf libdl.so.0 /lib/libdl.so
  ln -vsf libm.so.0 /lib/libm.so
  ln -vsf libnsl.so.0 /lib/libnsl.so
  ln -vsf libpthread.so.0 /lib/libpthread.so
  ln -vsf libresolv.so.0 /lib/libresolv.so
  ln -vsf librt.so.0 /lib/librt.so

gcc_pass2:
  sed -i -e 's|\(^CROSS_SYSTEM_HEADER_DIR\
=\).*|\1 /toolchain/include|g' gcc/Makefile.in
  sed -i -e 's|\(^NATIVE_SYSTEM_HEADER_DIR\
=\).*|\1 /toolchain/include|g' gcc/Makefile.in
  echo -e "\n#undef STARTFILE_PREFIX_SPEC\n#define\
STARTFILE_PREFIX_SPEC \"/lib/\"" >> gcc/config/linux.h
  mkdir -vp $WO/build-gcc
  cd $WO/build-gcc
  ../gcc-$VERSION/configure --prefix=/toolchain --disable-static\
--enable-shared --disable-nls --with-local-prefix=/toolchain\
--with-nostdinc --enable-languages=c,c++ --with-dynamic-linker=$ldso\
--libexecdir=/toolchain/lib --with-pic --enable-long-long\
--target=$target --build=$target --host=$target --enable-libs
  make
  make install
  cd $WO
  rm -Rf build-gcc
  mv -v /toolchain/lib/*.so* /lib
  rm -Rf /toolchain/{info,man} /toolchain/bin/${target}* \
/toolchain/lib/lib{iberty,stdc++_pic,supc++,ssp_nonshared}.a \
/toolchain/lib/lib{supc++,ssp_nonshared}.la /toolchain/lib/$target/*/*.a

binutils_pass1:
  $MD $WO/build-binutils
  cd $WO/build-binutils
  ../binutils-$VERSION/configure --prefix=/ \
--includedir=/toolchain/include --bindir=/bin --sbindir=/sbin \
--localstatedir=/var --datadir=/share --sysconfdir=/etc \
--libexecdir=/lib --disable-static --enable-shared --disable-nls \
--with-pic --target=$target --host=$target --build=$target \
--with-lib-path=/lib
  make
  make install
  rm -Rf /lib/ldscripts
  mv -v /$target/bin/* /toolchain/bin
  mv -v /$target/lib/* /lib
  mv -v /bin/{addr2line,c++filt,gprof,nm,objcopy,size,strings} \
/toolchain/bin
 cd $WO
 rm -Rf build-binutils /$target /lib/*.{a,la} /info /man \
/bin/{ar,as,ld,nm,objdump,ranlib,strip}

zlib_pass1
  old_CFLAGS="$CFLAGS"
  export CFLAGS="-fstack-protector $CFLAGS" 
  ./configure --prefix=/ --includedir=/toolchain/include --libdir=/lib \
--sharedir=/share --enable-shared --disable-nls --shared
  make
  make install
  rm -Rf /share/man
  export CFLAGS="$old_CFLAGS"
  unset old_CFLAGS

ncurses_pass1
./configure --prefix=/ --includedir=/toolchain/include --bindir=/bin \
--sbindir=/sbin --localstatedir=/var --datadir=/share --sysconfdir=/etc\
 --libexecdir=/lib --disable-static --enable-shared --disable-nls \
--with-pic --without-normal --without-debug --without-ada \
--enable-overwrite --with-shared --enable-colorfgbg --enable-symlinks \
--enable-ext-mouse --with-termlib --without-gpm --enable-termcap \
--with-termpath=/etc/termcap --enable-getcap --enable-const \
--enable-sigwinch --enable-tcap-names
  make
  make install
  rm -Rf /lib/*.a /man
  chmod +x /lib/*.so

-- 
Kevin Day


-- 

Attachment: uc-2.conf
Description: Binary data

Submitted By:            Kevin Day <kevin AT kevux DOT org>
Date:                    2006-06-04
Initial Package Version: 0.9.28
Upstream Status:         submitted to hlfs for purposes of their projects
Description:             Adds support for round, lround, llround, roundf, lroundf, llroundf, trunc, truncf

--- uClibc-0.9.28/libc/sysdeps/linux/common/bits/mathcalls.h.orig	2006-06-04 12:06:04.000000000 -0500
+++ uClibc-0.9.28/libc/sysdeps/linux/common/bits/mathcalls.h	2006-06-04 12:06:21.000000000 -0500
@@ -284,7 +284,7 @@
 
 /* Round X to nearest integral value, rounding halfway cases away from
    zero.  */
-__MATHCALL (round,, (_Mdouble_ __x));
+__MATHCALLX (round,, (_Mdouble_ __x), (__const__));
 
 /* Round X to the integral value in floating-point format nearest but
    not larger in magnitude.  */
--- uClibc-0.9.28/include/tgmath.h.orig	2006-06-04 12:06:15.000000000 -0500
+++ uClibc-0.9.28/include/tgmath.h	2006-06-04 12:06:21.000000000 -0500
@@ -345,13 +345,13 @@
 
 /* Round X to nearest integral value according to current rounding
    direction.  */
-#define lrint(Val) __TGMATH_UNARY_REAL_ONLY (Val, lrint)
-#define llrint(Val) __TGMATH_UNARY_REAL_ONLY (Val, llrint)
+#define lrint(Val) __TGMATH_UNARY_REAL_ONLY (Val, long int, lrint)
+#define llrint(Val) __TGMATH_UNARY_REAL_ONLY (Val, long long int, llrint)
 
 /* Round X to nearest integral value, rounding halfway cases away from
    zero.  */
-#define lround(Val) __TGMATH_UNARY_REAL_ONLY (Val, lround)
-#define llround(Val) __TGMATH_UNARY_REAL_ONLY (Val, llround)
+#define lround(Val) __TGMATH_UNARY_REAL_ONLY (Val, long int, lround)
+#define llround(Val) __TGMATH_UNARY_REAL_ONLY (Val, long long int, llround)
 
 
 /* Return X with its signed changed to Y's.  */
--- uClibc-0.9.28/libm/Makefile.orig	2006-06-04 11:52:32.000000000 -0500
+++ uClibc-0.9.28/libm/Makefile	2006-06-04 11:53:03.000000000 -0500
@@ -66,15 +66,17 @@
          w_cosh.c w_drem.c w_exp.c w_fmod.c w_gamma.c w_gamma_r.c\
          w_hypot.c w_j0.c w_j1.c w_jn.c w_lgamma.c w_lgamma_r.c\
          w_log.c w_log10.c w_pow.c w_remainder.c w_scalb.c w_sinh.c\
-         w_sqrt.c fpmacros.c nan.c s_ceilf.c s_floorf.c
+         w_sqrt.c fpmacros.c nan.c s_ceilf.c s_floorf.c \
+	 s_llroundf.c s_llround.c s_lroundf.c s_lround.c s_round.c s_roundf.c s_trunc.c s_truncf.c
 FL_MOBJ = acosf.o acoshf.o asinf.o asinhf.o atan2f.o atanf.o atanhf.o cbrtf.o \
 	ceilf.o copysignf.o cosf.o coshf.o erfcf.o erff.o exp2f.o expf.o \
 	expm1f.o fabsf.o fdimf.o floorf.o fmaf.o fmaxf.o fminf.o fmodf.o \
 	frexpf.o hypotf.o ilogbf.o ldexpf.o lgammaf.o log10f.o log1pf.o \
-	log2f.o logbf.o logf.o lrintf.o lroundf.o modff.o nearbyintf.o \
-	nextafterf.o powf.o remainderf.o remquof.o rintf.o roundf.o \
+	log2f.o logbf.o logf.o lrintf.o modff.o nearbyintf.o \
+	nextafterf.o powf.o remainderf.o remquof.o rintf.o \
 	scalblnf.o scalbnf.o sinf.o sinhf.o sqrtf.o tanf.o tanhf.o \
-	tgammaf.o truncf.o
+	tgammaf.o \
+	llroundf.o llround.o lroundf.o lround.o round.o roundf.o trunc.o truncf.o
 else
 # This list of math functions was taken from POSIX/IEEE 1003.1b-1993
 CSRC =   w_acos.c w_asin.c s_atan.c w_atan2.c s_ceil.c s_cos.c \
--- uClibc-0.9.28/libm/math_private.h.orig	2006-06-04 11:52:17.000000000 -0500
+++ uClibc-0.9.28/libm/math_private.h	2006-06-04 11:53:03.000000000 -0500
@@ -53,6 +53,23 @@
   } parts;
 } ieee_double_shape_type;
 
+/* A union which permits us to convert between a long double and
+   four 32 bit ints or two 64 bit ints.  */
+  
+typedef union
+{
+  long double value;
+  struct
+  {
+    u_int64_t msw;
+    u_int64_t lsw;
+  } parts64;
+  struct
+  { 
+    u_int32_t w0, w1, w2, w3;
+  } parts32;
+} ieee854_long_double_shape_type;
+  
 #else
 
 typedef union
@@ -65,6 +82,23 @@
   } parts;
 } ieee_double_shape_type;
 
+/* A union which permits us to convert between a long double and
+   four 32 bit ints or two 64 bit ints.  */
+  
+typedef union
+{
+  long double value;
+  struct
+  {
+    u_int64_t lsw;
+    u_int64_t msw;
+  } parts64;
+  struct
+  {
+    u_int32_t w3, w2, w1, w0;
+  } parts32;
+} ieee854_long_double_shape_type;
+
 #endif
 
 /* Get two 32 bit ints from a double.  */
@@ -152,6 +186,54 @@
   (d) = sf_u.value;						\
 } while (0)
 
+/* Get two 64 bit ints from a long double.  */
+
+#define GET_LDOUBLE_WORDS64(ix0,ix1,d)                          \
+do {                                                            \
+  ieee854_long_double_shape_type qw_u;                          \
+  qw_u.value = (d);                                             \
+  (ix0) = qw_u.parts64.msw;                                     \
+  (ix1) = qw_u.parts64.lsw;                                     \
+} while (0)
+
+/* Set a long double from two 64 bit ints.  */
+
+#define SET_LDOUBLE_WORDS64(d,ix0,ix1)                          \
+do {                                                            \
+  ieee854_long_double_shape_type qw_u;                          \
+  qw_u.parts64.msw = (ix0);                                     \
+  qw_u.parts64.lsw = (ix1);                                     \
+  (d) = qw_u.value;                                             \
+} while (0)
+
+/* Get the more significant 64 bits of a long double mantissa.  */
+
+#define GET_LDOUBLE_MSW64(v,d)                                  \
+do {                                                            \
+  ieee854_long_double_shape_type sh_u;                          \
+  sh_u.value = (d);                                             \
+  (v) = sh_u.parts64.msw;                                       \
+} while (0)
+
+/* Set the more significant 64 bits of a long double mantissa from an int.  */
+
+#define SET_LDOUBLE_MSW64(d,v)                                  \
+do {                                                            \
+  ieee854_long_double_shape_type sh_u;                          \
+  sh_u.value = (d);                                             \
+  sh_u.parts64.msw = (v);                                       \
+  (d) = sh_u.value;                                             \
+} while (0)
+
+/* Get the least significant 64 bits of a long double mantissa.  */
+
+#define GET_LDOUBLE_LSW64(v,d)                                  \
+do {                                                            \
+  ieee854_long_double_shape_type sh_u;                          \
+  sh_u.value = (d);                                             \
+  (v) = sh_u.parts64.lsw;                                       \
+} while (0)
+
 /* ieee style elementary functions */
 extern double __ieee754_sqrt __P((double));
 extern double __ieee754_acos __P((double));
--- uClibc-0.9.28/libm/s_llround.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_llround.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,75 @@
+/* Round long double value to long long int.
+   Copyright (C) 1997, 1999, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997 and
+   		  Jakub Jelinek <[EMAIL PROTECTED]>, 1999.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+long long int
+llround (double x)
+{
+  int64_t j0;
+  u_int64_t i1, i0;
+  long long int result;
+  int sign;
+
+  GET_LDOUBLE_WORDS64 (i0, i1, x);
+  j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
+  sign = (i0 & 0x8000000000000000ULL) != 0 ? -1 : 1;
+  i0 &= 0x0000ffffffffffffLL;
+  i0 |= 0x0001000000000000LL;
+
+  if (j0 < 48)
+    {
+      if (j0 < 0)
+	return j0 < -1 ? 0 : sign;
+      else
+	{
+	  i0 += 0x0000800000000000LL >> j0;
+	  result = i0 >> (48 - j0);
+	}
+    }
+  else if (j0 < (int32_t) (8 * sizeof (long long int)) - 1)
+    {
+      if (j0 >= 112)
+	result = ((long long int) i0 << (j0 - 48)) | (i1 << (j0 - 112));
+      else
+	{
+	  u_int64_t j = i1 + (0x8000000000000000ULL >> (j0 - 48));
+	  if (j < i1)
+	    ++i0;
+
+	  if (j0 == 48)
+	    result = (long long int) i0;
+	  else
+	    result = ((long long int) i0 << (j0 - 48)) | (j >> (112 - j0));
+	}
+    }
+  else
+    {
+      /* The number is too large.  It is left implementation defined
+	 what happens.  */
+      return (long long int) x;
+    }
+
+  return sign * result;
+}
--- uClibc-0.9.28/libm/s_llroundf.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_llroundf.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,61 @@
+/* Round float value to long long int.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+long long int
+llroundf (float x)
+{
+  int32_t j0;
+  u_int32_t i;
+  long long int result;
+  int sign;
+
+  GET_FLOAT_WORD (i, x);
+  j0 = ((i >> 23) & 0xff) - 0x7f;
+  sign = (i & 0x80000000) != 0 ? -1 : 1;
+  i &= 0x7fffff;
+  i |= 0x800000;
+
+  if (j0 < (int32_t) (8 * sizeof (long long int)) - 1)
+    {
+      if (j0 < 0)
+	return j0 < -1 ? 0 : sign;
+      else if (j0 >= 23)
+	result = (long long int) i << (j0 - 23);
+      else
+	{
+	  i += 0x400000 >> j0;
+
+	  result = i >> (23 - j0);
+	}
+    }
+  else
+    {
+      /* The number is too large.  It is left implementation defined
+	 what happens.  */
+      return (long long int) x;
+    }
+
+  return sign * result;
+}
--- uClibc-0.9.28/libm/s_lround.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_lround.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,75 @@
+/* Round long double value to long int.
+   Copyright (C) 1997, 1999, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997 and
+   		  Jakub Jelinek <[EMAIL PROTECTED]>, 1999.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+long int
+lround (double x)
+{
+  int64_t j0;
+  u_int64_t i1, i0;
+  long int result;
+  int sign;
+
+  GET_LDOUBLE_WORDS64 (i0, i1, x);
+  j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
+  sign = (i0 & 0x8000000000000000ULL) != 0 ? -1 : 1;
+  i0 &= 0x0000ffffffffffffLL;
+  i0 |= 0x0001000000000000LL;
+
+  if (j0 < 48)
+    {
+      if (j0 < 0)
+	return j0 < -1 ? 0 : sign;
+      else
+	{
+	  i0 += 0x0000800000000000LL >> j0;
+	  result = i0 >> (48 - j0);
+	}
+    }
+  else if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
+    {
+      if (j0 >= 112)
+	result = ((long int) i0 << (j0 - 48)) | (i1 << (j0 - 112));
+      else
+	{
+	  u_int64_t j = i1 + (0x8000000000000000ULL >> (j0 - 48));
+	  if (j < i1)
+	    ++i0;
+
+	  if (j0 == 48)
+	    result = (long int) i0;
+	  else
+	    result = ((long int) i0 << (j0 - 48)) | (j >> (112 - j0));
+	}
+    }
+  else
+    {
+      /* The number is too large.  It is left implementation defined
+	 what happens.  */
+      return (long int) x;
+    }
+
+  return sign * result;
+}
--- uClibc-0.9.28/libm/s_lroundf.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_lroundf.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,61 @@
+/* Round float value to long int.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+long int
+lroundf (float x)
+{
+  int32_t j0;
+  u_int32_t i;
+  long int result;
+  int sign;
+
+  GET_FLOAT_WORD (i, x);
+  j0 = ((i >> 23) & 0xff) - 0x7f;
+  sign = (i & 0x80000000) != 0 ? -1 : 1;
+  i &= 0x7fffff;
+  i |= 0x800000;
+
+  if (j0 < (int32_t) (8 * sizeof (long int)) - 1)
+    {
+      if (j0 < 0)
+	return j0 < -1 ? 0 : sign;
+      else if (j0 >= 23)
+	result = (long int) i << (j0 - 23);
+      else
+	{
+	  i += 0x400000 >> j0;
+
+	  result = i >> (23 - j0);
+	}
+    }
+  else
+    {
+      /* The number is too large.  It is left implementation defined
+	 what happens.  */
+      return (long int) x;
+    }
+
+  return sign * result;
+}
--- uClibc-0.9.28/libm/s_round.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_round.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,92 @@
+/* Round double to integer away from zero.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+static const double huge = 1.0e300;
+
+
+double
+round (double x)
+{
+  int32_t i0, j0;
+  u_int32_t i1;
+
+  EXTRACT_WORDS (i0, i1, x);
+  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
+  if (j0 < 20)
+    {
+      if (j0 < 0)
+	{
+	  if (huge + x > 0.0)
+	    {
+	      i0 &= 0x80000000;
+	      if (j0 == -1)
+		i0 |= 0x3ff00000;
+	      i1 = 0;
+	    }
+	}
+      else
+	{
+	  u_int32_t i = 0x000fffff >> j0;
+	  if (((i0 & i) | i1) == 0)
+	    /* X is integral.  */
+	    return x;
+	  if (huge + x > 0.0)
+	    {
+	      /* Raise inexact if x != 0.  */
+	      i0 += 0x00080000 >> j0;
+	      i0 &= ~i;
+	      i1 = 0;
+	    }
+	}
+    }
+  else if (j0 > 51)
+    {
+      if (j0 == 0x400)
+	/* Inf or NaN.  */
+	return x + x;
+      else
+	return x;
+    }
+  else
+    {
+      u_int32_t i = 0xffffffff >> (j0 - 20);
+      if ((i1 & i) == 0)
+	/* X is integral.  */
+	return x;
+
+      if (huge + x > 0.0)
+	{
+	  /* Raise inexact if x != 0.  */
+	  u_int32_t j = i1 + (1 << (51 - j0));
+	  if (j < i1)
+	    i0 += 1;
+	  i1 = j;
+	}
+      i1 &= ~i;
+    }
+
+  INSERT_WORDS (x, i0, i1);
+  return x;
+}
--- uClibc-0.9.28/libm/s_roundf.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_roundf.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,72 @@
+/* Round float to integer away from zero.
+   Copyright (C) 1997 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+static const float huge = 1.0e30;
+
+
+float
+roundf (float x)
+{
+  int32_t i0, j0;
+
+  GET_FLOAT_WORD (i0, x);
+  j0 = ((i0 >> 23) & 0xff) - 0x7f;
+  if (j0 < 23)
+    {
+      if (j0 < 0)
+	{
+	  if (huge + x > 0.0F)
+	    {
+	      i0 &= 0x80000000;
+	      if (j0 == -1)
+		i0 |= 0x3f800000;
+	    }
+	}
+      else
+	{
+	  u_int32_t i = 0x007fffff >> j0;
+	  if ((i0 & i) == 0)
+	    /* X is integral.  */
+	    return x;
+	  if (huge + x > 0.0F)
+	    {
+	      /* Raise inexact if x != 0.  */
+	      i0 += 0x00400000 >> j0;
+	      i0 &= ~i;
+	    }
+	}
+    }
+  else
+    {
+      if (j0 == 0x80)
+	/* Inf or NaN.  */
+	return x + x;
+      else
+	return x;
+    }
+
+  SET_FLOAT_WORD (x, i0);
+  return x;
+}
--- uClibc-0.9.28/libm/s_trunc.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_trunc.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,56 @@
+/* Truncate argument to nearest integral value not larger than the argument.
+   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+double
+trunc (double x)
+{
+  int32_t i0, j0;
+  u_int32_t i1;
+  int sx;
+
+  EXTRACT_WORDS (i0, i1, x);
+  sx = i0 & 0x80000000;
+  j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
+  if (j0 < 20)
+    {
+      if (j0 < 0)
+	/* The magnitude of the number is < 1 so the result is +-0.  */
+	INSERT_WORDS (x, sx, 0);
+      else
+	INSERT_WORDS (x, sx | (i0 & ~(0x000fffff >> j0)), 0);
+    }
+  else if (j0 > 51)
+    {
+      if (j0 == 0x400)
+	/* x is inf or NaN.  */
+	return x + x;
+    }
+  else
+    {
+      INSERT_WORDS (x, i0, i1 & ~(0xffffffffu >> (j0 - 20)));
+    }
+
+  return x;
+}
--- uClibc-0.9.28/libm/s_truncf.c.orig	2006-06-04 11:54:40.000000000 -0500
+++ uClibc-0.9.28/libm/s_truncf.c	2006-06-04 12:00:19.000000000 -0500
@@ -0,0 +1,51 @@
+/* Truncate argument to nearest integral value not larger than the argument.
+   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <[EMAIL PROTECTED]>, 1997.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <math.h>
+
+#include "math_private.h"
+
+
+float
+truncf (float x)
+{
+  int32_t i0, j0;
+  int sx;
+
+  GET_FLOAT_WORD (i0, x);
+  sx = i0 & 0x80000000;
+  j0 = ((i0 >> 23) & 0xff) - 0x7f;
+  if (j0 < 23)
+    {
+      if (j0 < 0)
+	/* The magnitude of the number is < 1 so the result is +-0.  */
+	SET_FLOAT_WORD (x, sx);
+      else
+	SET_FLOAT_WORD (x, sx | (i0 & ~(0x007fffff >> j0)));
+    }
+  else
+    {
+      if (j0 == 0x80)
+	/* x is inf or NaN.  */
+	return x + x;
+    }
+
+  return x;
+}
Submitted By:            Kevin Day <kevin AT kevux DOT org>
Date:                    2006-06-13
Initial Package Version: 4.1.1
Upstream Status:         Not submitted
Description:             There are some serious flaws in the libssp and gcc-4.1.{0,1}
Most of the problems are mentioned at their relevant parts in the patch.
gcc/targhooks.c simply causes major issues with ssp.
I am not sure why they provided a file such as libssp_nonshared.a, the static file should be named the same so that the linker could work either way.

--- gcc-4.1.1/gcc/gcc.c.orig	2006-06-13 19:08:40.000000000 -0500
+++ gcc-4.1.1/gcc/gcc.c	2006-06-13 19:08:56.000000000 -0500
@@ -674,7 +674,7 @@
 #ifdef TARGET_LIBC_PROVIDES_SSP
 #define LINK_SSP_SPEC "%{fstack-protector:}"
 #else
-#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}"
+#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all: -lssp}"
 #endif
 #endif
 
--- gcc-4.1.1/gcc/targhooks.c.orig	2006-06-15 00:04:15.000000000 +0000
+++ gcc-4.1.1/gcc/targhooks.c	2006-06-15 00:04:40.000000000 +0000
@@ -403,7 +403,7 @@
     {
       t = build_function_type_list (void_type_node, NULL_TREE);
       t = build_decl (FUNCTION_DECL,
-		      get_identifier ("__stack_chk_fail_local"), t);
+		      get_identifier ("__stack_chk_fail"), t);
       TREE_STATIC (t) = 1;
       TREE_PUBLIC (t) = 1;
       DECL_EXTERNAL (t) = 1;
--- gcc-4.1.1/libssp/ssp-local.c.orig	2006-06-15 00:51:08.000000000 +0000
+++ gcc-4.1.1/libssp/ssp-local.c	2006-06-15 00:52:13.000000000 +0000
@@ -41,6 +41,8 @@
    Using this entry point may avoid the load of a GP entirely for the
    function, making the overall code smaller.  */
 
+// This somehow breaks under the uClibc system, removing it allows things to compile with hardened specs with/without ssp_nonshared.a
+/*
 #ifdef HAVE_HIDDEN_VISIBILITY
 void
 __attribute__((visibility ("hidden")))
@@ -49,3 +51,4 @@
   __stack_chk_fail ();
 }
 #endif
+*/
--- gcc-4.1.1/libssp/ssp.c.orig	2006-06-15 00:51:01.000000000 +0000
+++ gcc-4.1.1/libssp/ssp.c	2006-06-15 00:52:56.000000000 +0000
@@ -168,6 +168,8 @@
   fail (msg, strlen (msg), "buffer overflow detected: terminated");
 }
 
+// This somehow breaks under the uClibc system, removing it allows things to compile with hardened specs with/without ssp_nonshared.a
+/*
 #ifdef HAVE_HIDDEN_VISIBILITY
 void
 __attribute__((visibility ("hidden")))
@@ -176,3 +178,4 @@
   __stack_chk_fail ();
 }
 #endif
+*/
Submitted By:            Kevin Day <kevin AT kevux DOT org>
Date:                    2006-04-27
Initial Package Version: 4.1.0
Upstream Status:         Not submitted
Description:             Fixes to make sure --disable-nls works during compilation. Normally, the compiler fails saying that it cannot conver the __ctype_toupper to a const int *, so I added a type cast to handle this.  Should be pretty safe, given that they probably intended the cast.

--- gcc-4.1.0/libstdc++-v3/config/os/gnu-linux/ctype_noninline.h.orig	2006-04-27 17:48:36.000000000 +0000
+++ gcc-4.1.0/libstdc++-v3/config/os/gnu-linux/ctype_noninline.h	2006-04-27 17:44:08.000000000 +0000
@@ -82,8 +82,8 @@
     _M_tolower = *__ctype_tolower_loc();
     _M_table = __table ? __table : *__ctype_b_loc();
 #else
-    _M_toupper = __ctype_toupper;
-    _M_tolower = __ctype_tolower;
+    _M_toupper = (const int *) __ctype_toupper;
+    _M_tolower = (const int *) __ctype_tolower;
     _M_table = __table ? __table : __ctype_b;
 #endif
     setlocale(LC_CTYPE, __old);
@@ -117,8 +117,8 @@
     _M_tolower = *__ctype_tolower_loc();
     _M_table = __table ? __table : *__ctype_b_loc();
 #else
-    _M_toupper = __ctype_toupper;
-    _M_tolower = __ctype_tolower;
+    _M_toupper = (const int *) __ctype_toupper;
+    _M_tolower = (const int *) __ctype_tolower;
     _M_table = __table ? __table : __ctype_b;
 #endif
     setlocale(LC_CTYPE, __old);

Attachment: uc-1.conf
Description: Binary data

-- 
http://linuxfromscratch.org/mailman/listinfo/hlfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to