[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#694112: gcc-4.6: please apply fixes, m68k patches, MiNT support



Source: gcc-4.6
Version: 4.6.3-13
Severity: wishlist
Tags: patch

Hi,

I’ve put together a collection of GCC patches made while working
on m68k again. They’re mostly independent of each other, but I’d
like to see them all applied eventually. I used this:

gcc-4.6 (4.6.3-13+m68k.3) unreleased; urgency=low

  * Update the libffi-m68k patch from upstream.

  * Backport atomic builtin backend code for Linux/m68k from trunk.
  * Add t-slibgcc-libgcc for m68k-linux (PR40134).

  * Re-enable building runtime packages normally built by gcc-4.7
    on cross toolchains, to keep them self-contained.

  * Add the FreeMiNT patches from Vincent Rivière to support the
    Debian architecture mint-m68k (only DEB_STAGE=stage1 for now).
    Note that adding support for unset DEB_STAGE would be challenging
    as there are currently no shared libraries at all on FreeMiNT.
  * Fix bug in debian/patches/gcc-multiarch-upstream.diff preventing
    us from disabling Multi-Arch when targetting m68k-mint.

 -- Thorsten Glaser <tg@mirbsd.de>  Sat, 24 Nov 2012 00:13:39 +0100

The patches are:

*** fix-autoconf.diff

Unbreak --disable-multiarch (and --enable-multiarch too, probably)
by checking the correct variable. (As announced in IRC.)

*** make-crossbuilds-complete.diff

When doing cross compilers, do build the “common and library packages”
and “gccxbase” to make them complete, so one doesn’t need to build two
cross toolchains just to get libgcc2. Touches common code but should
be unproblematic; in fact, help people.

*** update-libffi-diff.diff

Update the patch for libffi for m68k by another hunk upstream committed
to GCC. Unproblematic.

*** backport-atomics.diff

Backport code from then-trunk to add __sync_* atomic builtins, adjusted
to work within the GCC 4.6 framework. This also fixes PR40134 which
would have reappeared otherwise.

*** mint.diff

Depends on at least fix-autoconf and make-crossbuilds-complete.
Adds support for FreeMiNT (an unixoid Atari kernel which uses that
platform’s native TOS binaries) as a DEB_STAGE=stage1 platform.
We’ll need to https://wiki.debian.org/BuildingCrossCompilers to
that platform in order to be able to build several m68k bootloaders
from source (the Debian source packages usually ship the precompiled
binaries uuencoded, but they have to be generated somehow, and I’d
rather have the process be ⓐ documented and ⓑ use as much unmodified
Debian stuff as possible).

Compiling applications that run on FreeMiNT or even TOS works with
this given “mintlib”, its libc equivalent. Fleshing out FreeMiNT
support would be possible, but not easy inside the gcc-4.6 Debian
source package as mintlib doesn’t do dynamic linking. The author
of these patches wants to get them into GCC though and collaborates
on them with me (is interested what we do to them).

Did I submit the companion patch to binutils already? If not, prod me.

This patch touches debian/rules.d/binary-gcc.mk because even
binutils-multiarch with FreeMiNT enabled cannot handle stripping
libgcc.a with m68k-tos objects inside because detection is not
unambiguous, hence we just skip stripping them for cross-builds
targetting FreeMiNT. (The cross support of debhelper actually
works, it’s just that it isn’t suitable or even intended to
operate on packages that contain a cross-compiler native binary
as well as binaries for the target platform.)

It also changes several conditionals for m68k to operate on the
CPU macro (the dpkg architecture name is mint-m68k, so this works).


The patches need not be applied now (except the first), I can
easily carry a local version in d-p.org/unreleased until after
the unfreeze.

Thanks in advance,
//mirabilos
-- 
Darwinism never[…]applied to wizardkind. There's a more than fair amount of[…]
stupidity in its gene-pool[…]never eradicated[…]magic evens the odds that way.
It's[…]harder to die for us than[…]muggles[…]wonder if, as technology[…]better
[…]same will[…]happen there too. Dursleys' continued existence indicates so.
--- gcc-4.6-4.6.3/debian/rules.patch
+++ gcc-4.6-4.6.3/debian/rules.patch
@@ -96,6 +96,7 @@
 	arm-no-va_list-warn \
 	pr47955 \
 	m68k-fp-cmp-zero \
+	m68k-atomic \
 	gcc-gengtype-fix1 \
 	gcc-gengtype-fix2 \
 
--- gcc-4.6-4.6.3.orig/debian/patches/m68k-atomic.diff
+++ gcc-4.6-4.6.3/debian/patches/m68k-atomic.diff
@@ -0,0 +1,255 @@
+# DP: backport atomic builtin backend code for m68k from trunk
+# DP: and add t-slibgcc-libgcc to m68k configuration by advice
+# DP: of Mikel Pettersson to avoid running into PR40134 again
+
+--- a/src/libgcc/config.host
++++ b/src/libgcc/config.host
+@@ -383,9 +383,10 @@ m68k*-*-openbsd*)
+ 	;;
+ m68k-*-uclinux*)		# Motorola m68k/ColdFire running uClinux with uClibc
+ 	;;
+-m68k-*-linux*)		# Motorola m68k's running GNU/Linux
++m68k-*-linux*)			# Motorola m68k's running GNU/Linux
+ 				# with ELF format using glibc 2
+ 				# aka the GNU/Linux C library 6.
++	tmake_file="$tmake_file m68k/t-linux"
+ 	;;
+ m68k-*-rtems*)
+ 	;;
+--- /dev/null
++++ b/src/libgcc/config/m68k/linux-atomic.c
+@@ -0,0 +1,211 @@
++/* Linux-specific atomic operations for m68k Linux.
++   Copyright (C) 2011 Free Software Foundation, Inc.
++   Based on code contributed by CodeSourcery for ARM EABI Linux.
++
++This file is part of GCC.
++
++GCC is free software; you can redistribute it and/or modify it under
++the terms of the GNU General Public License as published by the Free
++Software Foundation; either version 3, or (at your option) any later
++version.
++
++GCC 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 General Public License
++for more details.
++
++Under Section 7 of GPL version 3, you are granted additional
++permissions described in the GCC Runtime Library Exception, version
++3.1, as published by the Free Software Foundation.
++
++You should have received a copy of the GNU General Public License and
++a copy of the GCC Runtime Library Exception along with this program;
++see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
++<http://www.gnu.org/licenses/>.  */
++
++/* Coldfire dropped the CAS instruction from the base M68K ISA.
++
++   GCC automatically issues a asm memory barrier when it encounters
++   a __sync_synchronize builtin.  Thus, we do not need to define this
++   builtin.
++
++   We implement byte, short and int versions of each atomic operation
++   using the kernel helper defined below.  There is no support for
++   64-bit operations yet.  */
++
++#include <asm/unistd.h>
++#include <stdbool.h>
++
++#ifndef __NR_atomic_cmpxchg_32
++#define __NR_atomic_cmpxchg_32  335
++#endif
++
++/* Kernel helper for compare-and-exchange a 32-bit value.  */
++static inline unsigned
++__kernel_cmpxchg (unsigned *mem, unsigned oldval, unsigned newval)
++{
++  register unsigned *a0 asm("a0") = mem;
++  register unsigned d2 asm("d2") = oldval;
++  register unsigned d1 asm("d1") = newval;
++  register unsigned d0 asm("d0") = __NR_atomic_cmpxchg_32;
++
++  asm volatile ("trap #0"
++		: "=r"(d0), "=r"(d1), "=r"(a0)
++		: "r"(d0), "r"(d1), "r"(d2), "r"(a0)
++		: "memory", "a1");
++
++  return d0;
++}
++
++#define HIDDEN __attribute__ ((visibility ("hidden")))
++
++/* Big endian masks  */
++#define INVERT_MASK_1 24
++#define INVERT_MASK_2 16
++
++#define MASK_1 0xffu
++#define MASK_2 0xffffu
++
++#define NAME_oldval(OP, WIDTH) __sync_fetch_and_##OP##_##WIDTH
++#define NAME_newval(OP, WIDTH) __sync_##OP##_and_fetch_##WIDTH
++
++#define WORD_SYNC_OP(OP, PFX_OP, INF_OP, RETURN)			\
++  unsigned HIDDEN							\
++  NAME##_##RETURN (OP, 4) (unsigned *ptr, unsigned val)			\
++  {									\
++    unsigned oldval, newval, cmpval = *ptr;				\
++									\
++    do {								\
++      oldval = cmpval;							\
++      newval = PFX_OP (oldval INF_OP val);				\
++      cmpval = __kernel_cmpxchg (ptr, oldval, newval);			\
++    } while (__builtin_expect (oldval != cmpval, 0));			\
++									\
++    return RETURN;							\
++  }
++
++#define SUBWORD_SYNC_OP(OP, PFX_OP, INF_OP, TYPE, WIDTH, RETURN)	\
++  TYPE HIDDEN								\
++  NAME##_##RETURN (OP, WIDTH) (TYPE *ptr, TYPE sval)			\
++  {									\
++    unsigned *wordptr = (unsigned *) ((unsigned long) ptr & ~3);	\
++    unsigned int mask, shift, oldval, newval, cmpval, wval;		\
++									\
++    shift = (((unsigned long) ptr & 3) << 3) ^ INVERT_MASK_##WIDTH;	\
++    mask = MASK_##WIDTH << shift;					\
++    wval = (sval & MASK_##WIDTH) << shift;				\
++									\
++    cmpval = *wordptr;							\
++    do {								\
++      oldval = cmpval;							\
++      newval = PFX_OP (oldval INF_OP wval);				\
++      newval = (newval & mask) | (oldval & ~mask);			\
++      cmpval = __kernel_cmpxchg (wordptr, oldval, newval);		\
++    } while (__builtin_expect (oldval != cmpval, 0));			\
++									\
++    return (RETURN >> shift) & MASK_##WIDTH;				\
++  }
++
++WORD_SYNC_OP (add,   , +, oldval)
++WORD_SYNC_OP (sub,   , -, oldval)
++WORD_SYNC_OP (or,    , |, oldval)
++WORD_SYNC_OP (and,   , &, oldval)
++WORD_SYNC_OP (xor,   , ^, oldval)
++WORD_SYNC_OP (nand, ~, &, oldval)
++
++SUBWORD_SYNC_OP (add,   , +, unsigned short, 2, oldval)
++SUBWORD_SYNC_OP (sub,   , -, unsigned short, 2, oldval)
++SUBWORD_SYNC_OP (or,    , |, unsigned short, 2, oldval)
++SUBWORD_SYNC_OP (and,   , &, unsigned short, 2, oldval)
++SUBWORD_SYNC_OP (xor,   , ^, unsigned short, 2, oldval)
++SUBWORD_SYNC_OP (nand, ~, &, unsigned short, 2, oldval)
++
++SUBWORD_SYNC_OP (add,   , +, unsigned char, 1, oldval)
++SUBWORD_SYNC_OP (sub,   , -, unsigned char, 1, oldval)
++SUBWORD_SYNC_OP (or,    , |, unsigned char, 1, oldval)
++SUBWORD_SYNC_OP (and,   , &, unsigned char, 1, oldval)
++SUBWORD_SYNC_OP (xor,   , ^, unsigned char, 1, oldval)
++SUBWORD_SYNC_OP (nand, ~, &, unsigned char, 1, oldval)
++
++WORD_SYNC_OP (add,   , +, newval)
++WORD_SYNC_OP (sub,   , -, newval)
++WORD_SYNC_OP (or,    , |, newval)
++WORD_SYNC_OP (and,   , &, newval)
++WORD_SYNC_OP (xor,   , ^, newval)
++WORD_SYNC_OP (nand, ~, &, newval)
++
++SUBWORD_SYNC_OP (add,   , +, unsigned short, 2, newval)
++SUBWORD_SYNC_OP (sub,   , -, unsigned short, 2, newval)
++SUBWORD_SYNC_OP (or,    , |, unsigned short, 2, newval)
++SUBWORD_SYNC_OP (and,   , &, unsigned short, 2, newval)
++SUBWORD_SYNC_OP (xor,   , ^, unsigned short, 2, newval)
++SUBWORD_SYNC_OP (nand, ~, &, unsigned short, 2, newval)
++
++SUBWORD_SYNC_OP (add,   , +, unsigned char, 1, newval)
++SUBWORD_SYNC_OP (sub,   , -, unsigned char, 1, newval)
++SUBWORD_SYNC_OP (or,    , |, unsigned char, 1, newval)
++SUBWORD_SYNC_OP (and,   , &, unsigned char, 1, newval)
++SUBWORD_SYNC_OP (xor,   , ^, unsigned char, 1, newval)
++SUBWORD_SYNC_OP (nand, ~, &, unsigned char, 1, newval)
++
++unsigned HIDDEN
++__sync_val_compare_and_swap_4 (unsigned *ptr, unsigned oldval, unsigned newval)
++{
++  return __kernel_cmpxchg (ptr, oldval, newval);
++}
++
++bool HIDDEN
++__sync_bool_compare_and_swap_4 (unsigned *ptr, unsigned oldval,
++				unsigned newval)
++{
++  return __kernel_cmpxchg (ptr, oldval, newval) == oldval;
++}
++
++#define SUBWORD_VAL_CAS(TYPE, WIDTH)					\
++  TYPE HIDDEN								\
++  __sync_val_compare_and_swap_##WIDTH (TYPE *ptr, TYPE soldval,		\
++				       TYPE snewval)			\
++  {									\
++    unsigned *wordptr = (unsigned *)((unsigned long) ptr & ~3);		\
++    unsigned int mask, shift, woldval, wnewval;				\
++    unsigned oldval, newval, cmpval;					\
++									\
++    shift = (((unsigned long) ptr & 3) << 3) ^ INVERT_MASK_##WIDTH;	\
++    mask = MASK_##WIDTH << shift;					\
++    woldval = (soldval & MASK_##WIDTH) << shift;			\
++    wnewval = (snewval & MASK_##WIDTH) << shift;			\
++    cmpval = *wordptr;							\
++									\
++    do {								\
++      oldval = cmpval;							\
++      if ((oldval & mask) != woldval)					\
++	break;								\
++      newval = (oldval & ~mask) | wnewval;				\
++      cmpval = __kernel_cmpxchg (wordptr, oldval, newval);		\
++    } while (__builtin_expect (oldval != cmpval, 0));			\
++									\
++    return (oldval >> shift) & MASK_##WIDTH;				\
++  }
++
++SUBWORD_VAL_CAS (unsigned short, 2)
++SUBWORD_VAL_CAS (unsigned char,  1)
++
++#define SUBWORD_BOOL_CAS(TYPE, WIDTH)					\
++  bool HIDDEN								\
++  __sync_bool_compare_and_swap_##WIDTH (TYPE *ptr, TYPE oldval,		\
++					TYPE newval)			\
++  {									\
++    return (__sync_val_compare_and_swap_##WIDTH (ptr, oldval, newval)	\
++	    == oldval);							\
++  }
++
++SUBWORD_BOOL_CAS (unsigned short, 2)
++SUBWORD_BOOL_CAS (unsigned char,  1)
++
++#undef NAME_oldval
++#define NAME_oldval(OP, WIDTH) __sync_lock_##OP##_##WIDTH
++#define COMMA ,
++
++WORD_SYNC_OP (test_and_set, , COMMA, oldval)
++SUBWORD_SYNC_OP (test_and_set, , COMMA, unsigned short, 1, oldval)
++SUBWORD_SYNC_OP (test_and_set, , COMMA, unsigned short, 2, oldval)
+--- /dev/null
++++ b/src/libgcc/config/m68k/t-linux
+@@ -0,0 +1 @@
++LIB2ADD_ST = $(srcdir)/config/m68k/linux-atomic.c
+--- a/src/gcc/config.gcc
++++ b/src/gcc/config.gcc
+@@ -1792,7 +1792,7 @@ m68k-*-uclinux*)		# Motorola m68k/ColdFi
+  	tm_defines="${tm_defines} MOTOROLA=1"
+ 	tmake_file="m68k/t-floatlib m68k/t-uclinux m68k/t-mlibs"
+ 	;;
+-m68k-*-linux*)		# Motorola m68k's running GNU/Linux
++m68k-*-linux*)			# Motorola m68k's running GNU/Linux
+ 				# with ELF format using glibc 2
+ 				# aka the GNU/Linux C library 6.
+ 	default_m68k_cpu=68020
+@@ -1807,6 +1807,7 @@ m68k-*-linux*)		# Motorola m68k's runnin
+ 	if test x$sjlj != x1; then
+ 	    tmake_file="$tmake_file m68k/t-slibgcc-elf-ver"
+ 	fi
++	tmake_file="$tmake_file t-slibgcc-libgcc"
+ 	;;
+ m68k-*-rtems*)
+ 	default_m68k_cpu=68020
--- gcc-4.6-4.6.3/debian/patches/gcc-multiarch-upstream.diff
+++ gcc-4.6-4.6.3/debian/patches/gcc-multiarch-upstream.diff
@@ -396,9 +396,9 @@
 +# Determine whether or not multiarch is enabled.
 +# Check whether --enable-multiarch was given.
 +if test "${enable_multiarch+set}" = set; then :
