public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Matthew Fortune <Matthew.Fortune@imgtec.com>
To: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Cc: "Sandra Loosemore (sandra@codesourcery.com)"
	<sandra@codesourcery.com>,
	"Joseph Myers (joseph@codesourcery.com)"
	<joseph@codesourcery.com>,
	"Petar Jovanovic" <Petar.Jovanovic@imgtec.com>
Subject: [PATCH] Initialise the machine specific part of rtld bootstrap map
Date: Wed, 26 Oct 2016 19:54:00 -0000	[thread overview]
Message-ID: <6D39441BF12EF246A7ABCE6654B0235380AABFF9@HHMAIL01.hh.imgtec.org> (raw)

Hi,

This is a long delayed follow up to a patch by Sandra:
https://sourceware.org/ml/libc-alpha/2015-03/msg00704.html

I've reimplemented it to be MIPS specific and lightweight to just
initialise the necessary fields. Tested using mips64el-linux-gnu (n64)
with some manual verification to make sure I saw the loader failures if I
initialised the fpabi to an illegal value instead of zero.

MIPS requires two fields in the machine specific part of the link map to
be zero initialised.  This is natually achieved except when the map is
allocated on the stack.  The only map allocated on the stack is the
bootstrap map which is often the first use of the stack space following
kernel allocation and is therefore zero.  However, if rtld is invoked
such that the stack has already been used then there may be non-zero
data and ABI checks which use the affected fields will spuriously fail.

	* elf/rtld.c (_dl_start) [ifndef DONT_USE_BOOTSTRAP_MAP]: Call
	ELF_MACHINE_INIT_MAP.
	* sysdeps/mips/dl-machine.h (ELF_MACHINE_INIT_MAP): Define macro.

Thanks,
Matthew

---
 elf/rtld.c                | 3 +++
 sysdeps/mips/dl-machine.h | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/elf/rtld.c b/elf/rtld.c
index 647661c..31539a4 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -364,6 +364,9 @@ _dl_start (void *arg)
      do not have to use the temporary bootstrap_map.  Global variables
      are initialized to zero by default.  */
 #ifndef DONT_USE_BOOTSTRAP_MAP
+# ifdef ELF_MACHINE_INIT_MAP
+  ELF_MACHINE_INIT_MAP (bootstrap_map);
+# endif
 # ifdef HAVE_BUILTIN_MEMSET
   __builtin_memset (bootstrap_map.l_info, '\0', sizeof (bootstrap_map.l_info));
 # else
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
index 8c0b40e..d929477 100644
--- a/sysdeps/mips/dl-machine.h
+++ b/sysdeps/mips/dl-machine.h
@@ -93,6 +93,13 @@ do { if ((l)->l_info[DT_MIPS (RLD_MAP_REL)]) \
 # define ELF_MACHINE_NAN2008 0
 #endif
 
+/* Initialise the machine dependent parts of a map.  This is not normally
+   required unless the map is allocated on the stack.  */
+#define ELF_MACHINE_INIT_MAP(MAP) \
+do { (MAP)->l_mach.fpabi = 0; \
+     (MAP)->l_mach.odd_spreg = 0; \
+   } while (0)
+
 /* Return nonzero iff ELF header is compatible with the running host.  */
 static inline int __attribute_used__
 elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
-- 
2.2.1

             reply	other threads:[~2016-10-26 19:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26 19:54 Matthew Fortune [this message]
2016-10-26 20:12 ` Joseph Myers
2016-10-26 21:01   ` Matthew Fortune
2016-10-26 21:07     ` Sandra Loosemore
2016-10-26 21:22       ` Matthew Fortune
2016-10-28 12:46       ` Matthew Fortune
2016-10-26 21:37     ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6D39441BF12EF246A7ABCE6654B0235380AABFF9@HHMAIL01.hh.imgtec.org \
    --to=matthew.fortune@imgtec.com \
    --cc=Petar.Jovanovic@imgtec.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=sandra@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).