public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Share code to disable ASR between GDB and gdbserver
@ 2015-01-09 22:19 Sergio Durigan Junior
  2015-01-09 22:19 ` [PATCH 2/2] Move code to disable ASR to nat/ Sergio Durigan Junior
  2015-01-09 22:19 ` [PATCH 1/2] Move safe_strerror to common/ Sergio Durigan Junior
  0 siblings, 2 replies; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-09 22:19 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Gary Benson

Hi,

This patch series shares code to disable ASR (address space
randomization) between GDB and gdbserver.  Specifically, it shares
parts of the code of the following functions:

  - gdb/linux-nat.c:linux_nat_create_inferior
  - gdb/gdbserver/linux-low.c:linux_create_inferior

It creates a new file under nat/, named linux-personality.c.  This new
file contains some functions that disable ASR before the inferior is
created, and then create a cleanup that can be called at the end of
the *_create_inferior function to re-enable ASR.  This idea was
proposed by Gary, and it is possible because gdbserver now can make
use of exceptions and cleanups (thanks, Gary!).

Before being able to share this code, I had to struggle with
safe_strerror: the GDB code to disable ASR calls this function to
report an error, but gdbserver calls only strerror.  So, after some
time, I managed to share safe_strerror between both; the code now
lives in common/, and obeys the original separation between POSIX and
MingW systems.  Pedro pointed out that we could import the strerror
module from gnulib, which already addresses the same issues that our
safe_strerror does, and does a bit more.  However, this has already
been tried before (by Tom Tromey), and the result was not good.  For
more details, please read this thread:
<https://lists.gnu.org/archive/html/bug-gnulib/2013-11/msg00078.html>.
In the end, I decided to share safe_strerror between both GDB and
gdbserver.

I regtested this patch on Fedora 20 x86_64, and found no regressions.
I intend to check the patches separately in the tree.

OK to check in?