-+  enableval=$enable_multiarch; case "${withval}" in
-+yes|no|auto) enable_multiarch=$withval;;
-+*) as_fn_error "bad value ${withval} given for --enable-multiarch option" "$LINENO" 5 ;;
++  enableval=$enable_multiarch; case "${enableval}" in
++yes|no|auto) enable_multiarch=$enableval;;
++*) as_fn_error "bad value ${enableval} given for --enable-multiarch option" "$LINENO" 5 ;;
 +esac
 +else
 +  enable_multiarch=auto
@@ -547,9 +547,9 @@
 +AC_ARG_ENABLE(multiarch,
 +[AS_HELP_STRING([--enable-multiarch],
 +		[enable support for multiarch paths])],
-+[case "${withval}" in
-+yes|no|auto) enable_multiarch=$withval;;
-+*) AC_MSG_ERROR(bad value ${withval} given for --enable-multiarch option) ;;
++[case "${enableval}" in
++yes|no|auto) enable_multiarch=$enableval;;
++*) AC_MSG_ERROR(bad value ${enableval} given for --enable-multiarch option) ;;
 +esac], [enable_multiarch=auto])
 +if test x${enable_multiarch} = xauto; then
 +  if test x$host != x$target && test "x$with_sysroot" = x; then
--- gcc-4.6-4.6.3/debian/rules.defs
+++ gcc-4.6-4.6.3/debian/rules.defs
@@ -310,6 +310,12 @@
 # XXX: should with_common_libs be "yes" only if this is the default compiler
 # version on the targeted arch?
 
