Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Oct 2008 20:24:04 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r183841 - head/libexec/rtld-elf/mips
Message-ID:  <200810132024.m9DKO4eO085447@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Mon Oct 13 20:24:03 2008
New Revision: 183841
URL: http://svn.freebsd.org/changeset/base/183841

Log:
  This code has no copyright.  It is fairly obvious to me that we're a
  derivitive of NetBSD's mips_reloc.c, so pull in the copyright notice
  from there.
  
  Also, a minor tweak to load/store pointers.  Other changes from NetBSD
  likely would be useful too...
  
  Obtained from:	NetBSD

Modified:
  head/libexec/rtld-elf/mips/reloc.c

Modified: head/libexec/rtld-elf/mips/reloc.c
==============================================================================
--- head/libexec/rtld-elf/mips/reloc.c	Mon Oct 13 20:07:13 2008	(r183840)
+++ head/libexec/rtld-elf/mips/reloc.c	Mon Oct 13 20:24:03 2008	(r183841)
@@ -1,4 +1,33 @@
 /*	$NetBSD: mdreloc.c,v 1.23 2003/07/26 15:04:38 mrg Exp $	*/
+/*	$NetBSD: mips_reloc.c,v 1.53 2008/07/24 04:39:25 matt Exp $	*/
+
+/*
+ * Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
+ * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
@@ -35,21 +64,33 @@ void _rtld_relocate_nonplt_self(Elf_Dyn 
 int open();
 int _open();
 
+/*
+ * It is possible for the compiler to emit relocations for unaligned data.
+ * We handle this situation with these inlines.
+ */
+#define	RELOC_ALIGNED_P(x) \
+	(((uintptr_t)(x) & (sizeof(void *) - 1)) == 0)
+
 static __inline Elf_Addr
 load_ptr(void *where)
 {
-	Elf_Addr res;
-
-	memcpy(&res, where, sizeof(res));
+	if (__predict_true(RELOC_ALIGNED_P(where)))
+		return *(Elf_Addr *)where;
+	else {
+		Elf_Addr res;
 
-	return (res);
+		(void)memcpy(&res, where, sizeof(res));
+		return res;
+	}
 }
 
-void
+static __inline void
 store_ptr(void *where, Elf_Addr val)
 {
-
-	memcpy(where, &val, sizeof(val));
+	if (__predict_true(RELOC_ALIGNED_P(where)))
+		*(Elf_Addr *)where = val;
+	else
+		(void)memcpy(where, &val, sizeof(val));
 }
 
 void
@@ -149,13 +190,6 @@ _mips_rtld_bind(Obj_Entry *obj, Elf_Size
 }
 
 /*
- * It is possible for the compiler to emit relocations for unaligned data.
- * We handle this situation with these inlines.
- */
-#define	RELOC_ALIGNED_P(x) \
-	(((uintptr_t)(x) & (sizeof(void *) - 1)) == 0)
-
-/*
  * Process non-PLT relocations
  */
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810132024.m9DKO4eO085447>