[PATCH] PPC libgcc compatibility
Franz Sirl
Franz.Sirl-kernel@lauterbach.com
Sun May 12 14:06:00 GMT 2002
Hi,
the appended patch implements most of the libgcc routines that may cause
broken binaries if a gcc-3.1 compiled glibc is installed. The symbols fixed
are (copied from gcc/libgcc2.c):
__ashldi3
__ashrdi3
__lshrdi3
__cmpdi2
__ucmpdi2
__divdi3
__moddi3
__udivdi3
__umoddi3
__fixdfdi
__fixsfdi
__fixunsdfdi
__fixunssfdi
The symbols not (yet? I don't know if I want to go down the float road) fixed:
__floatdidf
__floatdisf
Note that the list of symbols seems to be complete, I got reports of fully
installed RedHat and Suse systems and merged them together.
The other thing missing are all soft-float libgcc symbols. My guess is that
these happen only in 100% user controlled environments where you either do
full upgrades of everything or where using LD_PRELOAD=/lib/libgcc_s.so.1 or
/etc/ld.so.preload is no issue.
BTW, in the light of the gcc-3.1 release, these 2 patches should be installed
on the branch to cut down the number of warnings:
2001-11-29 Ulrich Drepper <drepper@redhat.com>
* posix/regex.h: Define __restrict_arr correctly.
2001-11-29 Andreas Jaeger <aj@suse.de>
* sysdeps/generic/abort.c: Include libioP.h for
_IO_flush_all_lockp prototype.
Franz.
* sysdeps/powerpc/Makefile (sysdeps_routines): Add divdi3, cmpdi2,
shdi3, fixdfdi, fixsfdi in csu dir.
(shared-only-routines): Likewise.
* sysdeps/wordsize-32/cmpdi2.c: New file.
* sysdeps/wordsize-32/shdi3.c: New file.
* sysdeps/wordsize-32/fixdfdi.c: New file.
* sysdeps/wordsize-32/fixsfdi.c: New file.
* sysdeps/powerpc/Versions (__divdi3, __moddi3, __udivdi3, __umoddi3,
__ashldi3, __ashrdi3, __lshrdi3, __cmpdi2, __ucmpdi2, __fixdfdi,
__fixsfdi, __fixunsdfdi, __fixunssfdi): Export at GLIBC_2.0.
-------------- next part --------------
Index: sysdeps/powerpc/Makefile
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/powerpc/Makefile,v
retrieving revision 1.13
diff -u -p -r1.13 Makefile
--- sysdeps/powerpc/Makefile 27 Nov 2000 23:32:47 -0000 1.13
+++ sysdeps/powerpc/Makefile 9 May 2002 12:00:08 -0000
@@ -34,6 +34,11 @@ CFLAGS-initfini.s = -g0 -fpic -O1
CFLAGS-init.o = -G0
CFLAGS-gmon-start.o = -G0
endif
+ifeq (yes,$(build-shared))
+# Compatibility
+sysdep_routines += divdi3 cmpdi2 shdi3 fixdfdi fixsfdi
+shared-only-routines += divdi3 cmpdi2 shdi3 fixdfdi fixsfdi
+endif
endif
ifeq ($(subdir),string)
Index: sysdeps/powerpc/Versions
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/powerpc/Versions,v
retrieving revision 1.2
diff -u -p -r1.2 Versions
--- sysdeps/powerpc/Versions 28 Feb 2000 21:27:57 -0000 1.2
+++ sysdeps/powerpc/Versions 9 May 2002 12:00:08 -0000
@@ -1,3 +1,14 @@
+libc {
+ GLIBC_2.0 {
+ # Functions from libgcc.
+ __divdi3; __moddi3; __udivdi3; __umoddi3;
+ __cmpdi2; __ucmpdi2;
+ __ashldi3; __ashrdi3; __lshrdi3;
+ __fixdfdi; __fixunsdfdi;
+ __fixsfdi; __fixunssfdi;
+ }
+}
+
libm {
GLIBC_2.1 {
# symbols used in macros from sysdeps/powerpc/bits/fenv.h
--- /dev/null Thu Jan 1 01:00:00 1970
+++ sysdeps/wordsize-32/cmpdi2.c Wed May 8 22:47:36 2002
@@ -0,0 +1,89 @@
+/* 64-bit multiplication and division
+ Copyright (C) 1989, 1992-1999, 2000, 2001, 2002
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <endian.h>
+#include <stdlib.h>
+#include <bits/wordsize.h>
+
+#if __WORDSIZE != 32
+#error This is for 32-bit targets only
+#endif
+
+typedef unsigned int UQItype __attribute__ ((mode (QI)));
+typedef int SItype __attribute__ ((mode (SI)));
+typedef unsigned int USItype __attribute__ ((mode (SI)));
+typedef int DItype __attribute__ ((mode (DI)));
+typedef unsigned int UDItype __attribute__ ((mode (DI)));
+#define Wtype SItype
+#define HWtype SItype
+#define DWtype DItype
+#define UWtype USItype
+#define UHWtype USItype
+#define UDWtype UDItype
+#define W_TYPE_SIZE 32
+
+#include <stdlib/longlong.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+struct DWstruct { Wtype high, low;};
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+struct DWstruct { Wtype low, high;};
+#else
+#error Unhandled endianity
+#endif
+typedef union { struct DWstruct s; DWtype ll; } DWunion;
+
+
+Wtype
+__cmpdi2 (DWtype a, DWtype b)
+{
+ DWunion au, bu;
+
+ au.ll = a, bu.ll = b;
+
+ if (au.s.high < bu.s.high)
+ return 0;
+ else if (au.s.high > bu.s.high)
+ return 2;
+ if ((UWtype) au.s.low < (UWtype) bu.s.low)
+ return 0;
+ else if ((UWtype) au.s.low > (UWtype) bu.s.low)
+ return 2;
+ return 1;
+}
+
+
+Wtype
+__ucmpdi2 (DWtype a, DWtype b)
+{
+ DWunion au, bu;
+
+ au.ll = a, bu.ll = b;
+
+ if ((UWtype) au.s.high < (UWtype) bu.s.high)
+ return 0;
+ else if ((UWtype) au.s.high > (UWtype) bu.s.high)
+ return 2;
+ if ((UWtype) au.s.low < (UWtype) bu.s.low)
+ return 0;
+ else if ((UWtype) au.s.low > (UWtype) bu.s.low)
+ return 2;
+ return 1;
+}
--- /dev/null Thu Jan 1 01:00:00 1970
+++ sysdeps/wordsize-32/fixdfdi.c Thu May 9 13:55:10 2002
@@ -0,0 +1,92 @@
+/* 64-bit multiplication and division
+ Copyright (C) 1989, 1992-1999, 2000, 2001, 2002
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <endian.h>
+#include <stdlib.h>
+#include <bits/wordsize.h>
+
+#if __WORDSIZE != 32
+#error This is for 32-bit targets only
+#endif
+
+typedef unsigned int UQItype __attribute__ ((mode (QI)));
+typedef int SItype __attribute__ ((mode (SI)));
+typedef unsigned int USItype __attribute__ ((mode (SI)));
+typedef int DItype __attribute__ ((mode (DI)));
+typedef unsigned int UDItype __attribute__ ((mode (DI)));
+typedef float SFtype __attribute__ ((mode (SF)));
+typedef float DFtype __attribute__ ((mode (DF)));
+#define Wtype SItype
+#define HWtype SItype
+#define DWtype DItype
+#define UWtype USItype
+#define UHWtype USItype
+#define UDWtype UDItype
+#define W_TYPE_SIZE 32
+
+#include <stdlib/longlong.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+struct DWstruct { Wtype high, low;};
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+struct DWstruct { Wtype low, high;};
+#else
+#error Unhandled endianity
+#endif
+typedef union { struct DWstruct s; DWtype ll; } DWunion;
+
+#define WORD_SIZE __WORDSIZE
+#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
+
+DWtype
+__fixunsdfdi (DFtype a)
+{
+ DFtype b;
+ UDWtype v;
+
+ if (a < 0)
+ return 0;
+
+ /* Compute high word of result, as a flonum. */
+ b = (a / HIGH_WORD_COEFF);
+ /* Convert that to fixed (but not to DWtype!),
+ and shift it into the high word. */
+ v = (UWtype) b;
+ v <<= WORD_SIZE;
+ /* Remove high part from the DFtype, leaving the low part as flonum. */
+ a -= (DFtype)v;
+ /* Convert that to fixed (but not to DWtype!) and add it in.
+ Sometimes A comes out negative. This is significant, since
+ A has more bits than a long int does. */
+ if (a < 0)
+ v -= (UWtype) (- a);
+ else
+ v += (UWtype) a;
+ return v;
+}
+
+
+DWtype
+__fixdfdi (DFtype a)
+{
+ if (a < 0)
+ return - __fixunsdfdi (-a);
+ return __fixunsdfdi (a);
+}
--- /dev/null Thu Jan 1 01:00:00 1970
+++ sysdeps/wordsize-32/fixsfdi.c Thu May 9 13:54:26 2002
@@ -0,0 +1,98 @@
+/* 64-bit multiplication and division
+ Copyright (C) 1989, 1992-1999, 2000, 2001, 2002
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <endian.h>
+#include <stdlib.h>
+#include <bits/wordsize.h>
+
+#if __WORDSIZE != 32
+#error This is for 32-bit targets only
+#endif
+
+typedef unsigned int UQItype __attribute__ ((mode (QI)));
+typedef int SItype __attribute__ ((mode (SI)));
+typedef unsigned int USItype __attribute__ ((mode (SI)));
+typedef int DItype __attribute__ ((mode (DI)));
+typedef unsigned int UDItype __attribute__ ((mode (DI)));
+typedef float SFtype __attribute__ ((mode (SF)));
+typedef float DFtype __attribute__ ((mode (DF)));
+#define Wtype SItype
+#define HWtype SItype
+#define DWtype DItype
+#define UWtype USItype
+#define UHWtype USItype
+#define UDWtype UDItype
+#define W_TYPE_SIZE 32
+
+#include <stdlib/longlong.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+struct DWstruct { Wtype high, low;};
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+struct DWstruct { Wtype low, high;};
+#else
+#error Unhandled endianity
+#endif
+typedef union { struct DWstruct s; DWtype ll; } DWunion;
+
+
+#define WORD_SIZE __WORDSIZE
+#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
+
+
+DWtype
+__fixunssfDI (SFtype original_a)
+{
+ /* Convert the SFtype to a DFtype, because that is surely not going
+ to lose any bits. Some day someone else can write a faster version
+ that avoids converting to DFtype, and verify it really works right. */
+ DFtype a = original_a;
+ DFtype b;
+ UDWtype v;
+
+ if (a < 0)
+ return 0;
+
+ /* Compute high word of result, as a flonum. */
+ b = (a / HIGH_WORD_COEFF);
+ /* Convert that to fixed (but not to DWtype!),
+ and shift it into the high word. */
+ v = (UWtype) b;
+ v <<= WORD_SIZE;
+ /* Remove high part from the DFtype, leaving the low part as flonum. */
+ a -= (DFtype) v;
+ /* Convert that to fixed (but not to DWtype!) and add it in.
+ Sometimes A comes out negative. This is significant, since
+ A has more bits than a long int does. */
+ if (a < 0)
+ v -= (UWtype) (- a);
+ else
+ v += (UWtype) a;
+ return v;
+}
+
+
+DWtype
+__fixsfdi (SFtype a)
+{
+ if (a < 0)
+ return - __fixunssfDI (-a);
+ return __fixunssfDI (a);
+}
--- /dev/null Thu Jan 1 01:00:00 1970
+++ sysdeps/wordsize-32/shdi3.c Thu May 9 13:53:12 2002
@@ -0,0 +1,143 @@
+/* 64-bit multiplication and division
+ Copyright (C) 1989, 1992-1999, 2000, 2001, 2002
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <endian.h>
+#include <stdlib.h>
+#include <bits/wordsize.h>
+
+#if __WORDSIZE != 32
+#error This is for 32-bit targets only
+#endif
+
+typedef unsigned int UQItype __attribute__ ((mode (QI)));
+typedef int SItype __attribute__ ((mode (SI)));
+typedef unsigned int USItype __attribute__ ((mode (SI)));
+typedef int DItype __attribute__ ((mode (DI)));
+typedef unsigned int UDItype __attribute__ ((mode (DI)));
+#define Wtype SItype
+#define HWtype SItype
+#define DWtype DItype
+#define UWtype USItype
+#define UHWtype USItype
+#define UDWtype UDItype
+#define W_TYPE_SIZE 32
+#define BITS_PER_UNIT 8
+
+#include <stdlib/longlong.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+struct DWstruct { Wtype high, low;};
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+struct DWstruct { Wtype low, high;};
+#else
+#error Unhandled endianity
+#endif
+typedef union { struct DWstruct s; DWtype ll; } DWunion;
+
+
+DWtype
+__lshrdi3 (DWtype u, Wtype b)
+{
+ DWunion w;
+ Wtype bm;
+ DWunion uu;
+
+ if (b == 0)
+ return u;
+
+ uu.ll = u;
+
+ bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+ if (bm <= 0)
+ {
+ w.s.high = 0;
+ w.s.low = (UWtype) uu.s.high >> -bm;
+ }
+ else
+ {
+ UWtype carries = (UWtype) uu.s.high << bm;
+
+ w.s.high = (UWtype) uu.s.high >> b;
+ w.s.low = ((UWtype) uu.s.low >> b) | carries;
+ }
+
+ return w.ll;
+}
+
+
+DWtype
+__ashldi3 (DWtype u, Wtype b)
+{
+ DWunion w;
+ Wtype bm;
+ DWunion uu;
+
+ if (b == 0)
+ return u;
+
+ uu.ll = u;
+
+ bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+ if (bm <= 0)
+ {
+ w.s.low = 0;
+ w.s.high = (UWtype) uu.s.low << -bm;
+ }
+ else
+ {
+ UWtype carries = (UWtype) uu.s.low >> bm;
+
+ w.s.low = (UWtype) uu.s.low << b;
+ w.s.high = ((UWtype) uu.s.high << b) | carries;
+ }
+
+ return w.ll;
+}
+
+
+DWtype
+__ashrdi3 (DWtype u, Wtype b)
+{
+ DWunion w;
+ Wtype bm;
+ DWunion uu;
+
+ if (b == 0)
+ return u;
+
+ uu.ll = u;
+
+ bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+ if (bm <= 0)
+ {
+ /* w.s.high = 1..1 or 0..0 */
+ w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
+ w.s.low = uu.s.high >> -bm;
+ }
+ else
+ {
+ UWtype carries = (UWtype) uu.s.high << bm;
+
+ w.s.high = uu.s.high >> b;
+ w.s.low = ((UWtype) uu.s.low >> b) | carries;
+ }
+
+ return w.ll;
+}
More information about the Libc-alpha
mailing list