Sergio.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/2] Move safe_strerror to common/
  2015-01-09 22:19 [PATCH 0/2] Share code to disable ASR between GDB and gdbserver Sergio Durigan Junior
  2015-01-09 22:19 ` [PATCH 2/2] Move code to disable ASR to nat/ Sergio Durigan Junior
@ 2015-01-09 22:19 ` Sergio Durigan Junior
  2015-01-13 16:54   ` Pedro Alves
  1 sibling, 1 reply; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-09 22:19 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Gary Benson, Sergio Durigan Junior

This patch moves safe_strerror from the gdb/{posix,mingw}-hdep.c files
to the respective common/{posix,mingw}-strerror.c files.  This is a
preparation for the next patch, which shares a common code (to disable
address space randomization when creating a new inferior).

The patch has been regtested on Fedora 20 x86_64, and no regressions
were found.  I am assuming the MingW modifications are also safe, but
I have not checked them too deep.

gdb/ChangeLog
2015-01-09  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (ALLDEPFILES): Including common/mingw-strerror.c and
	common/posix-strerror.c.
	(posix-strerror.o): New rule.
	(mingw-strerror.o): Likewise.
	* common/common-utils.h (safe_strerror): Move prototype to here,
	from utils.h.
	* common/common.host: New file.
	* common/mingw-strerror.c: Likewise.
	* common/posix-strerror.c: Likewise.
	* configure: Regenerated.
	* configure.ac: Add posix-strerror.o to the $gdb_host_obs
	variable.  Source common/common.host.
	* configure.host: Remove variable gdb_host_obs (moved to
	common/common.host).
	* contrib/ari/gdb_ari.sh: Mention gdb/common/mingw-strerror.c and
	gdb/common/posix-strerror.c when warning about the use of
	strerror.
	* mingw-hdep.c (safe_strerror): Remove definition; move it to
	common/mingw-strerror.c.
	* posix-hdep.c (safe_strerror): Remove definition; move it to
	common/posix-hdep.c.
	* utils.h (safe_strerror): Remove prototype; move to
	common/common-utils.h.

gdb/gdbserver/ChangeLog
2015-01-09  Sergio Durigan Junior  <sergiodj@redhat.com>

	* configure: Regenerated.
	* configure.ac: Initialize new variable $srv_host_obs.  Source
	file ../common/common.host.  Add $srv_host_obs to GDBSERVER_DEPFILES.
---
 gdb/Makefile.in             | 12 +++++++--
 gdb/common/common-utils.h   |  6 +++++
 gdb/common/common.host      | 17 ++++++++++++
 gdb/common/mingw-strerror.c | 64 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/common/posix-strerror.c | 38 +++++++++++++++++++++++++++
 gdb/configure               |  3 ++-
 gdb/configure.ac            |  3 ++-
 gdb/configure.host          |  3 ---
 gdb/contrib/ari/gdb_ari.sh  |  4 +--
 gdb/gdbserver/Makefile.in   |  6 +++++
 gdb/gdbserver/configure     |  7 ++++-
 gdb/gdbserver/configure.ac  |  7 ++++-
 gdb/mingw-hdep.c            | 44 -------------------------------
 gdb/posix-hdep.c            | 20 --------------
 gdb/utils.h                 |  3 ---
 15 files changed, 159 insertions(+), 78 deletions(-)
 create mode 100644 gdb/common/common.host
 create mode 100644 gdb/common/mingw-strerror.c
 create mode 100644 gdb/common/posix-strerror.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 5dae3e6..a8bae82 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1680,7 +1680,7 @@ ALLDEPFILES = \
 	m68klinux-nat.c m68klinux-tdep.c \
 	m88k-tdep.c m88kbsd-nat.c \
 	microblaze-tdep.c microblaze-linux-tdep.c \
-	mingw-hdep.c \
+	mingw-hdep.c common/mingw-strerror.c \
 	mips-linux-nat.c mips-linux-tdep.c \
 	mips-sde-tdep.c \
 	mips-tdep.c \
@@ -1690,7 +1690,7 @@ ALLDEPFILES = \
 	nios2-tdep.c nios2-linux-tdep.c \
 	nbsd-nat.c nbsd-tdep.c obsd-nat.c obsd-tdep.c \
 	somread.c solib-som.c \
-	posix-hdep.c \
+	posix-hdep.c common/posix-strerror.c \
 	ppc-sysv-tdep.c ppc-linux-nat.c ppc-linux-tdep.c ppc64-tdep.c \
 	ppcfbsd-nat.c ppcfbsd-tdep.c \
 	ppcnbsd-nat.c ppcnbsd-tdep.c \
@@ -2228,6 +2228,14 @@ common-exceptions.o: ${srcdir}/common/common-exceptions.c
 	$(COMPILE) $(srcdir)/common/common-exceptions.c
 	$(POSTCOMPILE)
 
+posix-strerror.o: ${srcdir}/common/posix-strerror.c
+	$(COMPILE) $(srcdir)/common/posix-strerror.c
+	$(POSTCOMPILE)
+
+mingw-strerror.o: ${srcdir}/common/mingw-strerror.c
+	$(COMPILE) $(srcdir)/common/mingw-strerror.c
+	$(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index f110924..60aa030 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -62,4 +62,10 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
 
 char *savestring (const char *ptr, size_t len);
 
+/* The strerror() function can return NULL for errno values that are
+   out of range.  Provide a "safe" version that always returns a
+   printable string.  */
+
+extern char *safe_strerror (int);
+
 #endif
diff --git a/gdb/common/common.host b/gdb/common/common.host
new file mode 100644
index 0000000..74c4515
--- /dev/null
+++ b/gdb/common/common.host
@@ -0,0 +1,17 @@
+# Mapping of configurations into GDB host definitions.  This is
+# invoked from the autoconf generated configure script.
+
+# This file sets the following shell variables:
+#  gdb_host_obs			host-specific .o files to include when building GDB
+#  srv_host_obs			likewise, but when building gdbserver
+
+case "${host}" in
+
+i[34567]86-*-mingw32*)	gdb_host_obs="mingw-hdep.o mingw-strerror.o"
+			srv_host_obs="mingw-strerror.o"
+			;;
+x86_64-*-mingw*)        gdb_host_obs="mingw-hdep.o mingw-strerror.o"
+			srv_host_obs="mingw-strerror.o"
+			;;
+
+esac
diff --git a/gdb/common/mingw-strerror.c b/gdb/common/mingw-strerror.c
new file mode 100644
index 0000000..c62c42d
--- /dev/null
+++ b/gdb/common/mingw-strerror.c
@@ -0,0 +1,64 @@
+/* Safe version of strerror for MinGW, for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+#include <windows.h>
+
+/* Implementation of safe_strerror as defined in common-utils.h.
+
+   The Windows runtime implementation of strerror never returns NULL,
+   but does return a useless string for anything above sys_nerr;
+   unfortunately this includes all socket-related error codes.
+   This replacement tries to find a system-provided error message.  */
+
+char *
+safe_strerror (int errnum)
+{
+  static char *buffer;
+  int len;
+
+  if (errnum >= 0 && errnum < sys_nerr)
+    return strerror (errnum);
+
+  if (buffer)
+    {
+      LocalFree (buffer);
+      buffer = NULL;
+    }
+
+  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+		     | FORMAT_MESSAGE_FROM_SYSTEM,
+		     NULL, errnum,
+		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+		     (LPTSTR) &buffer, 0, NULL) == 0)
+    {
+      static char buf[32];
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      return buf;
+    }
+
+  /* Windows error messages end with a period and a CR-LF; strip that
+     out.  */
+  len = strlen (buffer);
+  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
+    buffer[len - 3] = '\0';
+
+  return buffer;
+}
diff --git a/gdb/common/posix-strerror.c b/gdb/common/posix-strerror.c
new file mode 100644
index 0000000..119fcf6
--- /dev/null
+++ b/gdb/common/posix-strerror.c
@@ -0,0 +1,38 @@
+/* Safe version of strerror for POSIX systems for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+/* Implementation of safe_strerror as defined in common-utils.h.  */
+
+char *
+safe_strerror (int errnum)
+{
+  char *msg;
+
+  msg = strerror (errnum);
+  if (msg == NULL)
+    {
+      static char buf[32];
+
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      msg = buf;
+    }
+  return (msg);
+}
diff --git a/gdb/configure b/gdb/configure
index 7ff74ba..2d53196 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -5298,7 +5298,7 @@ fi
 
 # Provide defaults for some variables set by the per-host and per-target
 # configuration.
-gdb_host_obs=posix-hdep.o
+gdb_host_obs="posix-hdep.o posix-strerror.o"
 
 if test "${target}" = "${host}"; then
   gdb_native=yes
@@ -5307,6 +5307,7 @@ else
 fi
 
 . $srcdir/configure.host
+. $srcdir/common/common.host
 
 # Accumulate some settings from configure.tgt over all enabled targets
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index ec776d7..e03c747 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -195,7 +195,7 @@ esac],[want64=false])dnl
 
 # Provide defaults for some variables set by the per-host and per-target
 # configuration.
-gdb_host_obs=posix-hdep.o
+gdb_host_obs="posix-hdep.o posix-strerror.o"
 
 if test "${target}" = "${host}"; then
   gdb_native=yes
@@ -204,6 +204,7 @@ else
 fi
 
 . $srcdir/configure.host
+. $srcdir/common/common.host
 
 # Accumulate some settings from configure.tgt over all enabled targets
 
diff --git a/gdb/configure.host b/gdb/configure.host
index d07be4b..9f8a917 100644
--- a/gdb/configure.host
+++ b/gdb/configure.host
@@ -7,7 +7,6 @@
 #  gdb_host_float_format	host's float floatformat, or 0
 #  gdb_host_double_format	host's double floatformat, or 0
 #  gdb_host_long_double_format	host's long double floatformat, or 0
-#  gdb_host_obs			host-specific .o files to include
 
 # Map host cpu into the config cpu subdirectory name.
 # The default is $host_cpu.
@@ -105,7 +104,6 @@ i[34567]86-*-netbsdelf* | i[34567]86-*-knetbsd*-gnu)
 			gdb_host=nbsdelf ;;
 i[34567]86-*-go32*)	gdb_host=go32 ;;
 i[34567]86-*-mingw32*)	gdb_host=mingw
-			gdb_host_obs=mingw-hdep.o
 			;;
 i[34567]86-*-msdosdjgpp*) gdb_host=go32 ;;
 i[34567]86-*-linux*)	gdb_host=linux ;;
@@ -181,7 +179,6 @@ x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
 			gdb_host=nbsd64 ;;
 x86_64-*-openbsd*)	gdb_host=obsd64 ;;
 x86_64-*-mingw*)        gdb_host=mingw64
-			gdb_host_obs=mingw-hdep.o
 			;;
 x86_64-*-cygwin*)	gdb_host=cygwin64 ;;
 m32r*-*-linux*)          gdb_host=linux ;;
diff --git a/gdb/contrib/ari/gdb_ari.sh b/gdb/contrib/ari/gdb_ari.sh
index 8a8cec8..b868a17 100644
--- a/gdb/contrib/ari/gdb_ari.sh
+++ b/gdb/contrib/ari/gdb_ari.sh
@@ -603,8 +603,8 @@ BEGIN { doc["strerror"] = "\
 Do not use strerror(), instead use safe_strerror()"
     category["strerror"] = ari_regression
     fix("strerror", "gdb/gdb_string.h", 1)
-    fix("strerror", "gdb/mingw-hdep.c", 1)
-    fix("strerror", "gdb/posix-hdep.c", 1)
+    fix("strerror", "gdb/common/mingw-strerror.c", 1)
+    fix("strerror", "gdb/common/posix-strerror.c", 1)
 }
 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
     fail("strerror")
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 1ed2ec8..f05f450 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -518,6 +518,12 @@ rsp-low.o: ../common/rsp-low.c
 common-utils.o: ../common/common-utils.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+posix-strerror.o: ../common/posix-strerror.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+mingw-strerror.o: ../common/mingw-strerror.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 vec.o: ../common/vec.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 45efc51..cddc8d7 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -5537,7 +5537,12 @@ $as_echo "$gdb_cv_m68k_is_coldfire" >&6; }
     ;;
 esac
 
+# Initialize as POSIX.  This will change if the host is MingW.
+
+srv_host_obs="posix-strerror.o"
+
 . ${srcdir}/configure.srv
+. ${srcdir}/../common/common.host
 
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
@@ -6034,7 +6039,7 @@ $as_echo "#define USE_XML 1" >>confdefs.h
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports __sync_*_compare_and_swap" >&5
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 02082cc..31fa42d 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -240,7 +240,12 @@ got it
     ;;
 esac
 
+# Initialize as POSIX.  This will change if the host is MingW.
+
+srv_host_obs="posix-strerror.o"
+
 . ${srcdir}/configure.srv
+. ${srcdir}/../common/common.host
 
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
@@ -385,7 +390,7 @@ if test "$srv_xmlfiles" != ""; then
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 dnl Check whether the target supports __sync_*_compare_and_swap.
diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c
index c0cc385..a0ed281 100644
--- a/gdb/mingw-hdep.c
+++ b/gdb/mingw-hdep.c
@@ -35,50 +35,6 @@ static HANDLE sigint_event;
    function.  */
 struct async_signal_handler *sigint_handler;
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string.
-
-   The Windows runtime implementation of strerror never returns NULL,
-   but does return a useless string for anything above sys_nerr;
-   unfortunately this includes all socket-related error codes.
-   This replacement tries to find a system-provided error message.  */
-
-char *
-safe_strerror (int errnum)
-{
-  static char *buffer;
-  int len;
-
-  if (errnum >= 0 && errnum < sys_nerr)
-    return strerror (errnum);
-
-  if (buffer)
-    {
-      LocalFree (buffer);
-      buffer = NULL;
-    }
-
-  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
-		     | FORMAT_MESSAGE_FROM_SYSTEM,
-		     NULL, errnum,
-		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-		     (LPTSTR) &buffer, 0, NULL) == 0)
-    {
-      static char buf[32];
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      return buf;
-    }
-
-  /* Windows error messages end with a period and a CR-LF; strip that
-     out.  */
-  len = strlen (buffer);
-  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
-    buffer[len - 3] = '\0';
-
-  return buffer;
-}
-
 /* Return an absolute file name of the running GDB, if possible, or
    ARGV0 if not.  The return value is in malloc'ed storage.  */
 
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c
index 13cddba..fef5ec1 100644
--- a/gdb/posix-hdep.c
+++ b/gdb/posix-hdep.c
@@ -22,26 +22,6 @@
 
 #include "gdb_select.h"
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string.  */
-
-char *
-safe_strerror (int errnum)
-{
-  char *msg;
-
-  msg = strerror (errnum);
-  if (msg == NULL)
-    {
-      static char buf[32];
-
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      msg = buf;
-    }
-  return (msg);
-}
-
 /* Wrapper for select.  Nothing special needed on POSIX platforms.  */
 
 int
diff --git a/gdb/utils.h b/gdb/utils.h
index 3debde7..e58260c 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -42,9 +42,6 @@ ULONGEST strtoulst (const char *num, const char **trailer, int base);
 int compare_positive_ints (const void *ap, const void *bp);
 int compare_strings (const void *ap, const void *bp);
 
-/* This is defined in *-hdep.c, e.g., posix-hdep.c.  */
-extern char *safe_strerror (int);
-
 /* A wrapper for bfd_errmsg to produce a more helpful error message
    in the case of bfd_error_file_ambiguously recognized.
    MATCHING, if non-NULL, is the corresponding argument to
-- 
1.9.3

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-09 22:19 [PATCH 0/2] Share code to disable ASR between GDB and gdbserver Sergio Durigan Junior
@ 2015-01-09 22:19 ` Sergio Durigan Junior
  2015-01-13 17:11   ` Pedro Alves
  2015-01-16 15:39   ` Ulrich Weigand
  2015-01-09 22:19 ` [PATCH 1/2] Move safe_strerror to common/ Sergio Durigan Junior
  1 sibling, 2 replies; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-09 22:19 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Gary Benson, Sergio Durigan Junior

This patch moves the shared code present on
gdb/linux-nat.c:linux_nat_create_inferior and
gdb/gdbserver/linux-low.c:linux_create_inferior to
nat/linux-personality.c.  This code is responsible for disabling
address space randomization based on user setting, and using
<sys/personality.h> to do that.  I decided to put the prototype of the
maybe_disable_address_space_randomization on nat/linux-osdata.h
because it seemed the best place to put it.

I regression-tested this patch on Fedora 20 x86_64, and found no
regressions.

gdb/ChangeLog
2015-01-09  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (linux-personality.o): New rule.
	* common/common-defs.h: Include <stdint.h>.
	* config/aarch64/linux.mh (NATDEPFILES): Include
	linux-personality.o.
	* config/alpha/alpha-linux.mh (NATDEPFILES): Likewise.
	* config/arm/linux.mh (NATDEPFILES): Likewise.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* config/i386/linux.mh (NATDEPFILES): Likewise.
	* config/ia64/linux.mh (NATDEPFILES): Likewise.
	* config/m32r/linux.mh (NATDEPFILES): Likewise.
	* config/m68k/linux.mh (NATDEPFILES): Likewise.
	* config/mips/linux.mh (NATDEPFILES): Likewise.
	* config/pa/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/spu-linux.mh (NATDEPFILES): Likewise.
	* config/s390/linux.mh (NATDEPFILES): Likewise.
	* config/sparc/linux64.mh (NATDEPFILES): Likewise.
	* config/sparc/linux.mh (NATDEPFILES): Likewise.
	* config/tilegx/linux.mh (NATDEPFILES): Likewise.
	* config/xtensa/linux.mh (NATDEPFILES): Likewise.
	* defs.h: Remove #include <stdint.h> (moved to
	common/common-defs.h).
	* linux-nat.c: Remove #include <sys/personality.h>; do not define
	ADDR_NO_RANDOMIZE (moved to nat/linux-personality.c).
	(linux_nat_create_inferior): Remove code to disable address space
	randomization (moved to nat/linux-personality.c).  Create cleanup
	to disable address space randomization.
	* nat/linux-osdata.h (maybe_disable_address_space_randomization):
	New prototype.
	* nat/linux-personality.c: New file.

gdb/gdbserver/ChangeLog
2015-01-09  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SFILES): Add linux-personality.c.
	(linux-personality.o): New rule.
	* configure.srv (srv_linux_obj): Add linux-personality.o to the
	list of objects to be built.
	* linux-low.c (linux_create_inferior): Remove code to disable
	address space randomization (moved to ../nat/linux-personality.c).
	Create cleanup to disable address space randomization.
---
 gdb/Makefile.in                   |  4 ++
 gdb/common/common-defs.h          |  1 +
 gdb/config/aarch64/linux.mh       |  3 +-
 gdb/config/alpha/alpha-linux.mh   |  2 +-
 gdb/config/arm/linux.mh           |  2 +-
 gdb/config/i386/linux.mh          |  2 +-
 gdb/config/i386/linux64.mh        |  2 +-
 gdb/config/ia64/linux.mh          |  1 +
 gdb/config/m32r/linux.mh          |  2 +-
 gdb/config/m68k/linux.mh          |  1 +
 gdb/config/mips/linux.mh          |  1 +
 gdb/config/pa/linux.mh            |  3 +-
 gdb/config/powerpc/linux.mh       |  2 +-
 gdb/config/powerpc/ppc64-linux.mh |  1 +
 gdb/config/powerpc/spu-linux.mh   |  2 +-
 gdb/config/s390/linux.mh          |  1 +
 gdb/config/sparc/linux.mh         |  3 +-
 gdb/config/sparc/linux64.mh       |  3 +-
 gdb/config/tilegx/linux.mh        |  3 +-
 gdb/config/xtensa/linux.mh        |  2 +-
 gdb/defs.h                        |  1 -
 gdb/gdbserver/Makefile.in         |  4 ++
 gdb/gdbserver/configure.srv       |  2 +-
 gdb/gdbserver/linux-low.c         | 33 ++--------------
 gdb/linux-nat.c                   | 40 ++-----------------
 gdb/nat/linux-osdata.h            |  2 +
 gdb/nat/linux-personality.c       | 81 +++++++++++++++++++++++++++++++++++++++
 27 files changed, 122 insertions(+), 82 deletions(-)
 create mode 100644 gdb/nat/linux-personality.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index a8bae82..4245e01 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2279,6 +2279,10 @@ mips-linux-watch.o: ${srcdir}/nat/mips-linux-watch.c
 	$(COMPILE) $(srcdir)/nat/mips-linux-watch.c
 	$(POSTCOMPILE)
 
+linux-personality.o: ${srcdir}/nat/linux-personality.c
+	$(COMPILE) $(srcdir)/nat/linux-personality.c
+	$(POSTCOMPILE)
+
 #
 # gdb/tui/ dependencies
 #
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 1873211..e80d332 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <string.h>
 #include <errno.h>
 #include <alloca.h>
diff --git a/gdb/config/aarch64/linux.mh b/gdb/config/aarch64/linux.mh
index af04f46..7f96e4d 100644
--- a/gdb/config/aarch64/linux.mh
+++ b/gdb/config/aarch64/linux.mh
@@ -21,7 +21,8 @@
 NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o aarch64-linux-nat.o \
 	proc-service.o linux-thread-db.o linux-nat.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-osdata.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-osdata.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/alpha/alpha-linux.mh b/gdb/config/alpha/alpha-linux.mh
index 81819a1..2ea02a1 100644
--- a/gdb/config/alpha/alpha-linux.mh
+++ b/gdb/config/alpha/alpha-linux.mh
@@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o alpha-linux-nat.o \
 	fork-child.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/arm/linux.mh b/gdb/config/arm/linux.mh
index 63c3eae..549bf42 100644
--- a/gdb/config/arm/linux.mh
+++ b/gdb/config/arm/linux.mh
@@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o arm-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh
index a4e4842..33fb281 100644
--- a/gdb/config/i386/linux.mh
+++ b/gdb/config/i386/linux.mh
@@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	x86-nat.o x86-dregs.o i386-linux-nat.o x86-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-btrace.o linux-waitpid.o
+	linux-btrace.o linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh
index d557202..d52eb52 100644
--- a/gdb/config/i386/linux64.mh
+++ b/gdb/config/i386/linux64.mh
@@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	linux-nat.o linux-osdata.o \
 	proc-service.o linux-thread-db.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-btrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_FILE= config/nm-linux.h
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/ia64/linux.mh b/gdb/config/ia64/linux.mh
index baa8709..9dce22b 100644
--- a/gdb/config/ia64/linux.mh
+++ b/gdb/config/ia64/linux.mh
@@ -5,6 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	ia64-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
+	linux-personality.o \
 	linux-procfs.o linux-ptrace.o linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/m32r/linux.mh b/gdb/config/m32r/linux.mh
index e9bb82c..6b810e6 100644
--- a/gdb/config/m32r/linux.mh
+++ b/gdb/config/m32r/linux.mh
@@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o				\
 	m32r-linux-nat.o proc-service.o linux-thread-db.o	\
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/m68k/linux.mh b/gdb/config/m68k/linux.mh
index bcec295..f3b3baa 100644
--- a/gdb/config/m68k/linux.mh
+++ b/gdb/config/m68k/linux.mh
@@ -5,6 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	m68klinux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/mips/linux.mh b/gdb/config/mips/linux.mh
index 021838e..d6a802f 100644
--- a/gdb/config/mips/linux.mh
+++ b/gdb/config/mips/linux.mh
@@ -4,6 +4,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o mips-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o \
 	mips-linux-watch.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/pa/linux.mh b/gdb/config/pa/linux.mh
index f1c0c32..9539b64 100644
--- a/gdb/config/pa/linux.mh
+++ b/gdb/config/pa/linux.mh
@@ -3,7 +3,8 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	hppa-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/powerpc/linux.mh b/gdb/config/powerpc/linux.mh
index a807d3f..76e62c0 100644
--- a/gdb/config/powerpc/linux.mh
+++ b/gdb/config/powerpc/linux.mh
@@ -6,7 +6,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	ppc-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/powerpc/ppc64-linux.mh b/gdb/config/powerpc/ppc64-linux.mh
index 4b91408..a050d8b 100644
--- a/gdb/config/powerpc/ppc64-linux.mh
+++ b/gdb/config/powerpc/ppc64-linux.mh
@@ -6,6 +6,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	ppc-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/powerpc/spu-linux.mh b/gdb/config/powerpc/spu-linux.mh
index 7ce7a5f..d44aeeb 100644
--- a/gdb/config/powerpc/spu-linux.mh
+++ b/gdb/config/powerpc/spu-linux.mh
@@ -4,5 +4,5 @@
 # PPU side of the Cell BE and debugging the SPU side.
 
 NATDEPFILES = spu-linux-nat.o fork-child.o inf-ptrace.o \
-	      linux-procfs.o linux-ptrace.o linux-waitpid.o
+	      linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o
 
diff --git a/gdb/config/s390/linux.mh b/gdb/config/s390/linux.mh
index 59bab83..e1ad899 100644
--- a/gdb/config/s390/linux.mh
+++ b/gdb/config/s390/linux.mh
@@ -3,6 +3,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o s390-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/sparc/linux.mh b/gdb/config/sparc/linux.mh
index 009ea95..bd7fc86 100644
--- a/gdb/config/sparc/linux.mh
+++ b/gdb/config/sparc/linux.mh
@@ -4,7 +4,8 @@ NATDEPFILES= sparc-nat.o sparc-linux-nat.o \
 	fork-child.o inf-ptrace.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/sparc/linux64.mh b/gdb/config/sparc/linux64.mh
index aad77c7..86f984f 100644
--- a/gdb/config/sparc/linux64.mh
+++ b/gdb/config/sparc/linux64.mh
@@ -4,7 +4,8 @@ NATDEPFILES= sparc-nat.o sparc64-nat.o sparc64-linux-nat.o \
 	fork-child.o inf-ptrace.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/tilegx/linux.mh b/gdb/config/tilegx/linux.mh
index 1ed9c33..b5edcd4 100644
--- a/gdb/config/tilegx/linux.mh
+++ b/gdb/config/tilegx/linux.mh
@@ -5,7 +5,8 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	tilegx-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 
 # The dynamically loaded libthread_db needs access to symbols in the
 # gdb executable.
diff --git a/gdb/config/xtensa/linux.mh b/gdb/config/xtensa/linux.mh
index 8ef84b4..b4e59b3 100644
--- a/gdb/config/xtensa/linux.mh
+++ b/gdb/config/xtensa/linux.mh
@@ -5,7 +5,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o xtensa-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/defs.h b/gdb/defs.h
index 99db465..a1cd45f 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 #include <limits.h>
-#include <stdint.h>
 
 /* The libdecnumber library, on which GDB depends, includes a header file
    called gstdint.h instead of relying directly on stdint.h.  GDB, on the
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index f05f450..75798ec 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -167,6 +167,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/common/vec.c $(srcdir)/common/gdb_vecs.c \
 	$(srcdir)/common/common-utils.c $(srcdir)/common/xml-utils.c \
 	$(srcdir)/nat/linux-osdata.c $(srcdir)/common/ptid.c \
+	$(srcdir)/nat/linux-personality.c \
 	$(srcdir)/common/buffer.c $(srcdir)/nat/linux-btrace.c \
 	$(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
 	$(srcdir)/nat/mips-linux-watch.c $(srcdir)/common/print-utils.c \
@@ -587,6 +588,9 @@ linux-waitpid.o: ../nat/linux-waitpid.c
 mips-linux-watch.o: ../nat/mips-linux-watch.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+linux-personality.o: ../nat/linux-personality.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 
 aarch64.c : $(srcdir)/../regformats/aarch64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/aarch64.dat aarch64.c
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 679fc9f..0d48ddd 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -42,7 +42,7 @@ srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd
 
 # Linux object files.  This is so we don't have to repeat
 # these files over and over again.
-srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o"
+srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o"
 
 # Input is taken from the "${target}" variable.
 
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 4d19c87..0ebb87a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -597,29 +597,11 @@ add_lwp (ptid_t ptid)
 static int
 linux_create_inferior (char *program, char **allargs)
 {
-#ifdef HAVE_PERSONALITY
-  int personality_orig = 0, personality_set = 0;
-#endif
   struct lwp_info *new_lwp;
   int pid;
   ptid_t ptid;
-
-#ifdef HAVE_PERSONALITY
-  if (disable_randomization)
-    {
-      errno = 0;
-      personality_orig = personality (0xffffffff);
-      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
-	{
-	  personality_set = 1;
-	  personality (personality_orig | ADDR_NO_RANDOMIZE);
-	}
-      if (errno != 0 || (personality_set
-			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
-	warning ("Error disabling address space randomization: %s",
-		 strerror (errno));
-    }
-#endif
+  struct cleanup *restore_personality
+    = maybe_disable_address_space_randomization (disable_randomization);
 
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)
   pid = vfork ();
@@ -665,16 +647,7 @@ linux_create_inferior (char *program, char **allargs)
       _exit (0177);
     }
 
-#ifdef HAVE_PERSONALITY
-  if (personality_set)
-    {
-      errno = 0;
-      personality (personality_orig);
-      if (errno != 0)
-	warning ("Error restoring address space randomization: %s",
-		 strerror (errno));
-    }
-#endif
+  do_cleanups (restore_personality);
 
   linux_add_process (pid, 0);
 
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 5f2c176b..8d45cf6 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -70,13 +70,6 @@
 #define SPUFS_MAGIC 0x23c9b64e
 #endif
 
-#ifdef HAVE_PERSONALITY
-# include <sys/personality.h>
-# if !HAVE_DECL_ADDR_NO_RANDOMIZE
-#  define ADDR_NO_RANDOMIZE 0x0040000
-# endif
-#endif /* HAVE_PERSONALITY */
-
 /* This comment documents high-level logic of this file.
 
 Waiting for events in sync mode
@@ -1103,45 +1096,18 @@ linux_nat_create_inferior (struct target_ops *ops,
 			   char *exec_file, char *allargs, char **env,
 			   int from_tty)
 {
-#ifdef HAVE_PERSONALITY
-  int personality_orig = 0, personality_set = 0;
-#endif /* HAVE_PERSONALITY */
+  struct cleanup *restore_personality
+    = maybe_disable_address_space_randomization (disable_randomization);
 
   /* The fork_child mechanism is synchronous and calls target_wait, so
      we have to mask the async mode.  */
 
-#ifdef HAVE_PERSONALITY
-  if (disable_randomization)
-    {
-      errno = 0;
-      personality_orig = personality (0xffffffff);
-      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
-	{
-	  personality_set = 1;
-	  personality (personality_orig | ADDR_NO_RANDOMIZE);
-	}
-      if (errno != 0 || (personality_set
-			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
-	warning (_("Error disabling address space randomization: %s"),
-		 safe_strerror (errno));
-    }
-#endif /* HAVE_PERSONALITY */
-
   /* Make sure we report all signals during startup.  */
   linux_nat_pass_signals (ops, 0, NULL);
 
   linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
 
-#ifdef HAVE_PERSONALITY
-  if (personality_set)
-    {
-      errno = 0;
-      personality (personality_orig);
-      if (errno != 0)
-	warning (_("Error restoring address space randomization: %s"),
-		 safe_strerror (errno));
-    }
-#endif /* HAVE_PERSONALITY */
+  do_cleanups (restore_personality);
 }
 
 /* Callback for linux_proc_attach_tgid_threads.  Attach to PTID if not
diff --git a/gdb/nat/linux-osdata.h b/gdb/nat/linux-osdata.h
index db8b445..ff501a2 100644
--- a/gdb/nat/linux-osdata.h
+++ b/gdb/nat/linux-osdata.h
@@ -24,4 +24,6 @@ extern int linux_common_core_of_thread (ptid_t ptid);
 extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf,
 					 ULONGEST offset, ULONGEST len);
 
+extern struct cleanup *maybe_disable_address_space_randomization (int disable_randomization);
+
 #endif
diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c
new file mode 100644
index 0000000..4b0349f
--- /dev/null
+++ b/gdb/nat/linux-personality.c
@@ -0,0 +1,81 @@
+/* Disable address space randomization based on inferior personality.
+
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "nat/linux-osdata.h"
+
+#ifdef HAVE_PERSONALITY
+# include <sys/personality.h>
+# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE
+#  define ADDR_NO_RANDOMIZE 0x0040000
+# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
+#endif /* HAVE_PERSONALITY */
+
+#ifdef HAVE_PERSONALITY
+static void
+restore_personality (void *arg)
+{
+  int personality_orig = (int) (uintptr_t) arg;
+
+  errno = 0;
+  personality (personality_orig);
+  if (errno != 0)
+    warning ("Error restoring address space randomization: %s",
+	     strerror (errno));
+}
+#endif /* HAVE_PERSONALITY */
+
+static struct cleanup *
+make_disable_asr_cleanup (int personality_set, int personality_orig)
+{
+#ifdef HAVE_PERSONALITY
+  if (personality_set != 0)
+    return make_cleanup (restore_personality,
+			 (void *) (uintptr_t) personality_orig);
+#endif /* HAVE_PERSONALITY */
+
+  return make_cleanup (null_cleanup, NULL);
+}
+
+struct cleanup *
+maybe_disable_address_space_randomization (int disable_randomization)
+{
+  int personality_orig = 0;
+  int personality_set = 0;
+
+#ifdef HAVE_PERSONALITY
+  if (disable_randomization)
+    {
+      errno = 0;
+      personality_orig = personality (0xffffffff);
+      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
+	{
+	  personality_set = 1;
+	  personality (personality_orig | ADDR_NO_RANDOMIZE);
+	}
+      if (errno != 0 || (personality_set
+			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
+	warning ("Error disabling address space randomization: %s",
+		 safe_strerror (errno));
+    }
+#endif /* HAVE_PERSONALITY */
+
+  return make_disable_asr_cleanup (personality_set,
+				   personality_orig);
+}
-- 
1.9.3

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/2] Move safe_strerror to common/
  2015-01-09 22:19 ` [PATCH 1/2] Move safe_strerror to common/ Sergio Durigan Junior