+ifeq ($(DEB_CROSS),yes)
+# re-enable common and library packages for cross builds
+with_common_pkgs := yes
+with_common_libs := yes
+endif
+
 # is this a multiarch-enabled build?
 ifeq (,$(filter $(distrelease),lenny etch squeeze dapper hardy jaunty karmic lucid maverick))
   with_multiarch_lib := yes
@@ -344,6 +350,11 @@
   else
     with_gccxbase := yes
   endif
+else
+  ifeq ($(DEB_TARGET_ARCH_OS),mint)
+    # hack to make cross-compiler self-hosted
+    with_gccxbase := yes
+  endif
 endif
 
 # build dev packages.
--- gcc-4.6-4.6.3/debian/rules.defs
+++ gcc-4.6-4.6.3/debian/rules.defs
@@ -662,6 +673,9 @@
 ifeq ($(fortran_no_cross)-$(DEB_CROSS),yes-yes)
   with_fortran := diasbled for cross compiler package
 endif
+ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+  with_fortran := not for FreeMiNT target from Debian packaging
+endif
 with_fortran := $(call envfilt, fortran, , , $(with_fortran))
 
 # Build all packages needed for Fortran development
@@ -697,6 +711,9 @@
 ifeq ($(objc_no_cross)-$(DEB_CROSS),yes-yes)
   with_objc := diasbled for cross compiler package
 endif
+ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+  with_objc := not for FreeMiNT target from Debian packaging
+endif
 with_objc := $(call envfilt, objc, obj-c++, , $(with_objc))
 
 ifeq ($(with_objc),yes)
@@ -736,6 +753,9 @@
 ifeq ($(objcxx_no_cross)-$(DEB_CROSS),yes-yes)
   with_objcxx := diasbled for cross compiler package
 endif
+ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+  with_objcxx := not for FreeMiNT target from Debian packaging
+endif
 with_objcxx := $(call envfilt, obj-c++, , c++ objc, $(with_objcxx))
 
 ifeq ($(with_objcxx),yes)
@@ -790,6 +810,9 @@
 ifeq ($(trunk_build),yes)
   with_nls := no
 endif
+ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+  with_nls := disabled for FreeMiNT
+endif
 with_nls := $(call envfilt, nls, , , $(with_nls))
 
 # powerpc nof libraries -----
@@ -1249,6 +1272,9 @@
 ifneq (,$(findstring $(DEB_TARGET_GNU_SYSTEM),$(locale_no_systems)))
   force_gnu_locales := disabled for system $(DEB_TARGET_GNU_SYSTEM)
 endif
+ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+  force_gnu_locales := disabled for FreeMiNT
+endif
 
 gcc_tarpath		:= $(firstword $(wildcard gcc-*.tar.* /usr/src/gcc-$(BASE_VERSION)/gcc-*.tar.*))
 gcc_tarball		:= $(notdir $(gcc_tarpath))
--- gcc-4.6-4.6.3/debian/rules.patch
+++ gcc-4.6-4.6.3/debian/rules.patch
@@ -199,10 +200,11 @@
   debian_patches += libjava-armel-unwind
 endif
 
-ifeq ($(DEB_TARGET_ARCH),m68k)
+ifeq ($(DEB_TARGET_ARCH_CPU),m68k)
   debian_patches += pr47612
   debian_patches += m68k-revert-pr45144
   debian_patches += m68k-ada
+  debian_patches += m68k-mint
 endif
 
 ifeq ($(DEB_TARGET_ARCH),powerpcspe)
--- gcc-4.6-4.6.3/debian/rules.conf
+++ gcc-4.6-4.6.3/debian/rules.conf
@@ -173,6 +173,13 @@
   endif
 endif
 LIBC_DEV_DEP = $(LIBC_DEP)-dev
+ifeq ($(DEB_TARGET_ARCH_OS),mint)
+  # no shared C library
+  LIBC_DEP =
+  # mintlib is the libc6-dev equivalent
+  LIBC_DEV_DEP = mintlib
+  libc_dev_ver = 0~
+endif
 # for cross
 ifeq ($(DEB_CROSS),yes)
   LIBC_DEP ?= $(LIBC_DEP)$(LS)
@@ -416,7 +423,14 @@
 
 else
 # build cross compiler
+ifeq ($(DEB_TARGET_ARCH_OS),mint)
+  #XXX for now; we can only do DEB_STAGE=stage1 because otherwise, gcc
+  # wants to use shared libraries, which FreeMiNT does not have; the
+  # correct value to use here is 'mintlib' possibly with some cross-foo
+  CROSS_BUILD_DEP :=
+else
   CROSS_BUILD_DEP := libc6-dev$(cross_lib_arch),
+endif
 ifeq ($(REVERSE_CROSS),yes)
   CROSS_BUILD_DEP += zlib1g-dev$(cross_lib_arch), libmpfr-dev$(cross_lib_arch),
 endif
@@ -589,6 +603,12 @@
   ifeq ($(DEB_STAGE),stage2)
     addons += libgcc gccxbase
   endif
+  ifeq ($(DEB_STAGE),stage1)
+    ifeq ($(DEB_TARGET_ARCH_OS),mint)
+      # hack to make cross-compiler self-hosted
+      addons += gccxbase
+    endif
+  endif
 else
 languages = c c++ fortran objc objpp
 ifeq ($(DEB_CROSS),yes)
--- gcc-4.6-4.6.3/debian/rules2
+++ gcc-4.6-4.6.3/debian/rules2
@@ -382,7 +382,7 @@
   endif
 endif
 
-ifeq ($(DEB_TARGET_GNU_CPU),$(findstring $(DEB_TARGET_GNU_CPU),m68k))
+ifeq ($(DEB_TARGET_ARCH_CPU),m68k)
   CONFARGS += --disable-werror
 endif
 # FIXME: correct fix-warnings.dpatch
@@ -410,7 +410,7 @@
   CONFARGS += --with-multilib-list=m4,m4-nofpu --with-cpu=sh4
 endif
 
-ifneq (,$(findstring m68k-linux,$(DEB_TARGET_GNU_TYPE)))
+ifeq ($(DEB_TARGET_ARCH_CPU),m68k)
   CONFARGS += --disable-multilib
 endif
 
@@ -516,6 +516,17 @@
   endif
 endif
 
+ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+  # only DEB_STAGE=stage1 since mintlib is not packaged in Debian
+  # and does not support shared libraries either, which the gcc
+  # cross-package framework assumes
+  CONFARGS += --disable-multilib
+  CONFARGS += --disable-shared
+  CONFARGS += --disable-linker-build-id
+  CONFARGS += --disable-threads
+  CONFARGS += --disable-gnu-unique-object
+endif
+
 ifeq ($(with_bootstrap),off)
   bootstrap_target =
 else ifeq ($(with_bootstrap),)
--- gcc-4.6-4.6.3/debian/rules.d/binary-gcc.mk
+++ gcc-4.6-4.6.3/debian/rules.d/binary-gcc.mk
@@ -16,6 +16,16 @@
   endif
 endif
 
+ifeq ($(DEB_CROSS),yes)
+  ifeq ($(DEB_TARGET_ARCH),mint-m68k)
+    # even binutils-multiarch's strip fails these
+    # and dh_strip is too unflexible to allow mixing
+    # strip calls for building cross-compilers, as
+    # opposed to cross-building packages
+    p_gcc_dhstrip_opts := -X libgcc.a -X libgcov.a
+  endif
+endif
+
 # gcc must be moved after g77 and g++
 # not all files $(PF)/include/*.h are part of gcc,
 # but it becomes difficult to name all these files ...
