[Buildroot] [RFC v1 2/2] package/gdb: gdb-11.1 compile for uclibc (ADDR_NO_RANDOMIZE related)

Peter Seiderer ps.report at gmx.net
Sat Nov 6 12:22:15 UTC 2021


On Sat,  6 Nov 2021 13:09:35 +0100, Peter Seiderer <ps.report at gmx.net> wrote:

> - add patch reverting upstream patch ([1]) which removed the configure
>   time check
> 
> Fixes:
> 
>   ../../gdbserver/../gdb/nat/linux-personality.c: In constructor ‘maybe_disable_address_space_randomization::maybe_disable_address_space_randomization(int)’:
>   ../../gdbserver/../gdb/nat/linux-personality.c:36:48: error: ‘ADDR_NO_RANDOMIZE’ was not declared in this scope
>      36 |       if (errno == 0 && !(m_personality_orig & ADDR_NO_RANDOMIZE))
>         |                                                ^~~~~~~~~~~~~~~~~
>   ../../gdbserver/../gdb/nat/linux-personality.c:42:37: error: ‘ADDR_NO_RANDOMIZE’ was not declared in this scope
>      42 |     && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
>         |                                     ^~~~~~~~~~~~~~~~~
> 
> [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=4655f8509fd44e6efabefa373650d9982ff37fd6
> 
> Signed-off-by: Peter Seiderer <ps.report at gmx.net>
> ---
> Note:
> 
>  - a quick fix, the proper fix would be (as mentioned in the upstream
>    commit changelog:
> 
>     [...]
>     If for some odd reason, some remotely modern system still needs a
>     configure check, then we can revert this commit but drop the
>     AC_RUN_IFELSE in favor of always doing the AC_LINK_IFELSE
>     cross-compile fallback.
>     [...]

And reported upstream:

	https://sourceware.org/bugzilla/show_bug.cgi?id=28555

Regards,
Peter

> ---
>  ...-personality-syscall-at-configure-ti.patch | 371 ++++++++++++++++++
>  1 file changed, 371 insertions(+)
>  create mode 100644 package/gdb/11.1/0008-Revert-Don-t-run-personality-syscall-at-configure-ti.patch
> 
> diff --git a/package/gdb/11.1/0008-Revert-Don-t-run-personality-syscall-at-configure-ti.patch b/package/gdb/11.1/0008-Revert-Don-t-run-personality-syscall-at-configure-ti.patch
> new file mode 100644
> index 0000000000..d674287b57
> --- /dev/null
> +++ b/package/gdb/11.1/0008-Revert-Don-t-run-personality-syscall-at-configure-ti.patch
> @@ -0,0 +1,371 @@
> +From c26b279aa4c7dc8a0cd9e30d2e43e6b95cefb5a0 Mon Sep 17 00:00:00 2001
> +From: Peter Seiderer <ps.report at gmx.net>
> +Date: Sat, 6 Nov 2021 12:54:42 +0100
> +Subject: [PATCH] Revert "Don't run personality syscall at configure time;
> + don't check it at all"
> +MIME-Version: 1.0
> +Content-Type: text/plain; charset=UTF-8
> +Content-Transfer-Encoding: 8bit
> +
> +This reverts commit 4655f8509fd44e6efabefa373650d9982ff37fd6 ([1]).
> +
> +Fixes (with uclibc toolchain):
> +
> +  ../../gdbserver/../gdb/nat/linux-personality.c: In constructor ‘maybe_disable_address_space_randomization::maybe_disable_address_space_randomization(int)’:
> +  ../../gdbserver/../gdb/nat/linux-personality.c:36:48: error: ‘ADDR_NO_RANDOMIZE’ was not declared in this scope
> +     36 |       if (errno == 0 && !(m_personality_orig & ADDR_NO_RANDOMIZE))
> +        |                                                ^~~~~~~~~~~~~~~~~
> +  ../../gdbserver/../gdb/nat/linux-personality.c:42:37: error: ‘ADDR_NO_RANDOMIZE’ was not declared in this scope
> +     42 |     && !(personality (0xffffffff) & ADDR_NO_RANDOMIZE)))
> +        |                                     ^~~~~~~~~~~~~~~~~
> +
> +[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=4655f8509fd44e6efabefa373650d9982ff37fd6
> +
> +Signed-off-by: Peter Seiderer <ps.report at gmx.net>
> +---
> + gdb/config.in               |  7 ++++
> + gdb/configure               | 74 +++++++++++++++++++++++++++++++++++++
> + gdb/linux-nat.c             |  4 ++
> + gdb/nat/linux-personality.c | 12 +++++-
> + gdbserver/config.in         |  7 ++++
> + gdbserver/configure         | 74 +++++++++++++++++++++++++++++++++++++
> + gdbserver/linux-low.cc      |  4 ++
> + gdbsupport/common.m4        | 23 ++++++++++++
> + 8 files changed, 204 insertions(+), 1 deletion(-)
> +
> +diff --git a/gdb/config.in b/gdb/config.in
> +index 2c30504..eee0eaf 100644
> +--- a/gdb/config.in
> ++++ b/gdb/config.in
> +@@ -96,6 +96,10 @@
> + /* define if the compiler supports basic C++11 syntax */
> + #undef HAVE_CXX11
> + 
> ++/* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if
> ++   you don't. */
> ++#undef HAVE_DECL_ADDR_NO_RANDOMIZE
> ++
> + /* Define to 1 if you have the declaration of `asprintf', and to 0 if you
> +    don't. */
> + #undef HAVE_DECL_ASPRINTF
> +@@ -297,6 +301,9 @@
> + /* Define to 1 if you have the <nlist.h> header file. */
> + #undef HAVE_NLIST_H
> + 
> ++/* Define if you support the personality syscall. */
> ++#undef HAVE_PERSONALITY
> ++
> + /* Define to 1 if you have the `pipe' function. */
> + #undef HAVE_PIPE
> + 
> +diff --git a/gdb/configure b/gdb/configure
> +index 5d89635..599521a 100755
> +--- a/gdb/configure
> ++++ b/gdb/configure
> +@@ -13838,6 +13838,80 @@ fi
> + done
> + 
> + 
> ++      ac_fn_c_check_decl "$LINENO" "ADDR_NO_RANDOMIZE" "ac_cv_have_decl_ADDR_NO_RANDOMIZE" "#include <sys/personality.h>
> ++"
> ++if test "x$ac_cv_have_decl_ADDR_NO_RANDOMIZE" = xyes; then :
> ++  ac_have_decl=1
> ++else
> ++  ac_have_decl=0
> ++fi
> ++
> ++cat >>confdefs.h <<_ACEOF
> ++#define HAVE_DECL_ADDR_NO_RANDOMIZE $ac_have_decl
> ++_ACEOF
> ++
> ++
> ++  if test "$cross_compiling" = yes; then :
> ++  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> ++/* end confdefs.h.  */
> ++#include <sys/personality.h>
> ++int
> ++main ()
> ++{
> ++
> ++  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
> ++  #       define ADDR_NO_RANDOMIZE 0x0040000
> ++  #      endif
> ++	 /* Test the flag could be set and stays set.  */
> ++	 personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
> ++	 if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
> ++	     return 1
> ++  ;
> ++  return 0;
> ++}
> ++_ACEOF
> ++if ac_fn_c_try_link "$LINENO"; then :
> ++  have_personality=true
> ++else
> ++  have_personality=false
> ++fi
> ++rm -f core conftest.err conftest.$ac_objext \
> ++    conftest$ac_exeext conftest.$ac_ext
> ++else
> ++  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> ++/* end confdefs.h.  */
> ++#include <sys/personality.h>
> ++int
> ++main ()
> ++{
> ++
> ++  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
> ++  #       define ADDR_NO_RANDOMIZE 0x0040000
> ++  #      endif
> ++	 /* Test the flag could be set and stays set.  */
> ++	 personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
> ++	 if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
> ++	     return 1
> ++  ;
> ++  return 0;
> ++}
> ++_ACEOF
> ++if ac_fn_c_try_run "$LINENO"; then :
> ++  have_personality=true
> ++else
> ++  have_personality=false
> ++fi
> ++rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
> ++  conftest.$ac_objext conftest.beam conftest.$ac_ext
> ++fi
> ++
> ++  if $have_personality
> ++  then
> ++
> ++$as_echo "#define HAVE_PERSONALITY 1" >>confdefs.h
> ++
> ++  fi
> ++
> +   ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
> + if test "x$ac_cv_have_decl_strstr" = xyes; then :
> +   ac_have_decl=1
> +diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
> +index f206b87..1a6bcb5 100644
> +--- a/gdb/linux-nat.c
> ++++ b/gdb/linux-nat.c
> +@@ -4195,7 +4195,11 @@ linux_nat_target::supports_multi_process ()
> + bool
> + linux_nat_target::supports_disable_randomization ()
> + {
> ++#ifdef HAVE_PERSONALITY
> +   return true;
> ++#else
> ++  return false;
> ++#endif
> + }
> + 
> + /* SIGCHLD handler that serves two purposes: In non-stop/async mode,
> +diff --git a/gdb/nat/linux-personality.c b/gdb/nat/linux-personality.c
> +index 9ce345b..87d1921 100644
> +--- a/gdb/nat/linux-personality.c
> ++++ b/gdb/nat/linux-personality.c
> +@@ -20,7 +20,12 @@
> + #include "gdbsupport/common-defs.h"
> + #include "nat/linux-personality.h"
> + 
> +-#include <sys/personality.h>
> ++#ifdef HAVE_PERSONALITY
> ++# include <sys/personality.h>
> ++# if !HAVE_DECL_ADDR_NO_RANDOMIZE
> ++#  define ADDR_NO_RANDOMIZE 0x0040000
> ++# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
> ++#endif /* HAVE_PERSONALITY */
> + 
> + /* See comment on nat/linux-personality.h.  */
> + 
> +@@ -29,6 +34,7 @@ maybe_disable_address_space_randomization (int disable_randomization)
> +   : m_personality_set (false),
> +     m_personality_orig (0)
> + {
> ++#ifdef HAVE_PERSONALITY
> +   if (disable_randomization)
> +     {
> +       errno = 0;
> +@@ -43,11 +49,14 @@ maybe_disable_address_space_randomization (int disable_randomization)
> + 	warning (_("Error disabling address space randomization: %s"),
> + 		 safe_strerror (errno));
> +     }
> ++#endif /* HAVE_PERSONALITY */
> + }
> + 
> + maybe_disable_address_space_randomization::
> + ~maybe_disable_address_space_randomization ()
> + {
> ++#ifdef HAVE_PERSONALITY
> ++
> +   if (m_personality_set)
> +     {
> +       errno = 0;
> +@@ -56,4 +65,5 @@ maybe_disable_address_space_randomization::
> + 	warning (_("Error restoring address space randomization: %s"),
> + 		 safe_strerror (errno));
> +     }
> ++#endif /* HAVE_PERSONALITY */
> + }
> +diff --git a/gdbserver/config.in b/gdbserver/config.in
> +index cf06c56..b55ddc1 100644
> +--- a/gdbserver/config.in
> ++++ b/gdbserver/config.in
> +@@ -31,6 +31,10 @@
> + /* define if the compiler supports basic C++11 syntax */
> + #undef HAVE_CXX11
> + 
> ++/* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if
> ++   you don't. */
> ++#undef HAVE_DECL_ADDR_NO_RANDOMIZE
> ++
> + /* Define to 1 if you have the declaration of `asprintf', and to 0 if you
> +    don't. */
> + #undef HAVE_DECL_ASPRINTF
> +@@ -178,6 +182,9 @@
> + /* Define to 1 if you have the <netinet/tcp.h> header file. */
> + #undef HAVE_NETINET_TCP_H
> + 
> ++/* Define if you support the personality syscall. */
> ++#undef HAVE_PERSONALITY
> ++
> + /* Define to 1 if you have the `pipe' function. */
> + #undef HAVE_PIPE
> + 
> +diff --git a/gdbserver/configure b/gdbserver/configure
> +index b227167..c566ab7 100755
> +--- a/gdbserver/configure
> ++++ b/gdbserver/configure
> +@@ -7131,6 +7131,80 @@ fi
> + done
> + 
> + 
> ++      ac_fn_c_check_decl "$LINENO" "ADDR_NO_RANDOMIZE" "ac_cv_have_decl_ADDR_NO_RANDOMIZE" "#include <sys/personality.h>
> ++"
> ++if test "x$ac_cv_have_decl_ADDR_NO_RANDOMIZE" = xyes; then :
> ++  ac_have_decl=1
> ++else
> ++  ac_have_decl=0
> ++fi
> ++
> ++cat >>confdefs.h <<_ACEOF
> ++#define HAVE_DECL_ADDR_NO_RANDOMIZE $ac_have_decl
> ++_ACEOF
> ++
> ++
> ++  if test "$cross_compiling" = yes; then :
> ++  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> ++/* end confdefs.h.  */
> ++#include <sys/personality.h>
> ++int
> ++main ()
> ++{
> ++
> ++  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
> ++  #       define ADDR_NO_RANDOMIZE 0x0040000
> ++  #      endif
> ++	 /* Test the flag could be set and stays set.  */
> ++	 personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
> ++	 if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
> ++	     return 1
> ++  ;
> ++  return 0;
> ++}
> ++_ACEOF
> ++if ac_fn_c_try_link "$LINENO"; then :
> ++  have_personality=true
> ++else
> ++  have_personality=false
> ++fi
> ++rm -f core conftest.err conftest.$ac_objext \
> ++    conftest$ac_exeext conftest.$ac_ext
> ++else
> ++  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> ++/* end confdefs.h.  */
> ++#include <sys/personality.h>
> ++int
> ++main ()
> ++{
> ++
> ++  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
> ++  #       define ADDR_NO_RANDOMIZE 0x0040000
> ++  #      endif
> ++	 /* Test the flag could be set and stays set.  */
> ++	 personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
> ++	 if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
> ++	     return 1
> ++  ;
> ++  return 0;
> ++}
> ++_ACEOF
> ++if ac_fn_c_try_run "$LINENO"; then :
> ++  have_personality=true
> ++else
> ++  have_personality=false
> ++fi
> ++rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
> ++  conftest.$ac_objext conftest.beam conftest.$ac_ext
> ++fi
> ++
> ++  if $have_personality
> ++  then
> ++
> ++$as_echo "#define HAVE_PERSONALITY 1" >>confdefs.h
> ++
> ++  fi
> ++
> +   ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
> + if test "x$ac_cv_have_decl_strstr" = xyes; then :
> +   ac_have_decl=1
> +diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
> +index 5c6191d..ca0c513 100644
> +--- a/gdbserver/linux-low.cc
> ++++ b/gdbserver/linux-low.cc
> +@@ -6224,7 +6224,11 @@ linux_process_target::core_of_thread (ptid_t ptid)
> + bool
> + linux_process_target::supports_disable_randomization ()
> + {
> ++#ifdef HAVE_PERSONALITY
> +   return true;
> ++#else
> ++  return false;
> ++#endif
> + }
> + 
> + bool
> +diff --git a/gdbsupport/common.m4 b/gdbsupport/common.m4
> +index 901c454..be925b4 100644
> +--- a/gdbsupport/common.m4
> ++++ b/gdbsupport/common.m4
> +@@ -55,6 +55,29 @@ AC_DEFUN([GDB_AC_COMMON], [
> + 		  ptrace64 sbrk setns sigaltstack sigprocmask \
> + 		  setpgid setpgrp getrusage getauxval sigtimedwait])
> + 
> ++  dnl Check if we can disable the virtual address space randomization.
> ++  dnl The functionality of setarch -R.
> ++  AC_CHECK_DECLS([ADDR_NO_RANDOMIZE],,, [#include <sys/personality.h>])
> ++  define([PERSONALITY_TEST], [AC_LANG_PROGRAM([#include <sys/personality.h>], [
> ++  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
> ++  #       define ADDR_NO_RANDOMIZE 0x0040000
> ++  #      endif
> ++	 /* Test the flag could be set and stays set.  */
> ++	 personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
> ++	 if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
> ++	     return 1])])
> ++  AC_RUN_IFELSE([PERSONALITY_TEST],
> ++		[have_personality=true],
> ++		[have_personality=false],
> ++		[AC_LINK_IFELSE([PERSONALITY_TEST],
> ++				[have_personality=true],
> ++				[have_personality=false])])
> ++  if $have_personality
> ++  then
> ++      AC_DEFINE([HAVE_PERSONALITY], 1,
> ++		[Define if you support the personality syscall.])
> ++  fi
> ++
> +   AC_CHECK_DECLS([strstr])
> + 
> +   # ----------------------- #
> +-- 
> +2.33.1
> +




More information about the buildroot mailing list