@ 2015-01-13 16:54   ` Pedro Alves
  2015-01-13 20:48     ` Sergio Durigan Junior
  0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2015-01-13 16:54 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Gary Benson

On 01/09/2015 10:19 PM, Sergio Durigan Junior wrote:
> This patch moves safe_strerror from the gdb/{posix,mingw}-hdep.c files
> to the respective common/{posix,mingw}-strerror.c files.  This is a
> preparation for the next patch, which shares a common code (to disable
> address space randomization when creating a new inferior).
> 
> The patch has been regtested on Fedora 20 x86_64, and no regressions
> were found.  I am assuming the MingW modifications are also safe, but
> I have not checked them too deep.

Note, it's "MinGW", capital G.  There are instances in the patch of the typo.

> 


> --- /dev/null
> +++ b/gdb/common/common.host
> @@ -0,0 +1,17 @@
> +# Mapping of configurations into GDB host definitions.  This is
> +# invoked from the autoconf generated configure script.

Copyright header missing.  I don't know why configure.host
doesn't have one.  Seems like an oversight.

> +
> +# This file sets the following shell variables:
> +#  gdb_host_obs			host-specific .o files to include when building GDB
> +#  srv_host_obs			likewise, but when building gdbserver
> +
> +case "${host}" in
> +
> +i[34567]86-*-mingw32*)	gdb_host_obs="mingw-hdep.o mingw-strerror.o"
> +			srv_host_obs="mingw-strerror.o"
> +			;;
> +x86_64-*-mingw*)        gdb_host_obs="mingw-hdep.o mingw-strerror.o"
> +			srv_host_obs="mingw-strerror.o"
> +			;;

You can merge those two cases.  Let's leave gdb-specific details in gdb proper, etc.
That is, make this file set a common-specific variable, like:

 case "${host}" in

 *-mingw*)	common_host_obs=mingw-strerror.o
 		;;
 *)
 		common_host_obs=posix-strerror.o
 		;;
 ecas

And then in configure.ac, do:

 . $srcdir/common/common.host
 gdb_host_obs=$gdb_host_obs $common_host_obs

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-09 22:19 ` [PATCH 2/2] Move code to disable ASR to nat/ Sergio Durigan Junior
@ 2015-01-13 17:11   ` Pedro Alves
  2015-01-13 20:55     ` Sergio Durigan Junior
  2015-01-16 15:39   ` Ulrich Weigand
  1 sibling, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2015-01-13 17:11 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Gary Benson

Hi Sergio,

Thanks.

On 01/09/2015 10:19 PM, Sergio Durigan Junior wrote:
> This patch moves the shared code present on
> gdb/linux-nat.c:linux_nat_create_inferior and
> gdb/gdbserver/linux-low.c:linux_create_inferior to
> nat/linux-personality.c.  This code is responsible for disabling
> address space randomization based on user setting, and using
> <sys/personality.h> to do that.  I decided to put the prototype of the
> maybe_disable_address_space_randomization on nat/linux-osdata.h
> because it seemed the best place to put it.

linux-osdata.h/linux-osdata.c are specifically about TARGET_OBJECT_OSDATA.

How about adding a matching nat/linux-personality.h file?

> --- a/gdb/nat/linux-osdata.h
> +++ b/gdb/nat/linux-osdata.h
> @@ -24,4 +24,6 @@ extern int linux_common_core_of_thread (ptid_t ptid);
>  extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf,
>  					 ULONGEST offset, ULONGEST len);
>  
> +extern struct cleanup *maybe_disable_address_space_randomization (int disable_randomization);

Line too long.  Write:

extern struct cleanup *maybe_disable_address_space_randomization
  (int disable_randomization);

> +	warning ("Error disabling address space randomization: %s",
> +		 safe_strerror (errno));

i18n.  The GDB version had it.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/2] Move safe_strerror to common/
  2015-01-13 16:54   ` Pedro Alves
@ 2015-01-13 20:48     ` Sergio Durigan Junior
  2015-01-14 11:26       ` Pedro Alves
  0 siblings, 1 reply; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-13 20:48 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Gary Benson

On Tuesday, January 13 2015, Pedro Alves wrote:

> On 01/09/2015 10:19 PM, Sergio Durigan Junior wrote:
>> This patch moves safe_strerror from the gdb/{posix,mingw}-hdep.c files
>> to the respective common/{posix,mingw}-strerror.c files.  This is a
>> preparation for the next patch, which shares a common code (to disable
>> address space randomization when creating a new inferior).
>> 
>> The patch has been regtested on Fedora 20 x86_64, and no regressions
>> were found.  I am assuming the MingW modifications are also safe, but
>> I have not checked them too deep.
>
> Note, it's "MinGW", capital G.  There are instances in the patch of the typo.

Ops, thanks.  Fixed.

>> --- /dev/null
>> +++ b/gdb/common/common.host
>> @@ -0,0 +1,17 @@
>> +# Mapping of configurations into GDB host definitions.  This is
>> +# invoked from the autoconf generated configure script.
>
> Copyright header missing.  I don't know why configure.host
> doesn't have one.  Seems like an oversight.

Yeah, it was just a copy and paste of gdb/configure.host.  Fixed.

>> +
>> +# This file sets the following shell variables:
>> +#  gdb_host_obs			host-specific .o files to include when building GDB
>> +#  srv_host_obs			likewise, but when building gdbserver
>> +
>> +case "${host}" in
>> +
>> +i[34567]86-*-mingw32*)	gdb_host_obs="mingw-hdep.o mingw-strerror.o"
>> +			srv_host_obs="mingw-strerror.o"
>> +			;;
>> +x86_64-*-mingw*)        gdb_host_obs="mingw-hdep.o mingw-strerror.o"
>> +			srv_host_obs="mingw-strerror.o"
>> +			;;
>
> You can merge those two cases.  Let's leave gdb-specific details in gdb proper, etc.
> That is, make this file set a common-specific variable, like:
>
>  case "${host}" in
>
>  *-mingw*)	common_host_obs=mingw-strerror.o
>  		;;
>  *)
>  		common_host_obs=posix-strerror.o
>  		;;
>  ecas
>
> And then in configure.ac, do:
>
>  . $srcdir/common/common.host
>  gdb_host_obs=$gdb_host_obs $common_host_obs

Hm, right.  Fixed.

Here's the updated patch.

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

gdb/ChangeLog
2015-01-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (ALLDEPFILES): Including common/mingw-strerror.c and
	common/posix-strerror.c.
	(posix-strerror.o): New rule.
	(mingw-strerror.o): Likewise.
	* common/common-utils.h (safe_strerror): Move prototype to here,
	from utils.h.
	* common/common.host: New file.
	* common/mingw-strerror.c: Likewise.
	* common/posix-strerror.c: Likewise.
	* configure: Regenerated.
	* configure.ac: Add posix-strerror.o to the $gdb_host_obs
	variable.  Source common/common.host.
	* configure.host: Remove variable gdb_host_obs (moved to
	common/common.host).
	* contrib/ari/gdb_ari.sh: Mention gdb/common/mingw-strerror.c and
	gdb/common/posix-strerror.c when warning about the use of
	strerror.
	* mingw-hdep.c (safe_strerror): Remove definition; move it to
	common/mingw-strerror.c.
	* posix-hdep.c (safe_strerror): Remove definition; move it to
	common/posix-hdep.c.
	* utils.h (safe_strerror): Remove prototype; move to
	common/common-utils.h.

gdb/gdbserver/ChangeLog
2015-01-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* configure: Regenerated.
	* configure.ac: Initialize new variable $srv_host_obs.  Source
	file ../common/common.host.  Add $srv_host_obs to GDBSERVER_DEPFILES.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 86ab1be..f0703d0 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1680,7 +1680,7 @@ ALLDEPFILES = \
 	m68klinux-nat.c m68klinux-tdep.c \
 	m88k-tdep.c m88kbsd-nat.c \
 	microblaze-tdep.c microblaze-linux-tdep.c \
-	mingw-hdep.c \
+	mingw-hdep.c common/mingw-strerror.c \
 	mips-linux-nat.c mips-linux-tdep.c \
 	mips-sde-tdep.c \
 	mips-tdep.c \
@@ -1690,7 +1690,7 @@ ALLDEPFILES = \
 	nios2-tdep.c nios2-linux-tdep.c \
 	nbsd-nat.c nbsd-tdep.c obsd-nat.c obsd-tdep.c \
 	somread.c solib-som.c \
-	posix-hdep.c \
+	posix-hdep.c common/posix-strerror.c \
 	ppc-sysv-tdep.c ppc-linux-nat.c ppc-linux-tdep.c ppc64-tdep.c \
 	ppcfbsd-nat.c ppcfbsd-tdep.c \
 	ppcnbsd-nat.c ppcnbsd-tdep.c \
@@ -2227,6 +2227,14 @@ common-exceptions.o: ${srcdir}/common/common-exceptions.c
 	$(COMPILE) $(srcdir)/common/common-exceptions.c
 	$(POSTCOMPILE)
 
+posix-strerror.o: ${srcdir}/common/posix-strerror.c
+	$(COMPILE) $(srcdir)/common/posix-strerror.c
+	$(POSTCOMPILE)
+
+mingw-strerror.o: ${srcdir}/common/mingw-strerror.c
+	$(COMPILE) $(srcdir)/common/mingw-strerror.c
+	$(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index f110924..60aa030 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -62,4 +62,10 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
 
 char *savestring (const char *ptr, size_t len);
 
+/* The strerror() function can return NULL for errno values that are
+   out of range.  Provide a "safe" version that always returns a
+   printable string.  */
+
+extern char *safe_strerror (int);
+
 #endif
diff --git a/gdb/common/common.host b/gdb/common/common.host
new file mode 100644
index 0000000..1c3374a
--- /dev/null
+++ b/gdb/common/common.host
@@ -0,0 +1,35 @@
+# Common object files to include for each host.
+#
+# Copyright (C) 2015 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Mapping of configurations into GDB host definitions.  This is
+# invoked from the autoconf generated configure script.
+
+# This file sets the following shell variables:
+#  gdb_host_obs			host-specific .o files to include when building GDB
+#  srv_host_obs			likewise, but when building gdbserver
+
+case "${host}" in
+
+*-mingw*)	common_host_obs=mingw-strerror.o
+		;;
+*)
+		common_host_obs=posix-strerror.o
+		;;
+
+esac
diff --git a/gdb/common/mingw-strerror.c b/gdb/common/mingw-strerror.c
new file mode 100644
index 0000000..c62c42d
--- /dev/null
+++ b/gdb/common/mingw-strerror.c
@@ -0,0 +1,64 @@
+/* Safe version of strerror for MinGW, for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+#include <windows.h>
+
+/* Implementation of safe_strerror as defined in common-utils.h.
+
+   The Windows runtime implementation of strerror never returns NULL,
+   but does return a useless string for anything above sys_nerr;
+   unfortunately this includes all socket-related error codes.
+   This replacement tries to find a system-provided error message.  */
+
+char *
+safe_strerror (int errnum)
+{
+  static char *buffer;
+  int len;
+
+  if (errnum >= 0 && errnum < sys_nerr)
+    return strerror (errnum);
+
+  if (buffer)
+    {
+      LocalFree (buffer);
+      buffer = NULL;
+    }
+
+  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+		     | FORMAT_MESSAGE_FROM_SYSTEM,
+		     NULL, errnum,
+		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+		     (LPTSTR) &buffer, 0, NULL) == 0)
+    {
+      static char buf[32];
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      return buf;
+    }
+
+  /* Windows error messages end with a period and a CR-LF; strip that
+     out.  */
+  len = strlen (buffer);
+  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
+    buffer[len - 3] = '\0';
+
+  return buffer;
+}
diff --git a/gdb/common/posix-strerror.c b/gdb/common/posix-strerror.c
new file mode 100644
index 0000000..119fcf6
--- /dev/null
+++ b/gdb/common/posix-strerror.c
@@ -0,0 +1,38 @@
+/* Safe version of strerror for POSIX systems for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+/* Implementation of safe_strerror as defined in common-utils.h.  */
+
+char *
+safe_strerror (int errnum)
+{
+  char *msg;
+
+  msg = strerror (errnum);
+  if (msg == NULL)
+    {
+      static char buf[32];
+
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      msg = buf;
+    }
+  return (msg);
+}
diff --git a/gdb/configure b/gdb/configure
index 7ff74ba..ae2a5f3 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -5298,7 +5298,7 @@ fi
 
 # Provide defaults for some variables set by the per-host and per-target
 # configuration.
-gdb_host_obs=posix-hdep.o
+gdb_host_obs="posix-hdep.o"
 
 if test "${target}" = "${host}"; then
   gdb_native=yes
@@ -5307,6 +5307,9 @@ else
 fi
 
 . $srcdir/configure.host
+. $srcdir/common/common.host
+
+gdb_host_obs="$gdb_host_obs $common_host_obs"
 
 # Accumulate some settings from configure.tgt over all enabled targets
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index ec776d7..7812ec6 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -195,7 +195,7 @@ esac],[want64=false])dnl
 
 # Provide defaults for some variables set by the per-host and per-target
 # configuration.
-gdb_host_obs=posix-hdep.o
+gdb_host_obs="posix-hdep.o"
 
 if test "${target}" = "${host}"; then
   gdb_native=yes
@@ -204,6 +204,9 @@ else
 fi
 
 . $srcdir/configure.host
+. $srcdir/common/common.host
+
+gdb_host_obs="$gdb_host_obs $common_host_obs"
 
 # Accumulate some settings from configure.tgt over all enabled targets
 
diff --git a/gdb/configure.host b/gdb/configure.host
index d07be4b..9f8a917 100644
--- a/gdb/configure.host
+++ b/gdb/configure.host
@@ -7,7 +7,6 @@
 #  gdb_host_float_format	host's float floatformat, or 0
 #  gdb_host_double_format	host's double floatformat, or 0
 #  gdb_host_long_double_format	host's long double floatformat, or 0
-#  gdb_host_obs			host-specific .o files to include
 
 # Map host cpu into the config cpu subdirectory name.
 # The default is $host_cpu.
@@ -105,7 +104,6 @@ i[34567]86-*-netbsdelf* | i[34567]86-*-knetbsd*-gnu)
 			gdb_host=nbsdelf ;;
 i[34567]86-*-go32*)	gdb_host=go32 ;;
 i[34567]86-*-mingw32*)	gdb_host=mingw
-			gdb_host_obs=mingw-hdep.o
 			;;
 i[34567]86-*-msdosdjgpp*) gdb_host=go32 ;;
 i[34567]86-*-linux*)	gdb_host=linux ;;
@@ -181,7 +179,6 @@ x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
 			gdb_host=nbsd64 ;;
 x86_64-*-openbsd*)	gdb_host=obsd64 ;;
 x86_64-*-mingw*)        gdb_host=mingw64
-			gdb_host_obs=mingw-hdep.o
 			;;
 x86_64-*-cygwin*)	gdb_host=cygwin64 ;;
 m32r*-*-linux*)          gdb_host=linux ;;
diff --git a/gdb/contrib/ari/gdb_ari.sh b/gdb/contrib/ari/gdb_ari.sh
index 8a8cec8..b868a17 100644
--- a/gdb/contrib/ari/gdb_ari.sh
+++ b/gdb/contrib/ari/gdb_ari.sh
@@ -603,8 +603,8 @@ BEGIN { doc["strerror"] = "\
 Do not use strerror(), instead use safe_strerror()"
     category["strerror"] = ari_regression
     fix("strerror", "gdb/gdb_string.h", 1)
-    fix("strerror", "gdb/mingw-hdep.c", 1)
-    fix("strerror", "gdb/posix-hdep.c", 1)
+    fix("strerror", "gdb/common/mingw-strerror.c", 1)
+    fix("strerror", "gdb/common/posix-strerror.c", 1)
 }
 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
     fail("strerror")
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 1ed2ec8..f05f450 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -518,6 +518,12 @@ rsp-low.o: ../common/rsp-low.c
 common-utils.o: ../common/common-utils.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+posix-strerror.o: ../common/posix-strerror.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+mingw-strerror.o: ../common/mingw-strerror.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 vec.o: ../common/vec.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 45efc51..8479283 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -5537,7 +5537,14 @@ $as_echo "$gdb_cv_m68k_is_coldfire" >&6; }
     ;;
 esac
 
+# Initialize as POSIX.  This will change if the host is MinGW.
+
+srv_host_obs=""
+
 . ${srcdir}/configure.srv
+. ${srcdir}/../common/common.host
+
+srv_host_obs="$srv_host_obs $common_host_obs"
 
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
@@ -6034,7 +6041,7 @@ $as_echo "#define USE_XML 1" >>confdefs.h
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports __sync_*_compare_and_swap" >&5
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 02082cc..8252f4b 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -240,7 +240,14 @@ got it
     ;;
 esac
 
+# Initialize as POSIX.  This will change if the host is MinGW.
+
+srv_host_obs=""
+
 . ${srcdir}/configure.srv
+. ${srcdir}/../common/common.host
+
+srv_host_obs="$srv_host_obs $common_host_obs"
 
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
@@ -385,7 +392,7 @@ if test "$srv_xmlfiles" != ""; then
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 dnl Check whether the target supports __sync_*_compare_and_swap.
diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c
index c0cc385..a0ed281 100644
--- a/gdb/mingw-hdep.c
+++ b/gdb/mingw-hdep.c
@@ -35,50 +35,6 @@ static HANDLE sigint_event;
    function.  */
 struct async_signal_handler *sigint_handler;
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string.
-
-   The Windows runtime implementation of strerror never returns NULL,
-   but does return a useless string for anything above sys_nerr;
-   unfortunately this includes all socket-related error codes.
-   This replacement tries to find a system-provided error message.  */
-
-char *
-safe_strerror (int errnum)
-{
-  static char *buffer;
-  int len;
-
-  if (errnum >= 0 && errnum < sys_nerr)
-    return strerror (errnum);
-
-  if (buffer)
-    {
-      LocalFree (buffer);
-      buffer = NULL;
-    }
-
-  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
-		     | FORMAT_MESSAGE_FROM_SYSTEM,
-		     NULL, errnum,
-		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-		     (LPTSTR) &buffer, 0, NULL) == 0)
-    {
-      static char buf[32];
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      return buf;
-    }
-
-  /* Windows error messages end with a period and a CR-LF; strip that
-     out.  */
-  len = strlen (buffer);
-  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
-    buffer[len - 3] = '\0';
-
-  return buffer;
-}
-
 /* Return an absolute file name of the running GDB, if possible, or
    ARGV0 if not.  The return value is in malloc'ed storage.  */
 
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c
index 13cddba..fef5ec1 100644
--- a/gdb/posix-hdep.c
+++ b/gdb/posix-hdep.c
@@ -22,26 +22,6 @@
 
 #include "gdb_select.h"
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string.  */
-
-char *
-safe_strerror (int errnum)
-{
-  char *msg;
-
-  msg = strerror (errnum);
-  if (msg == NULL)
-    {
-      static char buf[32];
-
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      msg = buf;
-    }
-  return (msg);
-}
-
 /* Wrapper for select.  Nothing special needed on POSIX platforms.  */
 
 int
diff --git a/gdb/utils.h b/gdb/utils.h
index 3debde7..e58260c 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -42,9 +42,6 @@ ULONGEST strtoulst (const char *num, const char **trailer, int base);
 int compare_positive_ints (const void *ap, const void *bp);
 int compare_strings (const void *ap, const void *bp);
 
-/* This is defined in *-hdep.c, e.g., posix-hdep.c.  */
-extern char *safe_strerror (int);
-
 /* A wrapper for bfd_errmsg to produce a more helpful error message
    in the case of bfd_error_file_ambiguously recognized.
    MATCHING, if non-NULL, is the corresponding argument to

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-13 17:11   ` Pedro Alves
@ 2015-01-13 20:55     ` Sergio Durigan Junior
  2015-01-14 11:32       ` Pedro Alves
  0 siblings, 1 reply; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-13 20:55 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Gary Benson

On Tuesday, January 13 2015, Pedro Alves wrote:

> Hi Sergio,
>
> Thanks.

Thanks for the review.

> On 01/09/2015 10:19 PM, Sergio Durigan Junior wrote:
>> This patch moves the shared code present on
>> gdb/linux-nat.c:linux_nat_create_inferior and
>> gdb/gdbserver/linux-low.c:linux_create_inferior to
>> nat/linux-personality.c.  This code is responsible for disabling
>> address space randomization based on user setting, and using
>> <sys/personality.h> to do that.  I decided to put the prototype of the
>> maybe_disable_address_space_randomization on nat/linux-osdata.h
>> because it seemed the best place to put it.
>
> linux-osdata.h/linux-osdata.c are specifically about TARGET_OBJECT_OSDATA.
>
> How about adding a matching nat/linux-personality.h file?

Right, did that.

>> --- a/gdb/nat/linux-osdata.h
>> +++ b/gdb/nat/linux-osdata.h
>> @@ -24,4 +24,6 @@ extern int linux_common_core_of_thread (ptid_t ptid);
>>  extern LONGEST linux_common_xfer_osdata (const char *annex, gdb_byte *readbuf,
>>  					 ULONGEST offset, ULONGEST len);
>>  
>> +extern struct cleanup *maybe_disable_address_space_randomization (int disable_randomization);
>
> Line too long.  Write:
>
> extern struct cleanup *maybe_disable_address_space_randomization
>   (int disable_randomization);

Sorry.  Fixed.

>> +	warning ("Error disabling address space randomization: %s",
>> +		 safe_strerror (errno));
>
> i18n.  The GDB version had it.

Fixed.

I also added comments to the new functions on
nat/linux-personality.[ch], and fixed a wrong use of strerror where it
should be safe_strerror.

Here's the updated patch.

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

gdb/ChangeLog
2015-01-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-personality.h.
	(linux-personality.o): New rule.
	* common/common-defs.h: Include <stdint.h>.
	* config/aarch64/linux.mh (NATDEPFILES): Include
	linux-personality.o.
	* config/alpha/alpha-linux.mh (NATDEPFILES): Likewise.
	* config/arm/linux.mh (NATDEPFILES): Likewise.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* config/i386/linux.mh (NATDEPFILES): Likewise.
	* config/ia64/linux.mh (NATDEPFILES): Likewise.
	* config/m32r/linux.mh (NATDEPFILES): Likewise.
	* config/m68k/linux.mh (NATDEPFILES): Likewise.
	* config/mips/linux.mh (NATDEPFILES): Likewise.
	* config/pa/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/spu-linux.mh (NATDEPFILES): Likewise.
	* config/s390/linux.mh (NATDEPFILES): Likewise.
	* config/sparc/linux64.mh (NATDEPFILES): Likewise.
	* config/sparc/linux.mh (NATDEPFILES): Likewise.
	* config/tilegx/linux.mh (NATDEPFILES): Likewise.
	* config/xtensa/linux.mh (NATDEPFILES): Likewise.
	* defs.h: Remove #include <stdint.h> (moved to
	common/common-defs.h).
	* linux-nat.c: Remove #include <sys/personality.h>; do not define
	ADDR_NO_RANDOMIZE (moved to nat/linux-personality.c).
	(linux_nat_create_inferior): Remove code to disable address space
	randomization (moved to nat/linux-personality.c).  Create cleanup
	to disable address space randomization.
	* nat/linux-osdata.h (maybe_disable_address_space_randomization):
	New prototype.
	* nat/linux-personality.c: New file.
	* nat/linux-personality.h: Likewise.

gdb/gdbserver/ChangeLog
2015-01-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SFILES): Add linux-personality.c.
	(linux-personality.o): New rule.
	* configure.srv (srv_linux_obj): Add linux-personality.o to the
	list of objects to be built.
	* linux-low.c: Include nat/linux-personality.h.
	(linux_create_inferior): Remove code to disable address space
	randomization (moved to ../nat/linux-personality.c).  Create
	cleanup to disable address space randomization.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f0703d0..9c33b3a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -961,7 +961,7 @@ common/print-utils.h common/rsp-low.h nat/x86-dregs.h x86-linux-nat.h \
 i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
 common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
 common/common-exceptions.h target/target.h common/symbol.h \
-common/common-regcache.h fbsd-tdep.h
+common/common-regcache.h fbsd-tdep.h nat/linux-personality.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -2278,6 +2278,10 @@ mips-linux-watch.o: ${srcdir}/nat/mips-linux-watch.c
 	$(COMPILE) $(srcdir)/nat/mips-linux-watch.c
 	$(POSTCOMPILE)
 
+linux-personality.o: ${srcdir}/nat/linux-personality.c
+	$(COMPILE) $(srcdir)/nat/linux-personality.c
+	$(POSTCOMPILE)
+
 #
 # gdb/tui/ dependencies
 #
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 1873211..e80d332 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <string.h>
 #include <errno.h>
 #include <alloca.h>
diff --git a/gdb/config/aarch64/linux.mh b/gdb/config/aarch64/linux.mh
index af04f46..7f96e4d 100644
--- a/gdb/config/aarch64/linux.mh
+++ b/gdb/config/aarch64/linux.mh
@@ -21,7 +21,8 @@
 NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o aarch64-linux-nat.o \
 	proc-service.o linux-thread-db.o linux-nat.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-osdata.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-osdata.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/alpha/alpha-linux.mh b/gdb/config/alpha/alpha-linux.mh
index 81819a1..2ea02a1 100644
--- a/gdb/config/alpha/alpha-linux.mh
+++ b/gdb/config/alpha/alpha-linux.mh
@@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o alpha-linux-nat.o \
 	fork-child.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/arm/linux.mh b/gdb/config/arm/linux.mh
index 63c3eae..549bf42 100644
--- a/gdb/config/arm/linux.mh
+++ b/gdb/config/arm/linux.mh
@@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o arm-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh
index a4e4842..33fb281 100644
--- a/gdb/config/i386/linux.mh
+++ b/gdb/config/i386/linux.mh
@@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	x86-nat.o x86-dregs.o i386-linux-nat.o x86-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-btrace.o linux-waitpid.o
+	linux-btrace.o linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh
index d557202..d52eb52 100644
--- a/gdb/config/i386/linux64.mh
+++ b/gdb/config/i386/linux64.mh
@@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	linux-nat.o linux-osdata.o \
 	proc-service.o linux-thread-db.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-btrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_FILE= config/nm-linux.h
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/ia64/linux.mh b/gdb/config/ia64/linux.mh
index baa8709..9dce22b 100644
--- a/gdb/config/ia64/linux.mh
+++ b/gdb/config/ia64/linux.mh
@@ -5,6 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	ia64-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
+	linux-personality.o \
 	linux-procfs.o linux-ptrace.o linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/m32r/linux.mh b/gdb/config/m32r/linux.mh
index e9bb82c..6b810e6 100644
--- a/gdb/config/m32r/linux.mh
+++ b/gdb/config/m32r/linux.mh
@@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o				\
 	m32r-linux-nat.o proc-service.o linux-thread-db.o	\
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/m68k/linux.mh b/gdb/config/m68k/linux.mh
index bcec295..f3b3baa 100644
--- a/gdb/config/m68k/linux.mh
+++ b/gdb/config/m68k/linux.mh
@@ -5,6 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	m68klinux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/mips/linux.mh b/gdb/config/mips/linux.mh
index 021838e..d6a802f 100644
--- a/gdb/config/mips/linux.mh
+++ b/gdb/config/mips/linux.mh
@@ -4,6 +4,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o mips-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o \
 	mips-linux-watch.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/pa/linux.mh b/gdb/config/pa/linux.mh
index f1c0c32..9539b64 100644
--- a/gdb/config/pa/linux.mh
+++ b/gdb/config/pa/linux.mh
@@ -3,7 +3,8 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	hppa-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/powerpc/linux.mh b/gdb/config/powerpc/linux.mh
index a807d3f..76e62c0 100644
--- a/gdb/config/powerpc/linux.mh
+++ b/gdb/config/powerpc/linux.mh
@@ -6,7 +6,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	ppc-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/powerpc/ppc64-linux.mh b/gdb/config/powerpc/ppc64-linux.mh
index 4b91408..a050d8b 100644
--- a/gdb/config/powerpc/ppc64-linux.mh
+++ b/gdb/config/powerpc/ppc64-linux.mh
@@ -6,6 +6,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	ppc-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/powerpc/spu-linux.mh b/gdb/config/powerpc/spu-linux.mh
index 7ce7a5f..d44aeeb 100644
--- a/gdb/config/powerpc/spu-linux.mh
+++ b/gdb/config/powerpc/spu-linux.mh
@@ -4,5 +4,5 @@
 # PPU side of the Cell BE and debugging the SPU side.
 
 NATDEPFILES = spu-linux-nat.o fork-child.o inf-ptrace.o \
-	      linux-procfs.o linux-ptrace.o linux-waitpid.o
+	      linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o
 
diff --git a/gdb/config/s390/linux.mh b/gdb/config/s390/linux.mh
index 59bab83..e1ad899 100644
--- a/gdb/config/s390/linux.mh
+++ b/gdb/config/s390/linux.mh
@@ -3,6 +3,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o s390-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/sparc/linux.mh b/gdb/config/sparc/linux.mh
index 009ea95..bd7fc86 100644
--- a/gdb/config/sparc/linux.mh
+++ b/gdb/config/sparc/linux.mh
@@ -4,7 +4,8 @@ NATDEPFILES= sparc-nat.o sparc-linux-nat.o \
 	fork-child.o inf-ptrace.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/sparc/linux64.mh b/gdb/config/sparc/linux64.mh
index aad77c7..86f984f 100644
--- a/gdb/config/sparc/linux64.mh
+++ b/gdb/config/sparc/linux64.mh
@@ -4,7 +4,8 @@ NATDEPFILES= sparc-nat.o sparc64-nat.o sparc64-linux-nat.o \
 	fork-child.o inf-ptrace.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/tilegx/linux.mh b/gdb/config/tilegx/linux.mh
index 1ed9c33..b5edcd4 100644
--- a/gdb/config/tilegx/linux.mh
+++ b/gdb/config/tilegx/linux.mh
@@ -5,7 +5,8 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	tilegx-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 
 # The dynamically loaded libthread_db needs access to symbols in the
 # gdb executable.
diff --git a/gdb/config/xtensa/linux.mh b/gdb/config/xtensa/linux.mh
index 8ef84b4..b4e59b3 100644
--- a/gdb/config/xtensa/linux.mh
+++ b/gdb/config/xtensa/linux.mh
@@ -5,7 +5,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o xtensa-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/defs.h b/gdb/defs.h
index 99db465..a1cd45f 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 #include <limits.h>
-#include <stdint.h>
 
 /* The libdecnumber library, on which GDB depends, includes a header file
    called gstdint.h instead of relying directly on stdint.h.  GDB, on the
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index f05f450..75798ec 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -167,6 +167,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/common/vec.c $(srcdir)/common/gdb_vecs.c \
 	$(srcdir)/common/common-utils.c $(srcdir)/common/xml-utils.c \
 	$(srcdir)/nat/linux-osdata.c $(srcdir)/common/ptid.c \
+	$(srcdir)/nat/linux-personality.c \
 	$(srcdir)/common/buffer.c $(srcdir)/nat/linux-btrace.c \
 	$(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
 	$(srcdir)/nat/mips-linux-watch.c $(srcdir)/common/print-utils.c \
@@ -587,6 +588,9 @@ linux-waitpid.o: ../nat/linux-waitpid.c
 mips-linux-watch.o: ../nat/mips-linux-watch.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+linux-personality.o: ../nat/linux-personality.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 
 aarch64.c : $(srcdir)/../regformats/aarch64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/aarch64.dat aarch64.c
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 679fc9f..0d48ddd 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -42,7 +42,7 @@ srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd
 
 # Linux object files.  This is so we don't have to repeat
 # these files over and over again.
-srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o"
+srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o"
 
 # Input is taken from the "${target}" variable.
 
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 4d19c87..5e37dd5 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -27,6 +27,7 @@
 #include <sys/ptrace.h>
 #include "nat/linux-ptrace.h"
 #include "nat/linux-procfs.h"
+#include "nat/linux-personality.h"
 #include <signal.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
@@ -597,29 +598,11 @@ add_lwp (ptid_t ptid)
 static int
 linux_create_inferior (char *program, char **allargs)
 {
-#ifdef HAVE_PERSONALITY
-  int personality_orig = 0, personality_set = 0;
-#endif
   struct lwp_info *new_lwp;
   int pid;
   ptid_t ptid;
-
-#ifdef HAVE_PERSONALITY
-  if (disable_randomization)
-    {
-      errno = 0;
-      personality_orig = personality (0xffffffff);
-      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
-	{
-	  personality_set = 1;
-	  personality (personality_orig | ADDR_NO_RANDOMIZE);
-	}
-      if (errno != 0 || (personality_set
-			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
-	warning ("Error disabling address space randomization: %s",
-		 strerror (errno));
-    }
-#endif
+  struct cleanup *restore_personality
+    = maybe_disable_address_space_randomization (disable_randomization);
 
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)
   pid = vfork ();
@@ -665,16 +648,7 @@ linux_create_inferior (char *program, char **allargs)
       _exit (0177);
     }
 
-#ifdef HAVE_PERSONALITY
-  if (personality_set)
-    {
-      errno = 0;
-      personality (personality_orig);
-      if (errno != 0)
-	warning ("Error restoring address space randomization: %s",
-		 strerror (errno));
-    }
-#endif
+  do_cleanups (restore_personality);
 
   linux_add_process (pid, 0);
 
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index a8a63cf..be52470 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -32,6 +32,7 @@
 #include "linux-nat.h"
 #include "nat/linux-ptrace.h"
 #include "nat/linux-procfs.h"
+#include "nat/linux-personality.h"
 #include "linux-fork.h"
 #include "gdbthread.h"
 #include "gdbcmd.h"
@@ -70,13 +71,6 @@
 #define SPUFS_MAGIC 0x23c9b64e
 #endif
 
-#ifdef HAVE_PERSONALITY
-# include <sys/personality.h>
-# if !HAVE_DECL_ADDR_NO_RANDOMIZE
-#  define ADDR_NO_RANDOMIZE 0x0040000
-# endif
-#endif /* HAVE_PERSONALITY */
-
 /* This comment documents high-level logic of this file.
 
 Waiting for events in sync mode
@@ -1103,45 +1097,18 @@ linux_nat_create_inferior (struct target_ops *ops,
 			   char *exec_file, char *allargs, char **env,
 			   int from_tty)
 {
-#ifdef HAVE_PERSONALITY
-  int personality_orig = 0, personality_set = 0;
-#endif /* HAVE_PERSONALITY */
+  struct cleanup *restore_personality
+    = maybe_disable_address_space_randomization (disable_randomization);
 
   /* The fork_child mechanism is synchronous and calls target_wait, so
      we have to mask the async mode.  */
 
-#ifdef HAVE_PERSONALITY
-  if (disable_randomization)
-    {
-      errno = 0;
-      personality_orig = personality (0xffffffff);
-      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
-	{
-	  personality_set = 1;
-	  personality (personality_orig | ADDR_NO_RANDOMIZE);
-	}
-      if (errno != 0 || (personality_set
-			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
-	warning (_("Error disabling address space randomization: %s"),
-		 safe_strerror (errno));
-    }
-#endif /* HAVE_PERSONALITY */
-
   /* Make sure we report all signals during startup.  */
   linux_nat_pass_signals (ops, 0, NULL);
 
   linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
 
-#ifdef HAVE_PERSONALITY
-  if (personality_set)
-    {
-      errno = 0;
-      personality (personality_orig);
-      if (errno != 0)
-	warning (_("Error restoring address space randomization: %s"),
-		 safe_strerror (errno));
-    }
-#endif /* HAVE_PERSONALITY */
+  do_cleanups (restore_personality);
 }
 
 /* Callback for linux_proc_attach_tgid_threads.  Attach to PTID if not
diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c
new file mode 100644
index 0000000..f61a2c6
--- /dev/null
+++ b/gdb/nat/linux-personality.c
@@ -0,0 +1,94 @@
+/* Disable address space randomization based on inferior personality.
+
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "nat/linux-personality.h"
+
+#ifdef HAVE_PERSONALITY
+# include <sys/personality.h>
+# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE
+#  define ADDR_NO_RANDOMIZE 0x0040000
+# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
+#endif /* HAVE_PERSONALITY */
+
+#ifdef HAVE_PERSONALITY
+
+/* Restore address space randomization of the inferior.  ARG is the
+   original inferior's personality value before the address space
+   randomization was disabled.  */
+
+static void
+restore_personality (void *arg)
+{
+  int personality_orig = (int) (uintptr_t) arg;
+
+  errno = 0;
+  personality (personality_orig);
+  if (errno != 0)
+    warning (_("Error restoring address space randomization: %s"),
+	     safe_strerror (errno));
+}
+#endif /* HAVE_PERSONALITY */
+
+/* Return a cleanup responsible for restoring the inferior's
+   personality (and restoring the inferior's address space
+   randomization) if HAVE_PERSONALITY and if PERSONALITY_SET is not
+   zero; return a null cleanup if not HAVE_PERSONALITY or if
+   PERSONALITY_SET is zero.  */
+
+static struct cleanup *
+make_disable_asr_cleanup (int personality_set, int personality_orig)
+{
+#ifdef HAVE_PERSONALITY
+  if (personality_set != 0)
+    return make_cleanup (restore_personality,
+			 (void *) (uintptr_t) personality_orig);
+#endif /* HAVE_PERSONALITY */
+
+  return make_cleanup (null_cleanup, NULL);
+}
+
+/* See comment on nat/linux-personality.h.  */
+
+struct cleanup *
+maybe_disable_address_space_randomization (int disable_randomization)
+{
+  int personality_orig = 0;
+  int personality_set = 0;
+
+#ifdef HAVE_PERSONALITY
+  if (disable_randomization)
+    {
+      errno = 0;
+      personality_orig = personality (0xffffffff);
+      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
+	{
+	  personality_set = 1;
+	  personality (personality_orig | ADDR_NO_RANDOMIZE);
+	}
+      if (errno != 0 || (personality_set
+			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
+	warning (_("Error disabling address space randomization: %s"),
+		 safe_strerror (errno));
+    }
+#endif /* HAVE_PERSONALITY */
+
+  return make_disable_asr_cleanup (personality_set,
+				   personality_orig);
+}
diff --git a/gdb/nat/linux-personality.h b/gdb/nat/linux-personality.h
new file mode 100644
index 0000000..817e4e8e
--- /dev/null
+++ b/gdb/nat/linux-personality.h
@@ -0,0 +1,31 @@
+/* Disable address space randomization based on inferior personality.
+
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef COMMON_LINUX_PERSONALITY_H
+#define COMMON_LINUX_PERSONALITY_H
+
+/* Disable the inferior's address space randomization if
+   DISABLE_RANDOMIZATION is not zero and if we have
+   <sys/personality.h>.  Return a cleanup which, when called, will
+   re-enable the inferior's address space randomization.  */
+
+extern struct cleanup *maybe_disable_address_space_randomization
+  (int disable_randomization);
+
+#endif /* ! COMMON_LINUX_PERSONALITY_H */

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/2] Move safe_strerror to common/
  2015-01-13 20:48     ` Sergio Durigan Junior
@ 2015-01-14 11:26       ` Pedro Alves
  2015-01-15  7:05         ` Sergio Durigan Junior
  0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2015-01-14 11:26 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Gary Benson

> diff --git a/gdb/common/common.host b/gdb/common/common.host
> new file mode 100644
> index 0000000..1c3374a
> --- /dev/null
> +++ b/gdb/common/common.host
> @@ -0,0 +1,35 @@
> +# Common object files to include for each host.
> +#
> +# Copyright (C) 2015 Free Software Foundation, Inc.
> +#
> +# This file is part of GDB.
> +#
> +# This program 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 of the License, or
> +# (at your option) any later version.
> +#
> +# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Mapping of configurations into GDB host definitions.

This comment isn't right.

> This is
> +# invoked from the autoconf generated configure script.
> +
> +# This file sets the following shell variables:
> +#  gdb_host_obs			host-specific .o files to include when building GDB
> +#  srv_host_obs			likewise, but when building gdbserver

This one is stale.  Should describe common_host_obs.

> +
> +case "${host}" in
> +
> +*-mingw*)	common_host_obs=mingw-strerror.o
> +		;;
> +*)
> +		common_host_obs=posix-strerror.o
> +		;;
> +
> +esac
> diff --git a/gdb/configure.ac b/gdb/configure.ac
> index ec776d7..7812ec6 100644
> --- a/gdb/configure.ac
> +++ b/gdb/configure.ac
> @@ -195,7 +195,7 @@ esac],[want64=false])dnl
>  
>  # Provide defaults for some variables set by the per-host and per-target
>  # configuration.
> -gdb_host_obs=posix-hdep.o
> +gdb_host_obs="posix-hdep.o"

Unnecessary change.

>  
>  if test "${target}" = "${host}"; then
>    gdb_native=yes
> @@ -204,6 +204,9 @@ else
>  fi
>  
>  . $srcdir/configure.host
> +. $srcdir/common/common.host
> +
> +gdb_host_obs="$gdb_host_obs $common_host_obs"
>  

I'd rather that it was the latter two lines that were together, like:

 . $srcdir/configure.host

 # Add in the common host objects.
 . $srcdir/common/common.host
 gdb_host_obs="$gdb_host_obs $common_host_obs"


>  # Accumulate some settings from configure.tgt over all enabled targets
>  
> diff --git a/gdb/configure.host b/gdb/configure.host
> index d07be4b..9f8a917 100644
> --- a/gdb/configure.host
> +++ b/gdb/configure.host
> @@ -7,7 +7,6 @@
>  #  gdb_host_float_format	host's float floatformat, or 0
>  #  gdb_host_double_format	host's double floatformat, or 0
>  #  gdb_host_long_double_format	host's long double floatformat, or 0
> -#  gdb_host_obs			host-specific .o files to include
>  
>  # Map host cpu into the config cpu subdirectory name.
>  # The default is $host_cpu.
> @@ -105,7 +104,6 @@ i[34567]86-*-netbsdelf* | i[34567]86-*-knetbsd*-gnu)
>  			gdb_host=nbsdelf ;;
>  i[34567]86-*-go32*)	gdb_host=go32 ;;
>  i[34567]86-*-mingw32*)	gdb_host=mingw
> -			gdb_host_obs=mingw-hdep.o
>  			;;
>  i[34567]86-*-msdosdjgpp*) gdb_host=go32 ;;
>  i[34567]86-*-linux*)	gdb_host=linux ;;
> @@ -181,7 +179,6 @@ x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
>  			gdb_host=nbsd64 ;;
>  x86_64-*-openbsd*)	gdb_host=obsd64 ;;
>  x86_64-*-mingw*)        gdb_host=mingw64
> -			gdb_host_obs=mingw-hdep.o
>  			;;
>  x86_64-*-cygwin*)	gdb_host=cygwin64 ;;
>  m32r*-*-linux*)          gdb_host=linux ;;

Given mingw-hdep.o still exists and must be included in the
mingw gdb build, this must be breaking the build there.
Just drop this hunk from the patch.  Could you make sure the mingw build
still builds?  There are mingw packages in Fedora.  (configure
with --host=x86_64-w64-mingw32).

> --- a/gdb/gdbserver/configure.ac
> +++ b/gdb/gdbserver/configure.ac
> @@ -240,7 +240,14 @@ got it
>      ;;
>  esac
>  
> +# Initialize as POSIX.  This will change if the host is MinGW.

Drop this comment.

> +
> +srv_host_obs=""

We don't actually need this.

> +
>  . ${srcdir}/configure.srv
> +. ${srcdir}/../common/common.host
> +
> +srv_host_obs="$srv_host_obs $common_host_obs"

Like in the GDB version:

  . ${srcdir}/configure.srv

  # Add in the common host objects.
  . ${srcdir}/../common/common.host
  srv_host_obs=$common_host_obs

But you can also drop srv_host_obs and write common_host_obs directly below.

>  
>  if test "${srv_mingwce}" = "yes"; then
>    LIBS="$LIBS -lws2"
> @@ -385,7 +392,7 @@ if test "$srv_xmlfiles" != ""; then
>    done
>  fi
>  
> -GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
> +GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
>  GDBSERVER_LIBS="$srv_libs"
>  
>  dnl Check whether the target supports __sync_*_compare_and_swap.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-13 20:55     ` Sergio Durigan Junior
@ 2015-01-14 11:32       ` Pedro Alves
  2015-01-15  7:06         ` Sergio Durigan Junior
  2015-01-16  0:04         ` Sergio Durigan Junior
  0 siblings, 2 replies; 17+ messages in thread
From: Pedro Alves @ 2015-01-14 11:32 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Gary Benson

On 01/13/2015 08:55 PM, Sergio Durigan Junior wrote:
> gdb/ChangeLog
> 2015-01-13  Sergio Durigan Junior  <sergiodj@redhat.com>

> 	* nat/linux-osdata.h (maybe_disable_address_space_randomization):
> 	New prototype.

This bit is stale.

> 	* nat/linux-personality.c: New file.
> 	* nat/linux-personality.h: Likewise.


> diff --git a/gdb/nat/linux-personality.h b/gdb/nat/linux-personality.h
> new file mode 100644
> index 0000000..817e4e8e
> --- /dev/null
> +++ b/gdb/nat/linux-personality.h
> @@ -0,0 +1,31 @@

> +#ifndef COMMON_LINUX_PERSONALITY_H
> +#define COMMON_LINUX_PERSONALITY_H

> +#endif /* ! COMMON_LINUX_PERSONALITY_H */

Should be NAT_LINUX_PERSONALITY_H.

Otherwise looks good.  Thanks.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/2] Move safe_strerror to common/
  2015-01-14 11:26       ` Pedro Alves
@ 2015-01-15  7:05         ` Sergio Durigan Junior
  2015-01-15  9:02           ` Pedro Alves
  0 siblings, 1 reply; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-15  7:05 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Gary Benson

Thanks for the review.

On Wednesday, January 14 2015, Pedro Alves wrote:

>> diff --git a/gdb/common/common.host b/gdb/common/common.host
>> new file mode 100644
>> index 0000000..1c3374a
>> --- /dev/null
>> +++ b/gdb/common/common.host
>> @@ -0,0 +1,35 @@
>> +# Common object files to include for each host.
>> +#
>> +# Copyright (C) 2015 Free Software Foundation, Inc.
>> +#
>> +# This file is part of GDB.
>> +#
>> +# This program 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 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +# Mapping of configurations into GDB host definitions.
>
> This comment isn't right.

Improved/fixed.

>> This is
>> +# invoked from the autoconf generated configure script.
>> +
>> +# This file sets the following shell variables:
>> +#  gdb_host_obs			host-specific .o files to include when building GDB
>> +#  srv_host_obs			likewise, but when building gdbserver
>
> This one is stale.  Should describe common_host_obs.

Fixed.

>> +
>> +case "${host}" in
>> +
>> +*-mingw*)	common_host_obs=mingw-strerror.o
>> +		;;
>> +*)
>> +		common_host_obs=posix-strerror.o
>> +		;;
>> +
>> +esac
>> diff --git a/gdb/configure.ac b/gdb/configure.ac
>> index ec776d7..7812ec6 100644
>> --- a/gdb/configure.ac
>> +++ b/gdb/configure.ac
>> @@ -195,7 +195,7 @@ esac],[want64=false])dnl
>>  
>>  # Provide defaults for some variables set by the per-host and per-target
>>  # configuration.
>> -gdb_host_obs=posix-hdep.o
>> +gdb_host_obs="posix-hdep.o"
>
> Unnecessary change.

Fixed.

>>  
>>  if test "${target}" = "${host}"; then
>>    gdb_native=yes
>> @@ -204,6 +204,9 @@ else
>>  fi
>>  
>>  . $srcdir/configure.host
>> +. $srcdir/common/common.host
>> +
>> +gdb_host_obs="$gdb_host_obs $common_host_obs"
>>  
>
> I'd rather that it was the latter two lines that were together, like:
>
>  . $srcdir/configure.host
>
>  # Add in the common host objects.
>  . $srcdir/common/common.host
>  gdb_host_obs="$gdb_host_obs $common_host_obs"
>

Adjusted.

>>  # Accumulate some settings from configure.tgt over all enabled targets
>>  
>> diff --git a/gdb/configure.host b/gdb/configure.host
>> index d07be4b..9f8a917 100644
>> --- a/gdb/configure.host
>> +++ b/gdb/configure.host
>> @@ -7,7 +7,6 @@
>>  #  gdb_host_float_format	host's float floatformat, or 0
>>  #  gdb_host_double_format	host's double floatformat, or 0
>>  #  gdb_host_long_double_format	host's long double floatformat, or 0
>> -#  gdb_host_obs			host-specific .o files to include
>>  
>>  # Map host cpu into the config cpu subdirectory name.
>>  # The default is $host_cpu.
>> @@ -105,7 +104,6 @@ i[34567]86-*-netbsdelf* | i[34567]86-*-knetbsd*-gnu)
>>  			gdb_host=nbsdelf ;;
>>  i[34567]86-*-go32*)	gdb_host=go32 ;;
>>  i[34567]86-*-mingw32*)	gdb_host=mingw
>> -			gdb_host_obs=mingw-hdep.o
>>  			;;
>>  i[34567]86-*-msdosdjgpp*) gdb_host=go32 ;;
>>  i[34567]86-*-linux*)	gdb_host=linux ;;
>> @@ -181,7 +179,6 @@ x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
>>  			gdb_host=nbsd64 ;;
>>  x86_64-*-openbsd*)	gdb_host=obsd64 ;;
>>  x86_64-*-mingw*)        gdb_host=mingw64
>> -			gdb_host_obs=mingw-hdep.o
>>  			;;
>>  x86_64-*-cygwin*)	gdb_host=cygwin64 ;;
>>  m32r*-*-linux*)          gdb_host=linux ;;
>
> Given mingw-hdep.o still exists and must be included in the
> mingw gdb build, this must be breaking the build there.
> Just drop this hunk from the patch.  Could you make sure the mingw build
> still builds?  There are mingw packages in Fedora.  (configure
> with --host=x86_64-w64-mingw32).

Thanks; I checked and it builds fine.

>> --- a/gdb/gdbserver/configure.ac
>> +++ b/gdb/gdbserver/configure.ac
>> @@ -240,7 +240,14 @@ got it
>>      ;;
>>  esac
>>  
>> +# Initialize as POSIX.  This will change if the host is MinGW.
>
> Drop this comment.

Done.

>> +
>> +srv_host_obs=""
>
> We don't actually need this.

Fixed.

>> +
>>  . ${srcdir}/configure.srv
>> +. ${srcdir}/../common/common.host
>> +
>> +srv_host_obs="$srv_host_obs $common_host_obs"
>
> Like in the GDB version:
>
>   . ${srcdir}/configure.srv
>
>   # Add in the common host objects.
>   . ${srcdir}/../common/common.host
>   srv_host_obs=$common_host_obs
>
> But you can also drop srv_host_obs and write common_host_obs directly below.

I decided to keep srv_host_obs.

>>  
>>  if test "${srv_mingwce}" = "yes"; then
>>    LIBS="$LIBS -lws2"
>> @@ -385,7 +392,7 @@ if test "$srv_xmlfiles" != ""; then
>>    done
>>  fi
>>  
>> -GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
>> +GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
>>  GDBSERVER_LIBS="$srv_libs"
>>  
>>  dnl Check whether the target supports __sync_*_compare_and_swap.
>
> Thanks,
> Pedro Alves

Here's the updated patch (with an updated ChangeLog).

Thanks,

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

gdb/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (ALLDEPFILES): Including common/mingw-strerror.c and
	common/posix-strerror.c.
	(posix-strerror.o): New rule.
	(mingw-strerror.o): Likewise.
	* common/common-utils.h (safe_strerror): Move prototype to here,
	from utils.h.
	* common/common.host: New file.
	* common/mingw-strerror.c: Likewise.
	* common/posix-strerror.c: Likewise.
	* configure: Regenerated.
	* configure.ac: Source common/common.host.  Add variable
	common_host_obs to gdb_host_obs.
	* contrib/ari/gdb_ari.sh: Mention gdb/common/mingw-strerror.c and
	gdb/common/posix-strerror.c when warning about the use of
	strerror.
	* mingw-hdep.c (safe_strerror): Remove definition; move it to
	common/mingw-strerror.c.
	* posix-hdep.c (safe_strerror): Remove definition; move it to
	common/posix-hdep.c.
	* utils.h (safe_strerror): Remove prototype; move to
	common/common-utils.h.

gdb/gdbserver/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (posix-strerror.o): New rule.
	(mingw-strerror.o): Likewise.
	* configure: Regenerated.
	* configure.ac: Source file ../common/common.host.  Initialize new
	variable srv_host_obs.  Add srv_host_obs to GDBSERVER_DEPFILES.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f970176..57ed361 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1680,7 +1680,7 @@ ALLDEPFILES = \
 	m68klinux-nat.c m68klinux-tdep.c \
 	m88k-tdep.c m88kbsd-nat.c \
 	microblaze-tdep.c microblaze-linux-tdep.c \
-	mingw-hdep.c \
+	mingw-hdep.c common/mingw-strerror.c \
 	mips-linux-nat.c mips-linux-tdep.c \
 	mips-sde-tdep.c \
 	mips-tdep.c \
@@ -1690,7 +1690,7 @@ ALLDEPFILES = \
 	nios2-tdep.c nios2-linux-tdep.c \
 	nbsd-nat.c nbsd-tdep.c obsd-nat.c obsd-tdep.c \
 	somread.c solib-som.c \
-	posix-hdep.c \
+	posix-hdep.c common/posix-strerror.c \
 	ppc-sysv-tdep.c ppc-linux-nat.c ppc-linux-tdep.c ppc64-tdep.c \
 	ppcfbsd-nat.c ppcfbsd-tdep.c \
 	ppcnbsd-nat.c ppcnbsd-tdep.c \
@@ -2227,6 +2227,14 @@ common-exceptions.o: ${srcdir}/common/common-exceptions.c
 	$(COMPILE) $(srcdir)/common/common-exceptions.c
 	$(POSTCOMPILE)
 
+posix-strerror.o: ${srcdir}/common/posix-strerror.c
+	$(COMPILE) $(srcdir)/common/posix-strerror.c
+	$(POSTCOMPILE)
+
+mingw-strerror.o: ${srcdir}/common/mingw-strerror.c
+	$(COMPILE) $(srcdir)/common/mingw-strerror.c
+	$(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index f110924..60aa030 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -62,4 +62,10 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
 
 char *savestring (const char *ptr, size_t len);
 
+/* The strerror() function can return NULL for errno values that are
+   out of range.  Provide a "safe" version that always returns a
+   printable string.  */
+
+extern char *safe_strerror (int);
+
 #endif
diff --git a/gdb/common/common.host b/gdb/common/common.host
new file mode 100644
index 0000000..4245e7c
--- /dev/null
+++ b/gdb/common/common.host
@@ -0,0 +1,36 @@
+# Common object files to include for each host.
+#
+# Copyright (C) 2015 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# This program 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 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Map host CPU into the common object files to be included by
+# GDB/gdbserver.  This is invoked from the autoconf generated
+# configure script.
+
+# This file sets the following shell variables:
+#  common_host_obs		host-specific .o files to include when building
+#  				GDB/gdbserver
+
+case "${host}" in
+
+*-mingw*)	common_host_obs=mingw-strerror.o
+		;;
+*)
+		common_host_obs=posix-strerror.o
+		;;
+
+esac
diff --git a/gdb/common/mingw-strerror.c b/gdb/common/mingw-strerror.c
new file mode 100644
index 0000000..c62c42d
--- /dev/null
+++ b/gdb/common/mingw-strerror.c
@@ -0,0 +1,64 @@
+/* Safe version of strerror for MinGW, for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+#include <windows.h>
+
+/* Implementation of safe_strerror as defined in common-utils.h.
+
+   The Windows runtime implementation of strerror never returns NULL,
+   but does return a useless string for anything above sys_nerr;
+   unfortunately this includes all socket-related error codes.
+   This replacement tries to find a system-provided error message.  */
+
+char *
+safe_strerror (int errnum)
+{
+  static char *buffer;
+  int len;
+
+  if (errnum >= 0 && errnum < sys_nerr)
+    return strerror (errnum);
+
+  if (buffer)
+    {
+      LocalFree (buffer);
+      buffer = NULL;
+    }
+
+  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+		     | FORMAT_MESSAGE_FROM_SYSTEM,
+		     NULL, errnum,
+		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+		     (LPTSTR) &buffer, 0, NULL) == 0)
+    {
+      static char buf[32];
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      return buf;
+    }
+
+  /* Windows error messages end with a period and a CR-LF; strip that
+     out.  */
+  len = strlen (buffer);
+  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
+    buffer[len - 3] = '\0';
+
+  return buffer;
+}
diff --git a/gdb/common/posix-strerror.c b/gdb/common/posix-strerror.c
new file mode 100644
index 0000000..119fcf6
--- /dev/null
+++ b/gdb/common/posix-strerror.c
@@ -0,0 +1,38 @@
+/* Safe version of strerror for POSIX systems for GDB, the GNU debugger.
+
+   Copyright (C) 2006-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+
+/* Implementation of safe_strerror as defined in common-utils.h.  */
+
+char *
+safe_strerror (int errnum)
+{
+  char *msg;
+
+  msg = strerror (errnum);
+  if (msg == NULL)
+    {
+      static char buf[32];
+
+      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
+      msg = buf;
+    }
+  return (msg);
+}
diff --git a/gdb/configure b/gdb/configure
index fdcf215..f62d5a0 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -5308,6 +5308,10 @@ fi
 
 . $srcdir/configure.host
 
+# Add in the common host objects.
+. $srcdir/common/common.host
+gdb_host_obs="$gdb_host_obs $common_host_obs"
+
 # Accumulate some settings from configure.tgt over all enabled targets
 
 TARGET_OBS=
diff --git a/gdb/configure.ac b/gdb/configure.ac
index cc18174..8dd7f8f 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -205,6 +205,10 @@ fi
 
 . $srcdir/configure.host
 
+# Add in the common host objects.
+. $srcdir/common/common.host
+gdb_host_obs="$gdb_host_obs $common_host_obs"
+
 # Accumulate some settings from configure.tgt over all enabled targets
 
 TARGET_OBS=
diff --git a/gdb/contrib/ari/gdb_ari.sh b/gdb/contrib/ari/gdb_ari.sh
index 8a8cec8..b868a17 100644
--- a/gdb/contrib/ari/gdb_ari.sh
+++ b/gdb/contrib/ari/gdb_ari.sh
@@ -603,8 +603,8 @@ BEGIN { doc["strerror"] = "\
 Do not use strerror(), instead use safe_strerror()"
     category["strerror"] = ari_regression
     fix("strerror", "gdb/gdb_string.h", 1)
-    fix("strerror", "gdb/mingw-hdep.c", 1)
-    fix("strerror", "gdb/posix-hdep.c", 1)
+    fix("strerror", "gdb/common/mingw-strerror.c", 1)
+    fix("strerror", "gdb/common/posix-strerror.c", 1)
 }
 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
     fail("strerror")
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 0e442fc..8406ff4 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -518,6 +518,12 @@ rsp-low.o: ../common/rsp-low.c
 common-utils.o: ../common/common-utils.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+posix-strerror.o: ../common/posix-strerror.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
+mingw-strerror.o: ../common/mingw-strerror.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 vec.o: ../common/vec.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 55bd2c5..2240b78 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -5539,6 +5539,10 @@ esac
 
 . ${srcdir}/configure.srv
 
+# Add in the common host objects.
+. ${srcdir}/../common/common.host
+srv_host_obs="$common_host_obs"
+
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
 elif test "${srv_mingw}" = "yes"; then
@@ -6034,7 +6038,7 @@ $as_echo "#define USE_XML 1" >>confdefs.h
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports __sync_*_compare_and_swap" >&5
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 39e3a06..f883adc 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -242,6 +242,10 @@ esac
 
 . ${srcdir}/configure.srv
 
+# Add in the common host objects.
+. ${srcdir}/../common/common.host
+srv_host_obs="$common_host_obs"
+
 if test "${srv_mingwce}" = "yes"; then
   LIBS="$LIBS -lws2"
 elif test "${srv_mingw}" = "yes"; then
@@ -385,7 +389,7 @@ if test "$srv_xmlfiles" != ""; then
   done
 fi
 
-GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
+GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles $srv_host_obs"
 GDBSERVER_LIBS="$srv_libs"
 
 dnl Check whether the target supports __sync_*_compare_and_swap.
diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c
index c0cc385..a0ed281 100644
--- a/gdb/mingw-hdep.c
+++ b/gdb/mingw-hdep.c
@@ -35,50 +35,6 @@ static HANDLE sigint_event;
    function.  */
 struct async_signal_handler *sigint_handler;
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string.
-
-   The Windows runtime implementation of strerror never returns NULL,
-   but does return a useless string for anything above sys_nerr;
-   unfortunately this includes all socket-related error codes.
-   This replacement tries to find a system-provided error message.  */
-
-char *
-safe_strerror (int errnum)
-{
-  static char *buffer;
-  int len;
-
-  if (errnum >= 0 && errnum < sys_nerr)
-    return strerror (errnum);
-
-  if (buffer)
-    {
-      LocalFree (buffer);
-      buffer = NULL;
-    }
-
-  if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
-		     | FORMAT_MESSAGE_FROM_SYSTEM,
-		     NULL, errnum,
-		     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
-		     (LPTSTR) &buffer, 0, NULL) == 0)
-    {
-      static char buf[32];
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      return buf;
-    }
-
-  /* Windows error messages end with a period and a CR-LF; strip that
-     out.  */
-  len = strlen (buffer);
-  if (len > 3 && strcmp (buffer + len - 3, ".\r\n") == 0)
-    buffer[len - 3] = '\0';
-
-  return buffer;
-}
-
 /* Return an absolute file name of the running GDB, if possible, or
    ARGV0 if not.  The return value is in malloc'ed storage.  */
 
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c
index 13cddba..fef5ec1 100644
--- a/gdb/posix-hdep.c
+++ b/gdb/posix-hdep.c
@@ -22,26 +22,6 @@
 
 #include "gdb_select.h"
 
-/* The strerror() function can return NULL for errno values that are
-   out of range.  Provide a "safe" version that always returns a
-   printable string.  */
-
-char *
-safe_strerror (int errnum)
-{
-  char *msg;
-
-  msg = strerror (errnum);
-  if (msg == NULL)
-    {
-      static char buf[32];
-
-      xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
-      msg = buf;
-    }
-  return (msg);
-}
-
 /* Wrapper for select.  Nothing special needed on POSIX platforms.  */
 
 int
diff --git a/gdb/utils.h b/gdb/utils.h
index 3debde7..e58260c 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -42,9 +42,6 @@ ULONGEST strtoulst (const char *num, const char **trailer, int base);
 int compare_positive_ints (const void *ap, const void *bp);
 int compare_strings (const void *ap, const void *bp);
 
-/* This is defined in *-hdep.c, e.g., posix-hdep.c.  */
-extern char *safe_strerror (int);
-
 /* A wrapper for bfd_errmsg to produce a more helpful error message
    in the case of bfd_error_file_ambiguously recognized.
    MATCHING, if non-NULL, is the corresponding argument to

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-14 11:32       ` Pedro Alves
@ 2015-01-15  7:06         ` Sergio Durigan Junior
  2015-01-16  0:04         ` Sergio Durigan Junior
  1 sibling, 0 replies; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-15  7:06 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Gary Benson

Thanks for the review.

On Wednesday, January 14 2015, Pedro Alves wrote:

> On 01/13/2015 08:55 PM, Sergio Durigan Junior wrote:
>> gdb/ChangeLog
>> 2015-01-13  Sergio Durigan Junior  <sergiodj@redhat.com>
>
>> 	* nat/linux-osdata.h (maybe_disable_address_space_randomization):
>> 	New prototype.
>
> This bit is stale.

Removed.

>> 	* nat/linux-personality.c: New file.
>> 	* nat/linux-personality.h: Likewise.
>
>
>> diff --git a/gdb/nat/linux-personality.h b/gdb/nat/linux-personality.h
>> new file mode 100644
>> index 0000000..817e4e8e
>> --- /dev/null
>> +++ b/gdb/nat/linux-personality.h
>> @@ -0,0 +1,31 @@
>
>> +#ifndef COMMON_LINUX_PERSONALITY_H
>> +#define COMMON_LINUX_PERSONALITY_H
>
>> +#endif /* ! COMMON_LINUX_PERSONALITY_H */
>
> Should be NAT_LINUX_PERSONALITY_H.

Fixed.

> Otherwise looks good.  Thanks.

Thanks.  Here's the updated patch (with an updated ChangeLog).  I will
wait until the first patch is accepted before I push this one.

Cheers,

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

gdb/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-personality.h.
	(linux-personality.o): New rule.
	* common/common-defs.h: Include <stdint.h>.
	* config/aarch64/linux.mh (NATDEPFILES): Include
	linux-personality.o.
	* config/alpha/alpha-linux.mh (NATDEPFILES): Likewise.
	* config/arm/linux.mh (NATDEPFILES): Likewise.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* config/i386/linux.mh (NATDEPFILES): Likewise.
	* config/ia64/linux.mh (NATDEPFILES): Likewise.
	* config/m32r/linux.mh (NATDEPFILES): Likewise.
	* config/m68k/linux.mh (NATDEPFILES): Likewise.
	* config/mips/linux.mh (NATDEPFILES): Likewise.
	* config/pa/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/spu-linux.mh (NATDEPFILES): Likewise.
	* config/s390/linux.mh (NATDEPFILES): Likewise.
	* config/sparc/linux64.mh (NATDEPFILES): Likewise.
	* config/sparc/linux.mh (NATDEPFILES): Likewise.
	* config/tilegx/linux.mh (NATDEPFILES): Likewise.
	* config/xtensa/linux.mh (NATDEPFILES): Likewise.
	* defs.h: Remove #include <stdint.h> (moved to
	common/common-defs.h).
	* linux-nat.c: Include nat/linux-personality.h.  Remove #include
	<sys/personality.h>; do not define ADDR_NO_RANDOMIZE (moved to
	nat/linux-personality.c).
	(linux_nat_create_inferior): Remove code to disable address space
	randomization (moved to nat/linux-personality.c).  Create cleanup
	to disable address space randomization.
	* nat/linux-personality.c: New file.
	* nat/linux-personality.h: Likewise.

gdb/gdbserver/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SFILES): Add linux-personality.c.
	(linux-personality.o): New rule.
	* configure.srv (srv_linux_obj): Add linux-personality.o to the
	list of objects to be built.
	* linux-low.c: Include nat/linux-personality.h.
	(linux_create_inferior): Remove code to disable address space
	randomization (moved to ../nat/linux-personality.c).  Create
	cleanup to disable address space randomization.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 57ed361..6b270eb 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -961,7 +961,7 @@ common/print-utils.h common/rsp-low.h nat/x86-dregs.h x86-linux-nat.h \
 i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
 common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
 common/common-exceptions.h target/target.h common/symbol.h \
-common/common-regcache.h fbsd-tdep.h
+common/common-regcache.h fbsd-tdep.h nat/linux-personality.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
@@ -2282,6 +2282,10 @@ ppc-linux.o: ${srcdir}/nat/ppc-linux.c
 	$(COMPILE) $(srcdir)/nat/ppc-linux.c
 	$(POSTCOMPILE)
 
+linux-personality.o: ${srcdir}/nat/linux-personality.c
+	$(COMPILE) $(srcdir)/nat/linux-personality.c
+	$(POSTCOMPILE)
+
 #
 # gdb/tui/ dependencies
 #
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 1873211..e80d332 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <string.h>
 #include <errno.h>
 #include <alloca.h>
diff --git a/gdb/config/aarch64/linux.mh b/gdb/config/aarch64/linux.mh
index af04f46..7f96e4d 100644
--- a/gdb/config/aarch64/linux.mh
+++ b/gdb/config/aarch64/linux.mh
@@ -21,7 +21,8 @@
 NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o aarch64-linux-nat.o \
 	proc-service.o linux-thread-db.o linux-nat.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-osdata.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-osdata.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/alpha/alpha-linux.mh b/gdb/config/alpha/alpha-linux.mh
index 81819a1..2ea02a1 100644
--- a/gdb/config/alpha/alpha-linux.mh
+++ b/gdb/config/alpha/alpha-linux.mh
@@ -3,7 +3,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o alpha-linux-nat.o \
 	fork-child.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/arm/linux.mh b/gdb/config/arm/linux.mh
index 63c3eae..549bf42 100644
--- a/gdb/config/arm/linux.mh
+++ b/gdb/config/arm/linux.mh
@@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o arm-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/i386/linux.mh b/gdb/config/i386/linux.mh
index a4e4842..33fb281 100644
--- a/gdb/config/i386/linux.mh
+++ b/gdb/config/i386/linux.mh
@@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	x86-nat.o x86-dregs.o i386-linux-nat.o x86-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-btrace.o linux-waitpid.o
+	linux-btrace.o linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/i386/linux64.mh b/gdb/config/i386/linux64.mh
index d557202..d52eb52 100644
--- a/gdb/config/i386/linux64.mh
+++ b/gdb/config/i386/linux64.mh
@@ -5,7 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	linux-nat.o linux-osdata.o \
 	proc-service.o linux-thread-db.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-btrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_FILE= config/nm-linux.h
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/ia64/linux.mh b/gdb/config/ia64/linux.mh
index baa8709..9dce22b 100644
--- a/gdb/config/ia64/linux.mh
+++ b/gdb/config/ia64/linux.mh
@@ -5,6 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	ia64-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
+	linux-personality.o \
 	linux-procfs.o linux-ptrace.o linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/m32r/linux.mh b/gdb/config/m32r/linux.mh
index e9bb82c..6b810e6 100644
--- a/gdb/config/m32r/linux.mh
+++ b/gdb/config/m32r/linux.mh
@@ -4,7 +4,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o				\
 	m32r-linux-nat.o proc-service.o linux-thread-db.o	\
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES= -ldl $(RDYNAMIC)
diff --git a/gdb/config/m68k/linux.mh b/gdb/config/m68k/linux.mh
index bcec295..f3b3baa 100644
--- a/gdb/config/m68k/linux.mh
+++ b/gdb/config/m68k/linux.mh
@@ -5,6 +5,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	m68klinux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/mips/linux.mh b/gdb/config/mips/linux.mh
index 021838e..d6a802f 100644
--- a/gdb/config/mips/linux.mh
+++ b/gdb/config/mips/linux.mh
@@ -4,6 +4,7 @@ NATDEPFILES= inf-ptrace.o fork-child.o mips-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
 	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o \
 	mips-linux-watch.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
diff --git a/gdb/config/pa/linux.mh b/gdb/config/pa/linux.mh
index f1c0c32..9539b64 100644
--- a/gdb/config/pa/linux.mh
+++ b/gdb/config/pa/linux.mh
@@ -3,7 +3,8 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	hppa-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/powerpc/linux.mh b/gdb/config/powerpc/linux.mh
index a807d3f..76e62c0 100644
--- a/gdb/config/powerpc/linux.mh
+++ b/gdb/config/powerpc/linux.mh
@@ -6,7 +6,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	ppc-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/powerpc/ppc64-linux.mh b/gdb/config/powerpc/ppc64-linux.mh
index 1b3fbc7..7eb6507 100644
--- a/gdb/config/powerpc/ppc64-linux.mh
+++ b/gdb/config/powerpc/ppc64-linux.mh
@@ -6,7 +6,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o \
 	ppc-linux-nat.o proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o ppc-linux.o
+	linux-waitpid.o ppc-linux.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The PowerPC has severe limitations on TOC size, and uses them even
diff --git a/gdb/config/powerpc/spu-linux.mh b/gdb/config/powerpc/spu-linux.mh
index 7ce7a5f..d44aeeb 100644
--- a/gdb/config/powerpc/spu-linux.mh
+++ b/gdb/config/powerpc/spu-linux.mh
@@ -4,5 +4,5 @@
 # PPU side of the Cell BE and debugging the SPU side.
 
 NATDEPFILES = spu-linux-nat.o fork-child.o inf-ptrace.o \
-	      linux-procfs.o linux-ptrace.o linux-waitpid.o
+	      linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o
 
diff --git a/gdb/config/s390/linux.mh b/gdb/config/s390/linux.mh
index 59bab83..e1ad899 100644
--- a/gdb/config/s390/linux.mh
+++ b/gdb/config/s390/linux.mh
@@ -3,6 +3,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o s390-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
+	linux-personality.o \
 	linux-waitpid.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/config/sparc/linux.mh b/gdb/config/sparc/linux.mh
index 009ea95..bd7fc86 100644
--- a/gdb/config/sparc/linux.mh
+++ b/gdb/config/sparc/linux.mh
@@ -4,7 +4,8 @@ NATDEPFILES= sparc-nat.o sparc-linux-nat.o \
 	fork-child.o inf-ptrace.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/sparc/linux64.mh b/gdb/config/sparc/linux64.mh
index aad77c7..86f984f 100644
--- a/gdb/config/sparc/linux64.mh
+++ b/gdb/config/sparc/linux64.mh
@@ -4,7 +4,8 @@ NATDEPFILES= sparc-nat.o sparc64-nat.o sparc64-linux-nat.o \
 	fork-child.o inf-ptrace.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 # The dynamically loaded libthread_db needs access to symbols in the
diff --git a/gdb/config/tilegx/linux.mh b/gdb/config/tilegx/linux.mh
index 1ed9c33..b5edcd4 100644
--- a/gdb/config/tilegx/linux.mh
+++ b/gdb/config/tilegx/linux.mh
@@ -5,7 +5,8 @@ NATDEPFILES= inf-ptrace.o fork-child.o \
 	tilegx-linux-nat.o \
 	proc-service.o linux-thread-db.o \
 	linux-nat.o linux-osdata.o linux-fork.o \
-	linux-procfs.o linux-ptrace.o linux-waitpid.o
+	linux-procfs.o linux-ptrace.o linux-waitpid.o \
+	linux-personality.o
 
 # The dynamically loaded libthread_db needs access to symbols in the
 # gdb executable.
diff --git a/gdb/config/xtensa/linux.mh b/gdb/config/xtensa/linux.mh
index 8ef84b4..b4e59b3 100644
--- a/gdb/config/xtensa/linux.mh
+++ b/gdb/config/xtensa/linux.mh
@@ -5,7 +5,7 @@ NAT_FILE= config/nm-linux.h
 NATDEPFILES= inf-ptrace.o fork-child.o xtensa-linux-nat.o \
 	linux-thread-db.o proc-service.o \
 	linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
-	linux-waitpid.o
+	linux-waitpid.o linux-personality.o
 NAT_CDEPS = $(srcdir)/proc-service.list
 
 LOADLIBES = -ldl $(RDYNAMIC)
diff --git a/gdb/defs.h b/gdb/defs.h
index 99db465..a1cd45f 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 #include <limits.h>
-#include <stdint.h>
 
 /* The libdecnumber library, on which GDB depends, includes a header file
    called gstdint.h instead of relying directly on stdint.h.  GDB, on the
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 8406ff4..b455c5b 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -167,6 +167,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/common/vec.c $(srcdir)/common/gdb_vecs.c \
 	$(srcdir)/common/common-utils.c $(srcdir)/common/xml-utils.c \
 	$(srcdir)/nat/linux-osdata.c $(srcdir)/common/ptid.c \
+	$(srcdir)/nat/linux-personality.c \
 	$(srcdir)/common/buffer.c $(srcdir)/nat/linux-btrace.c \
 	$(srcdir)/common/filestuff.c $(srcdir)/target/waitstatus.c \
 	$(srcdir)/nat/mips-linux-watch.c $(srcdir)/common/print-utils.c \
@@ -590,6 +591,9 @@ mips-linux-watch.o: ../nat/mips-linux-watch.c
 ppc-linux.o: ../nat/ppc-linux.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+linux-personality.o: ../nat/linux-personality.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 
 aarch64.c : $(srcdir)/../regformats/aarch64.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/aarch64.dat aarch64.c
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index f52aee2..127786e 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -42,7 +42,7 @@ srv_amd64_linux_xmlfiles="i386/amd64-linux.xml i386/amd64-avx-linux.xml i386/amd
 
 # Linux object files.  This is so we don't have to repeat
 # these files over and over again.
-srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o"
+srv_linux_obj="linux-low.o linux-osdata.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o"
 
 # Input is taken from the "${target}" variable.
 
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 4d19c87..5e37dd5 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -27,6 +27,7 @@
 #include <sys/ptrace.h>
 #include "nat/linux-ptrace.h"
 #include "nat/linux-procfs.h"
+#include "nat/linux-personality.h"
 #include <signal.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
@@ -597,29 +598,11 @@ add_lwp (ptid_t ptid)
 static int
 linux_create_inferior (char *program, char **allargs)
 {
-#ifdef HAVE_PERSONALITY
-  int personality_orig = 0, personality_set = 0;
-#endif
   struct lwp_info *new_lwp;
   int pid;
   ptid_t ptid;
-
-#ifdef HAVE_PERSONALITY
-  if (disable_randomization)
-    {
-      errno = 0;
-      personality_orig = personality (0xffffffff);
-      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
-	{
-	  personality_set = 1;
-	  personality (personality_orig | ADDR_NO_RANDOMIZE);
-	}
-      if (errno != 0 || (personality_set
-			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
-	warning ("Error disabling address space randomization: %s",
-		 strerror (errno));
-    }
-#endif
+  struct cleanup *restore_personality
+    = maybe_disable_address_space_randomization (disable_randomization);
 
 #if defined(__UCLIBC__) && defined(HAS_NOMMU)
   pid = vfork ();
@@ -665,16 +648,7 @@ linux_create_inferior (char *program, char **allargs)
       _exit (0177);
     }
 
-#ifdef HAVE_PERSONALITY
-  if (personality_set)
-    {
-      errno = 0;
-      personality (personality_orig);
-      if (errno != 0)
-	warning ("Error restoring address space randomization: %s",
-		 strerror (errno));
-    }
-#endif
+  do_cleanups (restore_personality);
 
   linux_add_process (pid, 0);
 
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index a8a63cf..be52470 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -32,6 +32,7 @@
 #include "linux-nat.h"
 #include "nat/linux-ptrace.h"
 #include "nat/linux-procfs.h"
+#include "nat/linux-personality.h"
 #include "linux-fork.h"
 #include "gdbthread.h"
 #include "gdbcmd.h"
@@ -70,13 +71,6 @@
 #define SPUFS_MAGIC 0x23c9b64e
 #endif
 
-#ifdef HAVE_PERSONALITY
-# include <sys/personality.h>
-# if !HAVE_DECL_ADDR_NO_RANDOMIZE
-#  define ADDR_NO_RANDOMIZE 0x0040000
-# endif
-#endif /* HAVE_PERSONALITY */
-
 /* This comment documents high-level logic of this file.
 
 Waiting for events in sync mode
@@ -1103,45 +1097,18 @@ linux_nat_create_inferior (struct target_ops *ops,
 			   char *exec_file, char *allargs, char **env,
 			   int from_tty)
 {
-#ifdef HAVE_PERSONALITY
-  int personality_orig = 0, personality_set = 0;
-#endif /* HAVE_PERSONALITY */
+  struct cleanup *restore_personality
+    = maybe_disable_address_space_randomization (disable_randomization);
 
   /* The fork_child mechanism is synchronous and calls target_wait, so
      we have to mask the async mode.  */
 