@@ -76,7 +86,7 @@
     files_gcc += $(gcc_lib_dir)/include/ia64intrin.h
 endif
 
-ifeq ($(DEB_TARGET_ARCH),m68k)
+ifeq ($(DEB_TARGET_ARCH_CPU),m68k)
     files_gcc += $(gcc_lib_dir)/include/math-68881.h
 endif
 
@@ -212,7 +222,7 @@
 	  true; \
 	fi
 	debian/dh_rmemptydirs -p$(p_gcc)
-	dh_strip -p$(p_gcc)
+	dh_strip -p$(p_gcc) $(p_gcc_dhstrip_opts)
 	dh_compress -p$(p_gcc) -X README.Bugs
 	dh_fixperms -p$(p_gcc)
 	dh_shlibdeps -p$(p_gcc)
--- gcc-4.6-4.6.3.orig/debian/patches/m68k-mint.diff
+++ gcc-4.6-4.6.3/debian/patches/m68k-mint.diff
@@ -0,0 +1,1180 @@
+Description: Add support for the m68k-atari-mint target
+ http://vincent.riviere.free.fr/soft/m68k-atari-mint/ contains a
+ collection of patches for a FreeMiNT cross and native toolchain.
+ This patch applies gcc-4.6.2-mint-20111028.patch.bz2 except the
+ not FreeMiNT-specific parts, which are already applied. It has
+ been reviewed, whitespace-sanitised, and some changes previously
+ globally applied are now only enabled for a FreeMiNT target.
+Origin: http://vincent.riviere.free.fr/soft/m68k-atari-mint/archives/gcc-4.6.2-mint-20111028.patch.bz2
+Author: Vincent Rivière <vincent.riviere@freesbee.fr>
+Reviewed-by: Thorsten Glaser <tg@debian.org>
+Last-Update: 2012-04-22
+
+--- a/src/config-ml.in
++++ b/src/config-ml.in
+@@ -351,6 +351,23 @@ m68*-*-*)
+ 	    esac
+ 	  done
+ 	fi
++	case "${host}" in
++	  *-*-mint*)
++	    case "${srcdir}" in
++	      */libgcc ) : ;;
++	      *)
++		old_multidirs="${multidirs}"
++		multidirs=""
++		for x in ${old_multidirs}; do
++		  case "$x" in
++		    *mshort ) : ;;
++		    *) multidirs="${multidirs} ${x}" ;;
++		  esac
++		done
++		;;
++	    esac
++	    ;;
++	esac
+ 	;;
+ mips*-*-*)
+ 	if [ x$enable_single_float = xno ]
+--- a/src/configure.ac
++++ b/src/configure.ac
+@@ -523,6 +523,9 @@ if test x$enable_libmudflap = x ; then
+     *-*-freebsd*)
+         # Enable libmudflap by default in FreeBSD.
+ 	;;
++    *-*-mint*)
++	# Enable libmudflap by default in MiNT.
++	;;
+     *)
+         # Disable it by default everywhere else.
+ 	noconfigdirs="$noconfigdirs target-libmudflap"
+@@ -895,6 +898,9 @@ case "${target}" in
+   m68k-*-coff*)
+     noconfigdirs="$noconfigdirs ${libgcj}"
+     ;;
++  m68k-*-mint*)
++    noconfigdirs="$noconfigdirs target-libiberty ${libgcj}"
++    ;;
+   m68*-*-* | fido-*-*)
+     libgloss_dir=m68k
+     ;;
+--- a/src/gcc/config/m68k/lb1sf68.asm
++++ b/src/gcc/config/m68k/lb1sf68.asm
+@@ -666,7 +666,9 @@ ROUND_TO_MINUS    = 3 | round result tow
+ 	.globl SYM (__negdf2)
+ 	.globl SYM (__cmpdf2)
+ 	.globl SYM (__cmpdf2_internal)
++#ifdef __ELF__
+ 	.hidden SYM (__cmpdf2_internal)
++#endif
+ 
+ 	.text
+ 	.even
+@@ -2581,7 +2583,9 @@ ROUND_TO_MINUS    = 3 | round result tow
+ 	.globl SYM (__negsf2)
+ 	.globl SYM (__cmpsf2)
+ 	.globl SYM (__cmpsf2_internal)
++#ifdef __ELF__
+ 	.hidden SYM (__cmpsf2_internal)
++#endif
+ 
+ | These are common routines to return and signal exceptions.	
+ 
+--- a/src/gcc/config/m68k/math-68881.h
++++ b/src/gcc/config/m68k/math-68881.h
+@@ -42,6 +42,15 @@
+ #ifndef __math_68881
+ #define __math_68881
+ 
++#undef __math_68881_inline
++#if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
++#define __math_68881_inline	extern __inline__ __attribute__((__gnu_inline__))
++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
++#define __math_68881_inline	static inline
++#else
++#define __math_68881_inline	extern __inline__
++#endif
++
+ #include <errno.h>
+ 
+ #undef HUGE_VAL
+@@ -64,7 +73,7 @@
+ })
+ #endif
+ 
+-__inline extern double
++__math_68881_inline double
+ sin (double x)
+ {
+   double value;
+@@ -75,7 +84,7 @@ sin (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ cos (double x)
+ {
+   double value;
+@@ -86,7 +95,7 @@ cos (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ tan (double x)
+ {
+   double value;
+@@ -97,7 +106,7 @@ tan (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ asin (double x)
+ {
+   double value;
+@@ -108,7 +117,7 @@ asin (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ acos (double x)
+ {
+   double value;
+@@ -119,7 +128,7 @@ acos (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ atan (double x)
+ {
+   double value;
+@@ -130,7 +139,7 @@ atan (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ atan2 (double y, double x)
+ {
+   double pi, pi_over_2;
+@@ -187,7 +196,7 @@ atan2 (double y, double x)
+     }
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ sinh (double x)
+ {
+   double value;
+@@ -198,7 +207,7 @@ sinh (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ cosh (double x)
+ {
+   double value;
+@@ -209,7 +218,7 @@ cosh (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ tanh (double x)
+ {
+   double value;
+@@ -220,7 +229,7 @@ tanh (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ atanh (double x)
+ {
+   double value;
+@@ -231,7 +240,7 @@ atanh (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ exp (double x)
+ {
+   double value;
+@@ -242,7 +251,7 @@ exp (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ expm1 (double x)
+ {
+   double value;
+@@ -253,7 +262,7 @@ expm1 (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ log (double x)
+ {
+   double value;
+@@ -264,7 +273,7 @@ log (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ log1p (double x)
+ {
+   double value;
+@@ -275,7 +284,7 @@ log1p (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ log10 (double x)
+ {
+   double value;
+@@ -286,7 +295,7 @@ log10 (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ sqrt (double x)
+ {
+   double value;
+@@ -297,13 +306,13 @@ sqrt (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ hypot (double x, double y)
+ {
+   return sqrt (x*x + y*y);
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ pow (double x, double y)
+ {
+   if (x > 0)
+@@ -352,7 +361,7 @@ pow (double x, double y)
+     }
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ fabs (double x)
+ {
+   double value;
+@@ -363,7 +372,7 @@ fabs (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ ceil (double x)
+ {
+   int rounding_mode, round_up;
+@@ -385,7 +394,7 @@ ceil (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ floor (double x)
+ {
+   int rounding_mode, round_down;
+@@ -408,7 +417,7 @@ floor (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ rint (double x)
+ {
+   int rounding_mode, round_nearest;
+@@ -430,7 +439,7 @@ rint (double x)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ fmod (double x, double y)
+ {
+   double value;
+@@ -442,7 +451,7 @@ fmod (double x, double y)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ drem (double x, double y)
+ {
+   double value;
+@@ -454,7 +463,7 @@ drem (double x, double y)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ scalb (double x, int n)
+ {
+   double value;
+@@ -466,7 +475,7 @@ scalb (double x, int n)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ logb (double x)
+ {
+   double exponent;
+@@ -477,7 +486,7 @@ logb (double x)
+   return exponent;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ ldexp (double x, int n)
+ {
+   double value;
+@@ -489,7 +498,7 @@ ldexp (double x, int n)
+   return value;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ frexp (double x, int *exp)
+ {
+   double float_exponent;
+@@ -514,7 +523,7 @@ frexp (double x, int *exp)
+   return mantissa;
+ }
+ 
+-__inline extern double
++__math_68881_inline double
+ modf (double x, double *ip)
+ {
+   double temp;
+--- /dev/null
++++ b/src/gcc/config/m68k/mint.h
+@@ -0,0 +1,179 @@
++/* Definitions of target machine for GNU compiler.
++   Atari ST TOS/MiNT.
++   Copyright (C) 1994, 1995, 2007, 2008, 2009, 2010, 2011, 2012
++   Free Software Foundation, Inc.
++
++This file is part of GCC.
++
++GCC is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 3, or (at your option)
++any later version.
++
++GCC 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 General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with GCC; see the file COPYING3.  If not see
++<http://www.gnu.org/licenses/>.  */
++
++/* Here are four prefixes that are used by asm_fprintf to
++   facilitate customization for alternate assembler syntaxes.
++   Machines with no likelihood of an alternate syntax need not
++   define these and need not use asm_fprintf.  */
++
++/* The prefix for register names.  Note that REGISTER_NAMES
++   is supposed to include this prefix. Also note that this is NOT an
++   fprintf format string, it is a literal string */
++
++#undef REGISTER_PREFIX
++#define REGISTER_PREFIX "%"
++
++/* The prefix for local (compiler generated) labels.
++   These labels will not appear in the symbol table.  */
++
++#undef LOCAL_LABEL_PREFIX
++#define LOCAL_LABEL_PREFIX "."
++
++#undef ASM_COMMENT_START
++#define ASM_COMMENT_START "|"
++
++#undef WCHAR_TYPE
++#define WCHAR_TYPE "short unsigned int"
++
++#undef WCHAR_TYPE_SIZE
++#define WCHAR_TYPE_SIZE SHORT_TYPE_SIZE
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS()		\
++  do						\
++    {						\
++      builtin_define ("__MINT__");		\
++      builtin_define_std ("atarist");		\
++      builtin_assert ("machine=atari");		\
++      builtin_assert ("system=mint");		\
++      if (TARGET_68881)				\
++	/* non-standard */			\
++	builtin_define ("__M68881__");		\
++    }						\
++  while (0)
++
++/* The following defines are nonstandard
++   and are kept only for compatibility
++   with older versions of GCC for MiNT.  */
++
++#undef CPP_SPEC
++#define CPP_SPEC			\
++  "%{m68000:-D__M68000__} "		\
++  "%{mc68020:-D__M68020__} "		\
++  "%{m68020:-D__M68020__} "		\
++  "%{m68030:-D__M68020__} "		\
++  "%{m68040:-D__M68020__} "		\
++  "%{m68060:-D__M68020__} "		\
++  "%{m68020-40:-D__M68020__} "		\
++  "%{m68020-60:-D__M68020__} "		\
++  "%{!m680*:%{!mc680*:-D__M68000__}} "	\
++  "%{mshort:-D__MSHORT__}"
++
++#define STARTFILE_SPEC	"%{pg|p|profile:gcrt0.o%s;:crt0.o%s}"
++#define LIB_SPEC	"-lc"
++
++/* Every structure or union's size must be a multiple of 2 bytes.  */
++#define STRUCTURE_SIZE_BOUNDARY 16
++
++/* The -g option generates stabs debug information.  */
++#define DBX_DEBUGGING_INFO 1
++
++/* This is the assembler directive to equate two values.  */
++#undef SET_ASM_OP
++#define SET_ASM_OP		"\t.set\t"
++
++/* This is how we tell the assembler that a symbol is weak.  */
++#undef ASM_WEAKEN_LABEL
++#define ASM_WEAKEN_LABEL(FILE,NAME) \
++  do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
++       fputc ('\n', FILE); } while (0)
++
++/* Don't default to pcc-struct-return, because gcc is the only compiler, and
++   we want to retain compatibility with older gcc versions.  */
++#define DEFAULT_PCC_STRUCT_RETURN 0
++
++/* The system headers are C++-aware.  */
++#define NO_IMPLICIT_EXTERN_C
++
++/* By default, the vtable entries are void pointers, the so the alignment
++   is the same as pointer alignment.  The value of this macro specifies
++   the alignment of the vtable entry in bits.  It should be defined only
++   when special alignment is necessary.
++
++   MiNT: The default value of 32 is too much and unsupported by a.out-mintprg.
++*/
++#define TARGET_VTABLE_ENTRY_ALIGN 16
++
++/* If we have a definition of INCOMING_RETURN_ADDR_RTX, assume that
++   the rest of the DWARF 2 frame unwind support is also provided.
++
++   MiNT: DWARF 2 frame unwind is not supported by a.out-mint.
++*/
++#define DWARF2_UNWIND_INFO 0
++
++/* config/m68k.md has an explicit reference to the program counter,
++   prefix this by the register prefix.  */
++
++#define ASM_RETURN_CASE_JUMP				\
++  do {							\
++    if (TARGET_COLDFIRE)				\
++      {							\
++	if (ADDRESS_REG_P (operands[0]))		\
++	  return "jmp %%pc@(2,%0:l)";			\
++	else						\
++	  return "ext%.l %0\n\tjmp %%pc@(2,%0:l)";	\
++      }							\
++    else						\
++      return "jmp %%pc@(2,%0:w)";			\
++  } while (0)
++
++/* The ADDR_DIFF_VEC must exactly follow the previous instruction.  */
++
++#undef ADDR_VEC_ALIGN
++#define ADDR_VEC_ALIGN(ADDR_VEC) 0
++
++/* If defined, a C expression whose value is a string containing the
++   assembler operation to identify the following data as uninitialized global
++   data.  */
++
++#define BSS_SECTION_ASM_OP "\t.bss"
++
++/* A C statement (sans semicolon) to output to the stdio stream
++   FILE the assembler definition of uninitialized global DECL named
++   NAME whose size is SIZE bytes and alignment is ALIGN bytes.
++   Try to use asm_output_aligned_bss to implement this macro.  */
++
++#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
++  asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
++
++/* Disable -fpic and -fPIC since bsr.l _label@PLTPC
++   is unsupported by the assembler.  */
++
++#undef  SUBTARGET_OVERRIDE_OPTIONS
++#define SUBTARGET_OVERRIDE_OPTIONS					\
++do {									\
++  if (flag_pic && !TARGET_PCREL)					\
++      error ("-f%s is not supported on this target",			\
++	     (flag_pic > 1) ? "PIC" : "pic");				\
++} while (0)
++
++
++/* Workaround for GCC bug #35067 about multiple thunks.  */
++
++#undef MAKE_DECL_ONE_ONLY
++#define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
++
++/* Avoid requiring -static with -fmudflap like in config/bfin/uclinux.h */
++#define MFWRAP_SPEC " %{fmudflap|fmudflapth: \
++ --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\
++ --wrap=mmap --wrap=munmap --wrap=alloca\
++ %{fmudflapth: --wrap=pthread_create\
++}} %{fmudflap|fmudflapth: --wrap=main}"
+--- /dev/null
++++ b/src/gcc/config/m68k/t-mint
+@@ -0,0 +1,41 @@
++#
++# Use multiple libraries
++#
++
++MULTILIB_OPTIONS = m68020-60/mcpu=5475 mshort
++
++MULTILIB_DIRNAMES = m68020-60 m5475 mshort
++
++MULTILIB_MATCHES = \
++	m68020-60=m68881 \
++	m68020-60=m68020 \
++	m68020-60=m68020-40 \
++	m68020-60=mc68020 \
++	m68020-60=m68030 \
++	m68020-60=m68040 \
++	m68020-60=m68060 \
++	m68020-60=mcpu?68020 \
++	m68020-60=mcpu?68030 \
++	m68020-60=mcpu?68040 \
++	m68020-60=mcpu?68060 \
++	m68020-60=march?68020 \
++	m68020-60=march?68030 \
++	m68020-60=march?68040 \
++	m68020-60=march?68060 \
++	mcpu?5475=mcfv4e \
++	mcpu?5475=mcpu?5470 \
++	mcpu?5475=mcpu?5471 \
++	mcpu?5475=mcpu?5472 \
++	mcpu?5475=mcpu?5473 \
++	mcpu?5475=mcpu?5474 \
++	mcpu?5475=mcpu?547x \
++	mcpu?5475=mcpu?5480 \
++	mcpu?5475=mcpu?5481 \
++	mcpu?5475=mcpu?5482 \
++	mcpu?5475=mcpu?5483 \
++	mcpu?5475=mcpu?5484 \
++	mcpu?5475=mcpu?5485 \
++	mcpu?5475=mcpu?548x
++
++LIBGCC = stmp-multilib
++INSTALL_LIBGCC = install-multilib
+--- a/src/gcc/config.gcc
++++ b/src/gcc/config.gcc
+@@ -1809,6 +1809,15 @@ m68k-*-linux*)			# Motorola m68k's runni
+ 	fi
+ 	tmake_file="$tmake_file t-slibgcc-libgcc"
+ 	;;
++m68k-*-mint*)
++	default_m68k_cpu=68000
++	default_cf_cpu=5475
++	tm_file="${tm_file} m68k/mint.h"
++	tm_defines="${tm_defines} MOTOROLA=1"
++	tmake_file="m68k/t-floatlib m68k/t-mint"
++	gas=yes
++	gnu_ld=yes
++	;;
+ m68k-*-rtems*)
+ 	default_m68k_cpu=68020
+ 	default_cf_cpu=5206
+--- a/src/libdecnumber/decNumberLocal.h
++++ b/src/libdecnumber/decNumberLocal.h
+@@ -188,7 +188,8 @@ see the files COPYING3 and COPYING.RUNTI
+   #if (DECNUMMAXE != DEC_MAX_EMAX)
+     #error Maximum exponent mismatch
+   #endif
+-  #if (DECNUMMINE != DEC_MIN_EMIN)
++  /* gcc 2.95.3 has bug in "!=" operator for negative constants */
++  #if !(DECNUMMINE == DEC_MIN_EMIN)
+     #error Minimum exponent mismatch
+   #endif
+ 
+--- a/src/libgcc/config.host
++++ b/src/libgcc/config.host
+@@ -388,6 +388,8 @@ m68k-*-linux*)			# Motorola m68k's runni
+ 				# aka the GNU/Linux C library 6.
+ 	tmake_file="$tmake_file m68k/t-linux"
+ 	;;
++m68k-*-mint*)
++	;;
+ m68k-*-rtems*)
+ 	;;
+ mcore-*-elf)
+--- a/src/libiberty/configure.ac
++++ b/src/libiberty/configure.ac
+@@ -201,6 +201,7 @@ esac
+ if [[ "${shared}" = "yes" ]]; then
+   case "${host}" in
+     *-*-cygwin*)	;;
++    *-*-mint*)		;;
+     alpha*-*-linux*)	PICFLAG=-fPIC ;;
+     arm*-*-*)		PICFLAG=-fPIC ;;
+     hppa*-*-*)		PICFLAG=-fPIC ;;
+--- a/src/libiberty/hex.c
++++ b/src/libiberty/hex.c
+@@ -24,7 +24,8 @@ Boston, MA 02110-1301, USA.  */
+ #include "libiberty.h"
+ #include "safe-ctype.h" /* for HOST_CHARSET_ASCII */
+ 
+-#if EOF != -1
++/* gcc 2.95.3 has bug in "!=" operator for negative constants */
++#if !(EOF == -1)
+  #error "hex.c requires EOF == -1"
+ #endif
+ 
+--- a/src/libiberty/safe-ctype.c
++++ b/src/libiberty/safe-ctype.c
+@@ -119,7 +119,8 @@ sets of characters:
+ #include <safe-ctype.h>
+ #include <stdio.h>  /* for EOF */
+ 
+-#if EOF != -1
++/* gcc 2.95.3 has bug in "!=" operator for negative constants */
++#if !(EOF == -1)
+  #error "<safe-ctype.h> requires EOF == -1"
+ #endif
+ 
+--- a/src/libmudflap/mf-hooks2.c
++++ b/src/libmudflap/mf-hooks2.c
+@@ -1667,6 +1667,7 @@ WRAPPER2(int, system, const char *string
+   return system (string);
+ }
+ 
++#ifdef HAVE_DLFCN_H
+ 
+ WRAPPER2(void *, dlopen, const char *path, int flags)
+ {
+@@ -1737,6 +1738,7 @@ WRAPPER2(void *, dlsym, void *handle, ch
+   return p;
+ }
+ 
++#endif /* HAVE_DLFCN_H */
+ 
+ #if defined (HAVE_SYS_IPC_H) && defined (HAVE_SYS_SEM_H) && defined (HAVE_SYS_SHM_H)
+ 
+--- a/src/libmudflap/mf-runtime.h
++++ b/src/libmudflap/mf-runtime.h
+@@ -97,6 +97,7 @@ extern int __mf_set_options (const char
+    instrumented modules are meant to be affected.  */
+ 
+ #ifdef _MUDFLAP
++#ifndef __USER_LABEL_PREFIX__
+ #pragma redefine_extname memcpy __mfwrap_memcpy
+ #pragma redefine_extname memmove __mfwrap_memmove
+ #pragma redefine_extname memset __mfwrap_memset
+@@ -230,6 +231,141 @@ extern int __mf_set_options (const char
+ #pragma redefine_extname getprotoent __mfwrap_getprotoent
+ #pragma redefine_extname getprotobyname __mfwrap_getprotobyname
+ #pragma redefine_extname getprotobynumber __mfwrap_getprotobynumber
++#else
++#pragma redefine_extname memcpy ___mfwrap_memcpy
++#pragma redefine_extname memmove ___mfwrap_memmove
++#pragma redefine_extname memset ___mfwrap_memset
++#pragma redefine_extname memcmp ___mfwrap_memcmp
++#pragma redefine_extname memchr ___mfwrap_memchr
++#pragma redefine_extname memrchr ___mfwrap_memrchr
++#pragma redefine_extname strcpy ___mfwrap_strcpy
++#pragma redefine_extname strncpy ___mfwrap_strncpy
++#pragma redefine_extname strcat ___mfwrap_strcat
++#pragma redefine_extname strncat ___mfwrap_strncat
++#pragma redefine_extname strcmp ___mfwrap_strcmp
++#pragma redefine_extname strcasecmp ___mfwrap_strcasecmp
++#pragma redefine_extname strncmp ___mfwrap_strncmp
++#pragma redefine_extname strncasecmp ___mfwrap_strncasecmp
++#pragma redefine_extname strdup ___mfwrap_strdup
++#pragma redefine_extname strndup ___mfwrap_strndup
++#pragma redefine_extname strchr ___mfwrap_strchr
++#pragma redefine_extname strrchr ___mfwrap_strrchr
++#pragma redefine_extname strstr ___mfwrap_strstr
++#pragma redefine_extname memmem ___mfwrap_memmem
++#pragma redefine_extname strlen ___mfwrap_strlen
++#pragma redefine_extname strnlen ___mfwrap_strnlen
++#pragma redefine_extname bzero ___mfwrap_bzero
++#pragma redefine_extname bcopy ___mfwrap_bcopy
++#pragma redefine_extname bcmp ___mfwrap_bcmp
++#pragma redefine_extname index ___mfwrap_index
++#pragma redefine_extname rindex ___mfwrap_rindex
++#pragma redefine_extname asctime ___mfwrap_asctime
++#pragma redefine_extname ctime ___mfwrap_ctime
++#pragma redefine_extname gmtime ___mfwrap_gmtime
++#pragma redefine_extname localtime ___mfwrap_localtime
++#pragma redefine_extname time ___mfwrap_time
++#pragma redefine_extname strerror ___mfwrap_strerror
++#pragma redefine_extname fopen ___mfwrap_fopen
++#pragma redefine_extname fdopen ___mfwrap_fdopen
++#pragma redefine_extname freopen ___mfwrap_freopen
++#pragma redefine_extname fclose ___mfwrap_fclose
++#pragma redefine_extname fread ___mfwrap_fread
++#pragma redefine_extname fwrite ___mfwrap_fwrite
++#pragma redefine_extname fgetc ___mfwrap_fgetc
++#pragma redefine_extname fgets ___mfwrap_fgets
++#pragma redefine_extname getc ___mfwrap_getc
++#pragma redefine_extname gets ___mfwrap_gets
++#pragma redefine_extname ungetc ___mfwrap_ungetc
++#pragma redefine_extname fputc ___mfwrap_fputc
++#pragma redefine_extname fputs ___mfwrap_fputs
++#pragma redefine_extname putc ___mfwrap_putc
++#pragma redefine_extname puts ___mfwrap_puts
++#pragma redefine_extname clearerr ___mfwrap_clearerr
++#pragma redefine_extname feof ___mfwrap_feof
++#pragma redefine_extname ferror ___mfwrap_ferror
++#pragma redefine_extname fileno ___mfwrap_fileno
++#pragma redefine_extname printf ___mfwrap_printf
++#pragma redefine_extname fprintf ___mfwrap_fprintf
++#pragma redefine_extname sprintf ___mfwrap_sprintf
++#pragma redefine_extname snprintf ___mfwrap_snprintf
++#pragma redefine_extname vprintf ___mfwrap_vprintf
++#pragma redefine_extname vfprintf ___mfwrap_vfprintf
++#pragma redefine_extname vsprintf ___mfwrap_vsprintf
++#pragma redefine_extname vsnprintf ___mfwrap_vsnprintf
++#pragma redefine_extname access ___mfwrap_access
++#pragma redefine_extname remove ___mfwrap_remove
++#pragma redefine_extname fflush ___mfwrap_fflush
++#pragma redefine_extname fseek ___mfwrap_fseek
++#pragma redefine_extname ftell ___mfwrap_ftell
++#pragma redefine_extname rewind ___mfwrap_rewind
++#pragma redefine_extname fgetpos ___mfwrap_fgetpos
++#pragma redefine_extname fsetpos ___mfwrap_fsetpos
++#pragma redefine_extname stat ___mfwrap_stat
++#pragma redefine_extname fstat ___mfwrap_fstat
++#pragma redefine_extname lstat ___mfwrap_lstat
++#pragma redefine_extname mkfifo ___mfwrap_mkfifo
++#pragma redefine_extname setvbuf ___mfwrap_setvbuf
++#pragma redefine_extname setbuf ___mfwrap_setbuf
++#pragma redefine_extname setbuffer ___mfwrap_setbuffer
++#pragma redefine_extname setlinebuf ___mfwrap_setlinebuf
++#pragma redefine_extname opendir ___mfwrap_opendir
++#pragma redefine_extname closedir ___mfwrap_closedir
++#pragma redefine_extname readdir ___mfwrap_readdir
++#pragma redefine_extname recv ___mfwrap_recv
++#pragma redefine_extname recvfrom ___mfwrap_recvfrom
++#pragma redefine_extname recvmsg ___mfwrap_recvmsg
++#pragma redefine_extname send ___mfwrap_send
++#pragma redefine_extname sendto ___mfwrap_sendto
++#pragma redefine_extname sendmsg ___mfwrap_sendmsg
++#pragma redefine_extname setsockopt ___mfwrap_setsockopt
++#pragma redefine_extname getsockopt ___mfwrap_getsockopt
++#pragma redefine_extname accept ___mfwrap_accept
++#pragma redefine_extname bind ___mfwrap_bind
++#pragma redefine_extname connect ___mfwrap_connect
++#pragma redefine_extname gethostname ___mfwrap_gethostname
++#pragma redefine_extname sethostname ___mfwrap_sethostname
++#pragma redefine_extname gethostbyname ___mfwrap_gethostbyname
++#pragma redefine_extname wait ___mfwrap_wait
++#pragma redefine_extname waitpid ___mfwrap_waitpid
++#pragma redefine_extname popen ___mfwrap_popen
++#pragma redefine_extname pclose ___mfwrap_pclose
++#pragma redefine_extname execve ___mfwrap_execve
++#pragma redefine_extname execv ___mfwrap_execv
++#pragma redefine_extname execvp ___mfwrap_execvp
++#pragma redefine_extname system ___mfwrap_system
++#pragma redefine_extname dlopen ___mfwrap_dlopen
++#pragma redefine_extname dlerror ___mfwrap_dlerror
++#pragma redefine_extname dlsym ___mfwrap_dlsym
++#pragma redefine_extname dlclose ___mfwrap_dlclose
++#pragma redefine_extname fopen64 ___mfwrap_fopen64
++#pragma redefine_extname freopen64 ___mfwrap_freopen64
++#pragma redefine_extname stat64 ___mfwrap_stat64
++#pragma redefine_extname fseeko64 ___mfwrap_fseeko64
++#pragma redefine_extname ftello64 ___mfwrap_ftello64
++#pragma redefine_extname semop ___mfwrap_semop
++#pragma redefine_extname semctl ___mfwrap_semctl
++#pragma redefine_extname shmctl ___mfwrap_shmctl
++#pragma redefine_extname shmat ___mfwrap_shmat
++#pragma redefine_extname shmdt ___mfwrap_shmdt
++#pragma redefine_extname __ctype_b_loc ___mfwrap___ctype_b_loc
++#pragma redefine_extname __ctype_toupper_loc ___mfwrap___ctype_toupper_loc
++#pragma redefine_extname __ctype_tolower_loc ___mfwrap___ctype_tolower_loc
++#pragma redefine_extname getlogin ___mfwrap_getlogin
++#pragma redefine_extname cuserid ___mfwrap_cuserid
++#pragma redefine_extname getpwnam ___mfwrap_getpwnam
++#pragma redefine_extname getpwuid ___mfwrap_getpwuid
++#pragma redefine_extname getgrnam ___mfwrap_getgrnam
++#pragma redefine_extname getgrgid ___mfwrap_getgrgid
++#pragma redefine_extname getservent ___mfwrap_getservent
++#pragma redefine_extname getservbyname ___mfwrap_getservbyname
++#pragma redefine_extname getservbyport ___mfwrap_getservbyport
++#pragma redefine_extname gai_strerror ___mfwrap_gai_strerror
++#pragma redefine_extname getmntent ___mfwrap_getmntent
++#pragma redefine_extname inet_ntoa ___mfwrap_inet_ntoa
++#pragma redefine_extname getprotoent ___mfwrap_getprotoent
++#pragma redefine_extname getprotobyname ___mfwrap_getprotobyname
++#pragma redefine_extname getprotobynumber ___mfwrap_getprotobynumber
++#endif /* __USER_LABEL_PREFIX__ */
+ 
+ /* Disable glibc macros.  */
+ #define __NO_STRING_INLINES
+--- a/src/libssp/ssp.c
++++ b/src/libssp/ssp.c
+@@ -63,6 +63,9 @@ see the files COPYING3 and COPYING.RUNTI
+ #ifdef HAVE_SYSLOG_H
+ # include <syslog.h>
+ #endif
++#ifdef __MINT__
++#include <mint/osbind.h>
++#endif
+ 
+ void *__stack_chk_guard = 0;
+ 
+@@ -96,7 +99,10 @@ __guard_setup (void)
+ static void
+ fail (const char *msg1, size_t msg1len, const char *msg3)
+ {
+-#ifdef __GNU_LIBRARY__
++#if defined(__MINT__)
++#define __progname program_invocation_short_name
++#endif
++#if defined(__GNU_LIBRARY__) || defined(__MINT__)
+   extern char * __progname;
+ #else
+   static const char __progname[] = "";
+@@ -139,6 +145,9 @@ fail (const char *msg1, size_t msg1len,
+     syslog (LOG_CRIT, msg3);
+ #endif /* HAVE_SYSLOG_H */
+ 
++#ifdef __MINT__
++  Pterm(127);
++#else
+   /* Try very hard to exit.  Note that signals may be blocked preventing
+      the first two options from working.  The use of volatile is here to
+      prevent optimizers from "knowing" that __builtin_trap is called first,
+@@ -160,6 +169,7 @@ fail (const char *msg1, size_t msg1len,
+           break;
+         }
+   }
++#endif
+ }
+ 
+ void
+--- /dev/null
++++ b/src/libstdc++-v3/config/os/mint/ctype_base.h
+@@ -0,0 +1,59 @@
++// Locale support -*- C++ -*-
++
++// Copyright (C) 1997, 1998, 1999, 2003, 2009, 2010
++// Free Software Foundation, Inc.
++//
++// This file is part of the GNU ISO C++ Library.  This library is free
++// software; you can redistribute it and/or modify it under the
++// terms of the GNU General Public License as published by the
++// Free Software Foundation; either version 3, or (at your option)
++// any later version.
++
++// This 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 General Public License for more details.
++
++// Under Section 7 of GPL version 3, you are granted additional
++// permissions described in the GCC Runtime Library Exception, version
++// 3.1, as published by the Free Software Foundation.
++
++// You should have received a copy of the GNU General Public License and
++// a copy of the GCC Runtime Library Exception along with this program;
++// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
++// <http://www.gnu.org/licenses/>.
++
++//
++// ISO C++ 14882: 22.1  Locales
++//
++
++// Mint C types, taken from mintlib-0.57.3/include/ctype.h
++
++namespace std _GLIBCXX_VISIBILITY(default)
++{
++_GLIBCXX_BEGIN_NAMESPACE_VERSION
++
++  /// @brief  Base class for ctype.
++  struct ctype_base
++  {
++    // Non-standard typedefs.
++    typedef const int* 		__to_type;
++
++    // NB: Offsets into ctype<char>::_M_table force a particular size
++    // on the mask type. Because of this, we don't use an enum.
++    typedef unsigned int 	mask;
++    static const mask upper    	= _CTu;
++    static const mask lower 	= _CTl;
++    static const mask alpha 	= _CTu | _CTl;
++    static const mask digit 	= _CTd;
++    static const mask xdigit 	= _CTx;
++    static const mask space 	= _CTs;
++    static const mask print 	= _CTP;
++    static const mask graph 	= _CTg;
++    static const mask cntrl 	= _CTc;
++    static const mask punct 	= _CTp;
++    static const mask alnum 	= _CTd | _CTu | _CTl ;
++  };
++
++_GLIBCXX_END_NAMESPACE_VERSION
++} // namespace
+--- /dev/null
++++ b/src/libstdc++-v3/config/os/mint/ctype_inline.h
+@@ -0,0 +1,76 @@
++// Locale support -*- C++ -*-
++
++// Copyright (C) 2000, 2003, 2009, 2010 Free Software Foundation, Inc.
++//
++// This file is part of the GNU ISO C++ Library.  This library is free
++// software; you can redistribute it and/or modify it under the
++// terms of the GNU General Public License as published by the
++// Free Software Foundation; either version 3, or (at your option)
++// any later version.
++
++// This 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 General Public License for more details.
++
++// Under Section 7 of GPL version 3, you are granted additional
++// permissions described in the GCC Runtime Library Exception, version
++// 3.1, as published by the Free Software Foundation.
++
++// You should have received a copy of the GNU General Public License and
++// a copy of the GCC Runtime Library Exception along with this program;
++// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
++// <http://www.gnu.org/licenses/>.
++
++/** @file bits/ctype_inline.h
++ *  This is an internal header file, included by other library headers.
++ *  Do not attempt to use it directly. @headername{locale}
++ */
++
++//
++// ISO C++ 14882: 22.1  Locales
++//
++
++// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
++// functions go in ctype.cc
++
++// Mint C types, taken from mintlib-0.57.3/include/ctype.h
++
++namespace std _GLIBCXX_VISIBILITY(default)
++{
++_GLIBCXX_BEGIN_NAMESPACE_VERSION
++
++  bool
++  ctype<char>::
++  is(mask __m, char __c) const
++  { return _ctype[(unsigned char)((__c) + 1)] & __m; }
++
++  const char*
++  ctype<char>::
++  is(const char* __low, const char* __high, mask* __vec) const
++  {
++    while (__low < __high)
++      *__vec++ = _ctype[(*__low++) + 1] ;
++    return __high;
++  }
++
++  const char*
++  ctype<char>::
++  scan_is(mask __m, const char* __low, const char* __high) const
++  {
++    while (__low < __high && !this->is(__m, *__low))
++      ++__low;
++    return __low;
++  }
++
++  const char*
++  ctype<char>::
++  scan_not(mask __m, const char* __low, const char* __high) const
++  {
++    while (__low < __high && this->is(__m, *__low) != 0)
++      ++__low;
++    return __low;
++  }
++
++_GLIBCXX_END_NAMESPACE_VERSION
++} // namespace
+--- /dev/null
++++ b/src/libstdc++-v3/config/os/mint/ctype_noninline.h
+@@ -0,0 +1,92 @@
++// Locale support -*- C++ -*-
++
++// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2009, 2010
++//  Free Software Foundation, Inc.
++//
++// This file is part of the GNU ISO C++ Library.  This library is free
++// software; you can redistribute it and/or modify it under the
++// terms of the GNU General Public License as published by the
++// Free Software Foundation; either version 3, or (at your option)
++// any later version.
++
++// This 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 General Public License for more details.
++
++// Under Section 7 of GPL version 3, you are granted additional
++// permissions described in the GCC Runtime Library Exception, version
++// 3.1, as published by the Free Software Foundation.
++
++// You should have received a copy of the GNU General Public License and
++// a copy of the GCC Runtime Library Exception along with this program;
++// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
++// <http://www.gnu.org/licenses/>.
++
++/** @file bits/ctype_noninline.h
++ *  This is an internal header file, included by other library headers.
++ *  Do not attempt to use it directly. @headername{locale}
++ */
++
++//
++// ISO C++ 14882: 22.1  Locales
++//
++
++// Information as gleaned from /usr/include/ctype.h
++
++  const ctype_base::mask*
++  ctype<char>::classic_table() throw()
++  { return 0; }
++
++  ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
++		     size_t __refs)
++  : facet(__refs), _M_del(__table != 0 && __del),
++  _M_toupper(NULL), _M_tolower(NULL),
++  _M_table(__table ? __table : classic_table())
++  {
++    memset(_M_widen, 0, sizeof(_M_widen));
++    _M_widen_ok = 0;
++    memset(_M_narrow, 0, sizeof(_M_narrow));
++    _M_narrow_ok = 0;
++  }
++
++  ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
++  : facet(__refs), _M_del(__table != 0 && __del),
++  _M_toupper(NULL), _M_tolower(NULL),
++  _M_table(__table ? __table : classic_table())
++  {
++    memset(_M_widen, 0, sizeof(_M_widen));
++    _M_widen_ok = 0;
++    memset(_M_narrow, 0, sizeof(_M_narrow));
++    _M_narrow_ok = 0;
++  }
++
++  char
++  ctype<char>::do_toupper(char __c) const
++  { return ::toupper((int) __c); }
++
++  const char*
++  ctype<char>::do_toupper(char* __low, const char* __high) const
++  {
++    while (__low < __high)
++      {
++	*__low = ::toupper((int) *__low);
++	++__low;
++      }
++    return __high;
++  }
++
++  char
++  ctype<char>::do_tolower(char __c) const
++  { return ::tolower((int) __c); }
++
++  const char*
++  ctype<char>::do_tolower(char* __low, const char* __high) const
++  {
++    while (__low < __high)
++      {
++	*__low = ::tolower((int) *__low);
++	++__low;
++      }
++    return __high;
++  }
+--- /dev/null
++++ b/src/libstdc++-v3/config/os/mint/os_defines.h
+@@ -0,0 +1,36 @@
++// Specific definitions for generic platforms  -*- C++ -*-
++
++// Copyright (C) 2000, 2009, 2010 Free Software Foundation, Inc.
++//
++// This file is part of the GNU ISO C++ Library.  This library is free
++// software; you can redistribute it and/or modify it under the
++// terms of the GNU General Public License as published by the
++// Free Software Foundation; either version 3, or (at your option)
++// any later version.
++
++// This 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 General Public License for more details.
++
++// Under Section 7 of GPL version 3, you are granted additional
++// permissions described in the GCC Runtime Library Exception, version
++// 3.1, as published by the Free Software Foundation.
++
++// You should have received a copy of the GNU General Public License and
++// a copy of the GCC Runtime Library Exception along with this program;
++// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
++// <http://www.gnu.org/licenses/>.
++
++/** @file bits/os_defines.h
++ *  This is an internal header file, included by other library headers.
++ *  Do not attempt to use it directly. @headername{iosfwd}
++ */
++
++#ifndef _GLIBCXX_OS_DEFINES
++#define _GLIBCXX_OS_DEFINES 1
++
++// System-specific #define, typedefs, corrections, etc, go here.  This
++// file will come before all others.
++
++#endif
+--- a/src/libstdc++-v3/configure.host
++++ b/src/libstdc++-v3/configure.host
+@@ -258,6 +258,10 @@ case "${host_os}" in
+     error_constants_dir="os/mingw32"
+     OPT_LDFLAGS="${OPT_LDFLAGS} \$(lt_host_flags)"
+     ;;
++  mint*)
++    SECTION_FLAGS="${SECTION_FLAGS} -D_GNU_SOURCE"
++    os_include_dir="os/mint"
++    ;;
+   netbsd*)
+     os_include_dir="os/bsd/netbsd"
+     ;;
+--- a/src/libstdc++-v3/crossconfig.m4
++++ b/src/libstdc++-v3/crossconfig.m4
+@@ -141,7 +141,7 @@ case "${host}" in
+ 	;;
+     esac
+     ;;
+-  *-linux* | *-uclinux* | *-gnu* | *-kfreebsd*-gnu | *-knetbsd*-gnu)
++  *-linux* | *-uclinux* | *-gnu* | *-kfreebsd*-gnu | *-knetbsd*-gnu | *-mint*)
+     GLIBCXX_CHECK_COMPILER_FEATURES
+     GLIBCXX_CHECK_LINKER_FEATURES
+     GLIBCXX_CHECK_MATH_SUPPORT
--- gcc-4.6-4.6.3/debian/patches/libffi-m68k.diff
+++ gcc-4.6-4.6.3/debian/patches/libffi-m68k.diff
@@ -1,5 +1,16 @@
+# DP: Apply #660525 fix to in-tree libffi
+
 --- a/src/libffi/src/m68k/sysv.S
 +++ b/src/libffi/src/m68k/sysv.S
+@@ -87,7 +87,7 @@
+ 
+ 	| If the return value pointer is NULL, assume no return value.
+ 	| NOTE: On the mc68000, tst on an address register is not supported.
+-#if defined(__mc68000__) && !defined(__mcoldfire__)
++#if !defined(__mc68020__) && !defined(__mc68030__) && !defined(__mc68040__) && !defined(__mc68060__) && !defined(__mcoldfire__)
+ 	cmp.w	#0, %a1
+ #else
+ 	tst.l	%a1
 @@ -109,7 +109,7 @@
  retfloat:
  	btst	#2,%d2

Reply to: