From: David Mair <dmair@suse.com>
Date: 2017-03-28 17:17:25.532260682 -0600
Subject: Add application of GLIBC proc_service prototype cleanup from upstream
References: bnc#1029318 bnc#1022962
Upstream: tbd (crash); merged (gdb)

crash source nests gdb source but crash/gdb has a newly seen build error on
some cases due to a "cause" and a new build environment. The cause is that the
function prototype for extern ps_get_thread_area() in GLIBC/proc_service has a
non-const first argument but implementations in crash's gdb have a const first
argument. Then gcc considers the definition as for a different function from
the declaration (conflicting types for 'ps_get_thread_area').

The fix is in upstream gdb (current):

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=754653a7c0a43a668a38aa30c4063b9e292a19f9

...but not upstream crash's gdb (older).

Created crash patch:

crash-gdb-add-proc_service-sync-with-GLIBC.patch

...to create a context fixed version of the gdb patch in expanded crash and
added it's application to the gdb Makefile patch. Note that "fixed" means
making it applicable to the older version of gdb in crash rather than the gdb
version the upstream gdb patch was intended for. Resolves the build error
causes I'm aware of.

I will make a public submission to crash upstream right away but there it will
probably be of the nested content rather than this patch of a patch. Upstream
generates the source tarball and the method used here was to avoid creating a
unique case of the source tarball containing the patch.

---
 Makefile |    1 +
 gdb-7.6-sync-proc_service-definition-with-GLIBC.patch | 277 +++++++++++++++++++
 2 file changed, 278 insertions(+)

--- a/Makefile
+++ b/Makefile
@@ -263,8 +263,9 @@ gdb_unzip:
 gdb_patch:
 	if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
 		patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
 	patch -d ${GDB} -p1 -F0 < ${GDB}-ppc64le-support.patch ; \
+	patch -d ${GDB} -p1 -F0 < ${GDB}-sync-proc_service-definition-with-GLIBC.patch ; \
 	if [ -f ${GDB}.series ]; then \
 		while read p; do \
 			patch -d ${GDB} -p1 -F0 < "$$p" ; \
 		done < ${GDB}.series ; \
