#! /bin/sh -e

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p0 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

# DP: PR target/27880: Restore static linking on ia64 with system libunwind
# DP: by adding unwind-compat to the static libgcc.

2006-06-19  Andreas Schwab  <schwab@suse.de>

	PR target/27880
	* unwind-compat.c: Wrap everything except _Unwind_GetIPInfo inside
	SHARED.
	* config/t-libunwind (LIB2ADDEHSTATIC): Add
	$(srcdir)/unwind-compat.c.

Index: gcc/config/t-libunwind
===================================================================
--- gcc/config/t-libunwind	(revision 114767)
+++ gcc/config/t-libunwind	(working copy)
@@ -6,7 +6,8 @@
 SHLIB_LC = -lunwind -lc
 LIB2ADDEH = $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c \
   $(srcdir)/unwind-compat.c $(srcdir)/unwind-dw2-fde-compat.c
-LIB2ADDEHSTATIC = $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c
+LIB2ADDEHSTATIC = $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c \
+  $(srcdir)/unwind-compat.c
 
 T_CFLAGS += -DUSE_LIBUNWIND_EXCEPTIONS
 TARGET_LIBGCC2_CFLAGS += -DUSE_GAS_SYMVER
Index: gcc/unwind-compat.c
===================================================================
--- gcc/unwind-compat.c	(revision 114767)
+++ gcc/unwind-compat.c	(working copy)
@@ -35,6 +35,7 @@
 #include "unwind-dw2-fde.h"
 #include "unwind-compat.h"
 
+#ifdef SHARED
 extern _Unwind_Reason_Code __libunwind_Unwind_Backtrace
   (_Unwind_Trace_Fn, void *);
 
@@ -136,13 +137,6 @@ _Unwind_GetIP (struct _Unwind_Context *c
 }
 symver (_Unwind_GetIP, GCC_3.0);
 
-_Unwind_Ptr
-_Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
-{
-  *ip_before_insn = 0;
-  return __libunwind_Unwind_GetIP (context);
-}
-
 extern void *__libunwind_Unwind_GetLanguageSpecificData
   (struct _Unwind_Context *);
 
@@ -212,4 +206,14 @@ _Unwind_SetIP (struct _Unwind_Context *c
   return __libunwind_Unwind_SetIP (context, val);
 }
 symver (_Unwind_SetIP, GCC_3.0);
+#endif /* SHARED */
+
+extern _Unwind_Ptr __libunwind_Unwind_GetIP (struct _Unwind_Context *);
+
+_Unwind_Ptr
+_Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
+{
+  *ip_before_insn = 0;
+  return __libunwind_Unwind_GetIP (context);
+}
 #endif