-#ifdef HAVE_PERSONALITY
-  if (disable_randomization)
-    {
-      errno = 0;
-      personality_orig = personality (0xffffffff);
-      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
-	{
-	  personality_set = 1;
-	  personality (personality_orig | ADDR_NO_RANDOMIZE);
-	}
-      if (errno != 0 || (personality_set
-			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
-	warning (_("Error disabling address space randomization: %s"),
-		 safe_strerror (errno));
-    }
-#endif /* HAVE_PERSONALITY */
-
   /* Make sure we report all signals during startup.  */
   linux_nat_pass_signals (ops, 0, NULL);
 
   linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
 
-#ifdef HAVE_PERSONALITY
-  if (personality_set)
-    {
-      errno = 0;
-      personality (personality_orig);
-      if (errno != 0)
-	warning (_("Error restoring address space randomization: %s"),
-		 safe_strerror (errno));
-    }
-#endif /* HAVE_PERSONALITY */
+  do_cleanups (restore_personality);
 }
 
 /* Callback for linux_proc_attach_tgid_threads.  Attach to PTID if not
diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c
new file mode 100644
index 0000000..f61a2c6
--- /dev/null
+++ b/gdb/nat/linux-personality.c
@@ -0,0 +1,94 @@
+/* Disable address space randomization based on inferior personality.
+
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "common-defs.h"
+#include "nat/linux-personality.h"
+
+#ifdef HAVE_PERSONALITY
+# include <sys/personality.h>
+# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE
+#  define ADDR_NO_RANDOMIZE 0x0040000
+# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
+#endif /* HAVE_PERSONALITY */
+
+#ifdef HAVE_PERSONALITY
+
+/* Restore address space randomization of the inferior.  ARG is the
+   original inferior's personality value before the address space
+   randomization was disabled.  */
+
+static void
+restore_personality (void *arg)
+{
+  int personality_orig = (int) (uintptr_t) arg;
+
+  errno = 0;
+  personality (personality_orig);
+  if (errno != 0)
+    warning (_("Error restoring address space randomization: %s"),
+	     safe_strerror (errno));
+}
+#endif /* HAVE_PERSONALITY */
+
+/* Return a cleanup responsible for restoring the inferior's
+   personality (and restoring the inferior's address space
+   randomization) if HAVE_PERSONALITY and if PERSONALITY_SET is not
+   zero; return a null cleanup if not HAVE_PERSONALITY or if
+   PERSONALITY_SET is zero.  */
+
+static struct cleanup *
+make_disable_asr_cleanup (int personality_set, int personality_orig)
+{
+#ifdef HAVE_PERSONALITY
+  if (personality_set != 0)
+    return make_cleanup (restore_personality,
+			 (void *) (uintptr_t) personality_orig);
+#endif /* HAVE_PERSONALITY */
+
+  return make_cleanup (null_cleanup, NULL);
+}
+
+/* See comment on nat/linux-personality.h.  */
+
+struct cleanup *
+maybe_disable_address_space_randomization (int disable_randomization)
+{
+  int personality_orig = 0;
+  int personality_set = 0;
+
+#ifdef HAVE_PERSONALITY
+  if (disable_randomization)
+    {
+      errno = 0;
+      personality_orig = personality (0xffffffff);
+      if (errno == 0 && !(personality_orig & ADDR_NO_RANDOMIZE))
+	{
+	  personality_set = 1;
+	  personality (personality_orig | ADDR_NO_RANDOMIZE);
+	}
+      if (errno != 0 || (personality_set
+			 && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
+	warning (_("Error disabling address space randomization: %s"),
+		 safe_strerror (errno));
+    }
+#endif /* HAVE_PERSONALITY */
+
+  return make_disable_asr_cleanup (personality_set,
+				   personality_orig);
+}
diff --git a/gdb/nat/linux-personality.h b/gdb/nat/linux-personality.h
new file mode 100644
index 0000000..009e614
--- /dev/null
+++ b/gdb/nat/linux-personality.h
@@ -0,0 +1,31 @@
+/* Disable address space randomization based on inferior personality.
+
+   Copyright (C) 2008-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program 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 of the License, or
+   (at your option) any later version.
+
+   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef NAT_LINUX_PERSONALITY_H
+#define NAT_LINUX_PERSONALITY_H
+
+/* Disable the inferior's address space randomization if
+   DISABLE_RANDOMIZATION is not zero and if we have
+   <sys/personality.h>.  Return a cleanup which, when called, will
+   re-enable the inferior's address space randomization.  */
+
+extern struct cleanup *maybe_disable_address_space_randomization
+  (int disable_randomization);
+
+#endif /* ! NAT_LINUX_PERSONALITY_H */

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/2] Move safe_strerror to common/
  2015-01-15  7:05         ` Sergio Durigan Junior
@ 2015-01-15  9:02           ` Pedro Alves
  2015-01-16  0:04             ` Sergio Durigan Junior
  0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2015-01-15  9:02 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Gary Benson

On 01/15/2015 07:04 AM, Sergio Durigan Junior wrote:

> --- /dev/null
> +++ b/gdb/common/common.host

> +# Map host CPU into the common object files to be included by

s/CPU/triplet/.

OK with that change.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/2] Move safe_strerror to common/
  2015-01-15  9:02           ` Pedro Alves
@ 2015-01-16  0:04             ` Sergio Durigan Junior
  0 siblings, 0 replies; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-16  0:04 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Gary Benson

On Thursday, January 15 2015, Pedro Alves wrote:

> On 01/15/2015 07:04 AM, Sergio Durigan Junior wrote:
>
>> --- /dev/null
>> +++ b/gdb/common/common.host
>
>> +# Map host CPU into the common object files to be included by
>
> s/CPU/triplet/.
>
> OK with that change.

Pushed, thanks.

  <https://sourceware.org/ml/gdb-cvs/2015-01/msg00125.html>
  fb23d554428f1d379fd8c3e959a294108fa59f88

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-14 11:32       ` Pedro Alves
  2015-01-15  7:06         ` Sergio Durigan Junior
@ 2015-01-16  0:04         ` Sergio Durigan Junior
  1 sibling, 0 replies; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-16  0:04 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Gary Benson

On Wednesday, January 14 2015, Pedro Alves wrote:

> Otherwise looks good.  Thanks.

Pushed, thanks.

  <https://sourceware.org/ml/gdb-cvs/2015-01/msg00126.html>
  8cc73a3902a68269626274e15d7c25bef0a61759

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/2] Move code to disable ASR to nat/
  2015-01-09 22:19 ` [PATCH 2/2] Move code to disable ASR to nat/ Sergio Durigan Junior
  2015-01-13 17:11   ` Pedro Alves
@ 2015-01-16 15:39   ` Ulrich Weigand
  2015-01-16 16:47     ` [PATCH][commit] Fix regression on RHEL-5 systems (was: Re: [PATCH 2/2] Move code to disable ASR to nat/) Sergio Durigan Junior
  1 sibling, 1 reply; 17+ messages in thread
From: Ulrich Weigand @ 2015-01-16 15:39 UTC (permalink / raw)
  To: Sergio Durigan Junior
  Cc: GDB Patches, Pedro Alves, Gary Benson, Sergio Durigan Junior

Sergio Durigan Junior wrote:

> This patch moves the shared code present on
> gdb/linux-nat.c:linux_nat_create_inferior and
> gdb/gdbserver/linux-low.c:linux_create_inferior to
> nat/linux-personality.c.  This code is responsible for disabling
> address space randomization based on user setting, and using
> <sys/personality.h> to do that.  I decided to put the prototype of the
> maybe_disable_address_space_randomization on nat/linux-osdata.h
> because it seemed the best place to put it.

This breaks building on my RHEL 5 machine:

/home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c: In function 'maybe_disable_address_space_randomization':
/home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: 'ADDR_NO_RANDOMIZE' undeclared (first use in this function)
/home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: (Each undeclared identifier is reported only once
/home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: for each function it appears in.)

It looks like this is because you replaced:
> -# if !HAVE_DECL_ADDR_NO_RANDOMIZE
by:
> +# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE

but config.h on my machine without ADDR_NO_RANDOMIZE contains:
#define HAVE_DECL_ADDR_NO_RANDOMIZE 0

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH][commit] Fix regression on RHEL-5 systems (was: Re: [PATCH 2/2] Move code to disable ASR to nat/)
  2015-01-16 15:39   ` Ulrich Weigand
@ 2015-01-16 16:47     ` Sergio Durigan Junior
  2015-01-19 19:16       ` Ulrich Weigand
  0 siblings, 1 reply; 17+ messages in thread
From: Sergio Durigan Junior @ 2015-01-16 16:47 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: GDB Patches, Pedro Alves, Gary Benson

On Friday, January 16 2015, Ulrich Weigand wrote:

> Sergio Durigan Junior wrote:
>
>> This patch moves the shared code present on
>> gdb/linux-nat.c:linux_nat_create_inferior and
>> gdb/gdbserver/linux-low.c:linux_create_inferior to
>> nat/linux-personality.c.  This code is responsible for disabling
>> address space randomization based on user setting, and using
>> <sys/personality.h> to do that.  I decided to put the prototype of the
>> maybe_disable_address_space_randomization on nat/linux-osdata.h
>> because it seemed the best place to put it.
>
> This breaks building on my RHEL 5 machine:
>
> /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c: In function 'maybe_disable_address_space_randomization':
> /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: 'ADDR_NO_RANDOMIZE' undeclared (first use in this function)
> /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: (Each undeclared identifier is reported only once
> /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: for each function it appears in.)

Ops.  Thanks for letting me know, Ulrich.

> It looks like this is because you replaced:
>> -# if !HAVE_DECL_ADDR_NO_RANDOMIZE
> by:
>> +# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE
>
> but config.h on my machine without ADDR_NO_RANDOMIZE contains:
> #define HAVE_DECL_ADDR_NO_RANDOMIZE 0

I took the liberty to go ahead and push the following patch as obvious.
Please let me know if there is anything else needed.

Thanks,

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

commit 4c347be60a1c25f78826fbf86d416a278740145b
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Fri Jan 16 11:42:28 2015 -0500

    Fix nat/linux-personality.c regression on RHEL-5
    
    This commit fixes the regression on RHEL-5 systems introduced by
    nat/linux-personality.c's check of HAVE_DECL_ADDR_NO_RANDOMIZE.
    RHEL-5 systems define HAVE_DECL_ADDR_NO_RANDOMIZE as zero, so we
    cannot use #ifndef; instead this patch uses the "#if !" construction.
    
    The regression was reported by Ulrich Weigand here:
    
      <https://sourceware.org/ml/gdb-patches/2015-01/msg00458.html>
    
    gdb/ChangeLog
    2015-01-16  Sergio Durigan Junior  <sergiodj@redhat.com>
    
    	* nat/linux-personality.c: Replace "#ifndef
    	HAVE_DECL_ADDR_NO_RANDOMIZE" by "#if
    	!HAVE_DECL_ADDR_NO_RANDOMIZE", fixing a regression in RHEL-5
    	systems.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b7ba1b2..b95abdc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-16  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* nat/linux-personality.c: Replace "#ifndef
+	HAVE_DECL_ADDR_NO_RANDOMIZE" by "#if
+	!HAVE_DECL_ADDR_NO_RANDOMIZE", fixing a regression in RHEL-5
+	systems.
+
 2015-01-16  Eli Zaretskii  <eliz@gnu.org>
 
 	* tui/tui-win.c (tui_rehighlight_all, tui_set_var_cmd): New
diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c
index f61a2c6..3ea8755 100644
--- a/gdb/nat/linux-personality.c
+++ b/gdb/nat/linux-personality.c
@@ -22,7 +22,7 @@
 
 #ifdef HAVE_PERSONALITY
 # include <sys/personality.h>
-# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE
+# if !HAVE_DECL_ADDR_NO_RANDOMIZE
 #  define ADDR_NO_RANDOMIZE 0x0040000
 # endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
 #endif /* HAVE_PERSONALITY */

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH][commit] Fix regression on RHEL-5 systems (was: Re: [PATCH 2/2] Move code to disable ASR to nat/)
  2015-01-16 16:47     ` [PATCH][commit] Fix regression on RHEL-5 systems (was: Re: [PATCH 2/2] Move code to disable ASR to nat/) Sergio Durigan Junior
@ 2015-01-19 19:16       ` Ulrich Weigand
  0 siblings, 0 replies; 17+ messages in thread
From: Ulrich Weigand @ 2015-01-19 19:16 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Pedro Alves, Gary Benson

Sergio Durigan Junior wrote:
> On Friday, January 16 2015, Ulrich Weigand wrote:
> > /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c: In function 'maybe_disable_address_space_randomization':
> > /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: 'ADDR_NO_RANDOMIZE' undeclared (first use in this function)
> > /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: (Each undeclared identifier is reported only once
> > /home/uweigand/dailybuild/spu-tc-2015-01-15/binutils-gdb-head/binutils-gdb/gdb/nat/linux-personality.c:80: error: for each function it appears in.)
> 
> Ops.  Thanks for letting me know, Ulrich.
> 
> > It looks like this is because you replaced:
> >> -# if !HAVE_DECL_ADDR_NO_RANDOMIZE
> > by:
> >> +# ifndef HAVE_DECL_ADDR_NO_RANDOMIZE
> >
> > but config.h on my machine without ADDR_NO_RANDOMIZE contains:
> > #define HAVE_DECL_ADDR_NO_RANDOMIZE 0
> 
> I took the liberty to go ahead and push the following patch as obvious.
> Please let me know if there is anything else needed.

Thanks, this does fix the problem for me.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2015-01-19 19:16 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-09 22:19 [PATCH 0/2] Share code to disable ASR between GDB and gdbserver Sergio Durigan Junior
2015-01-09 22:19 ` [PATCH 2/2] Move code to disable ASR to nat/ Sergio Durigan Junior
2015-01-13 17:11   ` Pedro Alves
2015-01-13 20:55     ` Sergio Durigan Junior
2015-01-14 11:32       ` Pedro Alves
2015-01-15  7:06         ` Sergio Durigan Junior
2015-01-16  0:04         ` Sergio Durigan Junior
2015-01-16 15:39   ` Ulrich Weigand
2015-01-16 16:47     ` [PATCH][commit] Fix regression on RHEL-5 systems (was: Re: [PATCH 2/2] Move code to disable ASR to nat/) Sergio Durigan Junior
2015-01-19 19:16       ` Ulrich Weigand
2015-01-09 22:19 ` [PATCH 1/2] Move safe_strerror to common/ Sergio Durigan Junior
2015-01-13 16:54   ` Pedro Alves
2015-01-13 20:48     ` Sergio Durigan Junior
2015-01-14 11:26       ` Pedro Alves
2015-01-15  7:05         ` Sergio Durigan Junior
2015-01-15  9:02           ` Pedro Alves
2015-01-16  0:04             ` Sergio Durigan Junior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).