--- /dev/null
+++ b/gdb-7.6-sync-proc_service-definition-with-GLIBC.patch
@@ -0,0 +1,277 @@
+From 754653a7c0a43a668a38aa30c4063b9e292a19f9 Mon Sep 17 00:00:00 2001
+From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
+Date: Thu, 25 Aug 2016 08:42:03 +0100
+Subject: [PATCH] Sync proc_service definition with GLIBC
+
+GLIBC BZ#20311 [1] proc_service.h install patch also remove 'const'
+attributes from ps_get_thread_area and comment #15 discuss why to remove
+the const attribute (basically since it a callback with the struct
+ps_prochandle owned by the client it should be able to modify it if
+it the case).
+
+On default build this is not the issue and current g++ does not trigger
+any issue with this mismatch declaration.  However, on some bootstrap
+build configuration where gdbserver is build with gcc instead this
+triggers:
+
+error: conflicting types for 'ps_get_thread_area'
+
+This patch fixes it by syncing the declaration with GLIBC.
+
+[1] https://sourceware.org/bugzilla/show_bug.cgi?id=20311
+
+gdb/ChangeLog:
+
+2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* aarch64-linux-nat.c (ps_get_thread_area): Remove const from
+	struct ps_prochandle.
+	* amd64-linux-nat.c (ps_get_thread_area): Likewise.
+	* arm-linux-nat.c (ps_get_thread_area): Likewise.
+	* gdb_proc_service.h (ps_get_thread_area): Likewise.
+	* i386-linux-nat.c (ps_get_thread_area): Likewise.
+	* m68klinux-nat.c (ps_get_thread_area): Likewise.
+	* mips-linux-nat.c (ps_get_thread_area): Likewise.
+
+gdb/gdbserver/ChangeLog:
+
+2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	PR server/20491
+	* gdb_proc_service.h (ps_get_thread_area): Remove const from struct
+	ps_prochandle.
+	* linux-aarch64-low.c (ps_get_thread_area): Likewise.
+	* linux-arm-low.c (ps_get_thread_area): Likewise.
+	* linux-m68k-low.c (ps_get_thread_area): Likewise.
+	* linux-mips-low.c (ps_get_thread_area): Likewise.
+	* linux-tic6x-low.c (ps_get_thread_area): Likewise.
+	* linux-x86-low.c (ps_get_thread_area): Likewise.
+---
+ gdb/ChangeLog                     | 14 ++++++++++++++
+ gdb/aarch64-linux-nat.c           |  2 +-
+ gdb/amd64-linux-nat.c             |  2 +-
+ gdb/arm-linux-nat.c               |  2 +-
+ gdb/gdb_proc_service.h            |  2 +-
+ gdb/gdbserver/ChangeLog           | 15 +++++++++++++++
+ gdb/gdbserver/linux-aarch64-low.c |  2 +-
+ gdb/gdbserver/linux-arm-low.c     |  2 +-
+ gdb/gdbserver/linux-m68k-low.c    |  2 +-
+ gdb/gdbserver/linux-mips-low.c    |  2 +-
+ gdb/gdbserver/linux-tic6x-low.c   |  2 +-
+ gdb/gdbserver/linux-x86-low.c     |  2 +-
+ gdb/i386-linux-nat.c              |  2 +-
+ gdb/m68klinux-nat.c               |  2 +-
+ gdb/mips-linux-nat.c              |  2 +-
+ 17 files changed, 44 insertions(+), 15 deletions(-)
+
+diff --git a/gdb/ChangeLog b/gdb/ChangeLog
+index 0d875c8..677ed7d 100644
+--- a/gdb/ChangeLog
++++ b/gdb/ChangeLog
+@@ -1,3 +1,14 @@
++2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
++
++	* aarch64-linux-nat.c (ps_get_thread_area): Remove const from
++	struct ps_prochandle.
++	* amd64-linux-nat.c (ps_get_thread_area): Likewise.
++	* arm-linux-nat.c (ps_get_thread_area): Likewise.
++	* gdb_proc_service.h (ps_get_thread_area): Likewise.
++	* i386-linux-nat.c (ps_get_thread_area): Likewise.
++	* m68klinux-nat.c (ps_get_thread_area): Likewise.
++	* mips-linux-nat.c (ps_get_thread_area): Likewise.
++
+ 2013-11-15  Alan Modra  <amodra@gmail.com>
+ 
+ 	* ppc64-tdep.c (ppc64_plt_entry_point): Renamed from..
+diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
+index e431637..65ca8ff 100644
+--- a/gdb/aarch64-linux-nat.c
++++ b/gdb/aarch64-linux-nat.c
+@@ -750,7 +750,7 @@ aarch64_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
+    storage (or its descriptor).  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   struct iovec iovec;
+diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
+index fea6ee2..5122b04 100644
+--- a/gdb/amd64-linux-nat.c
++++ b/gdb/amd64-linux-nat.c
+@@ -493,7 +493,7 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
+    a request for a thread's local storage address.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 32)
+diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c
+index d77ca93..d11bdc6 100644
+--- a/gdb/arm-linux-nat.c
++++ b/gdb/arm-linux-nat.c
+@@ -613,7 +613,7 @@ supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdb_proc_service.h b/gdb/gdb_proc_service.h
+index 38b98fc..0a9f26d 100644
+--- a/gdb/gdb_proc_service.h
++++ b/gdb/gdb_proc_service.h
+@@ -115,7 +115,7 @@ extern pid_t ps_getpid (struct ps_prochandle *);
+ /* Fetch the special per-thread address associated with the given LWP.
+    This call is only used on a few platforms (most use a normal register).
+    The meaning of the `int' parameter is machine-dependent.  */
+-extern ps_err_e ps_get_thread_area (const struct ps_prochandle *,
++extern ps_err_e ps_get_thread_area (struct ps_prochandle *,
+ 				    lwpid_t, int, psaddr_t *);
+ 
+ 
+diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
+index c28c2cb..af0140f 100644
+--- a/gdb/gdbserver/ChangeLog
++++ b/gdb/gdbserver/ChangeLog
+@@ -1,3 +1,15 @@
++2016-08-25  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
++
++	PR server/20491
++	* gdb_proc_service.h (ps_get_thread_area): Remove const from struct
++	ps_prochandle.
++	* linux-aarch64-low.c (ps_get_thread_area): Likewise.
++	* linux-arm-low.c (ps_get_thread_area): Likewise.
++	* linux-m68k-low.c (ps_get_thread_area): Likewise.
++	* linux-mips-low.c (ps_get_thread_area): Likewise.
++	* linux-tic6x-low.c (ps_get_thread_area): Likewise.
++	* linux-x86-low.c (ps_get_thread_area): Likewise.
++
+ 2013-04-25  Hui Zhu  <hui@codesourcery.com>
+ 
+ 	PR gdb/15186
+diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
+index 6efa035..e54a8ba 100644
+--- a/gdb/gdbserver/linux-aarch64-low.c
++++ b/gdb/gdbserver/linux-aarch64-low.c
+@@ -1089,7 +1089,7 @@ aarch64_stopped_by_watchpoint (void)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   struct iovec iovec;
+diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c
+index e1261e5..ed9b356 100644
+--- a/gdb/gdbserver/linux-arm-low.c
++++ b/gdb/gdbserver/linux-arm-low.c
+@@ -325,7 +325,7 @@ get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr,
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-m68k-low.c b/gdb/gdbserver/linux-m68k-low.c
+index df3d7c6..78a340f 100644
+--- a/gdb/gdbserver/linux-m68k-low.c
++++ b/gdb/gdbserver/linux-m68k-low.c
+@@ -159,7 +159,7 @@ m68k_breakpoint_at (CORE_ADDR pc)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-mips-low.c b/gdb/gdbserver/linux-mips-low.c
+index 30a03d5..9356bb3 100644
+--- a/gdb/gdbserver/linux-mips-low.c
++++ b/gdb/gdbserver/linux-mips-low.c
+@@ -238,7 +238,7 @@ mips_stopped_data_address (void)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-tic6x-low.c b/gdb/gdbserver/linux-tic6x-low.c
+index e40a3af..6b90560 100644
+--- a/gdb/gdbserver/linux-tic6x-low.c
++++ b/gdb/gdbserver/linux-tic6x-low.c
+@@ -256,7 +256,7 @@ tic6x_breakpoint_at (CORE_ADDR where)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
+index d847b93..acded1a 100644
+--- a/gdb/gdbserver/linux-x86-low.c
++++ b/gdb/gdbserver/linux-x86-low.c
+@@ -164,7 +164,7 @@ is_64bit_tdesc (void)
+ /* Called by libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+ #ifdef __x86_64__
+diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
+index a41ee21..70d954f 100644
+--- a/gdb/i386-linux-nat.c
++++ b/gdb/i386-linux-nat.c
+@@ -849,7 +849,7 @@ i386_linux_new_fork (struct lwp_info *parent, pid_t child_pid)
+    storage (or its descriptor).  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph, 
++ps_get_thread_area (struct ps_prochandle *ph,
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   /* NOTE: cagney/2003-08-26: The definition of this buffer is found
+diff --git a/gdb/m68klinux-nat.c b/gdb/m68klinux-nat.c
+index 24b6242..5b8684b 100644
+--- a/gdb/m68klinux-nat.c
++++ b/gdb/m68klinux-nat.c
+@@ -568,7 +568,7 @@ m68k_linux_store_inferior_registers (struct target_ops *ops,
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph, 
++ps_get_thread_area (struct ps_prochandle *ph, 
+ 		    lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) < 0)
+diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c
+index bfe9fcb..0f20f16 100644
+--- a/gdb/mips-linux-nat.c
++++ b/gdb/mips-linux-nat.c
+@@ -154,7 +154,7 @@ mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
+ /* Fetch the thread-local storage pointer for libthread_db.  */
+ 
+ ps_err_e
+-ps_get_thread_area (const struct ps_prochandle *ph,
++ps_get_thread_area (struct ps_prochandle *ph,
+                     lwpid_t lwpid, int idx, void **base)
+ {
+   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+-- 
+2.9.3
+
