Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src Apply patch (request by skrll in ticket #1702):



details:   https://anonhg.NetBSD.org/src/rev/c7ee35ce59eb
branches:  netbsd-1-6
changeset: 531359:c7ee35ce59eb
user:      tron <tron%NetBSD.org@localhost>
date:      Fri May 28 08:31:22 2004 +0000

description:
Apply patch (request by skrll in ticket #1702):
Bring "ld.elf_so" (mostly) in sync with NetBSD-current:
- MI and MD (e.g. under NetBSD-alpha) performance improvements
- RTLD_SELF, RTLD_NEXT, RTLD_DEFAULT support
- much better structured code
- closes PR bin/25464

diffstat:

 libexec/ld.elf_so/Makefile                  |   47 +-
 libexec/ld.elf_so/README                    |   44 +-
 libexec/ld.elf_so/TODO                      |   33 +
 libexec/ld.elf_so/arch/alpha/Makefile.inc   |   13 +-
 libexec/ld.elf_so/arch/alpha/alpha_reloc.c  |  379 ++++++++++++-
 libexec/ld.elf_so/arch/alpha/ld.so.script   |  134 ----
 libexec/ld.elf_so/arch/alpha/rtld_start.S   |   57 +-
 libexec/ld.elf_so/arch/arm/Makefile.inc     |   10 +-
 libexec/ld.elf_so/arch/arm/mdreloc.c        |  258 ++++++++
 libexec/ld.elf_so/arch/arm/rtld_start.S     |   25 +-
 libexec/ld.elf_so/arch/i386/Makefile.inc    |   10 +-
 libexec/ld.elf_so/arch/i386/mdreloc.c       |  223 +++++++
 libexec/ld.elf_so/arch/i386/rtld_start.S    |   45 +-
 libexec/ld.elf_so/arch/m68k/Makefile.inc    |   10 +-
 libexec/ld.elf_so/arch/m68k/mdreloc.c       |  176 ++++++
 libexec/ld.elf_so/arch/m68k/rtld_start.S    |   25 +-
 libexec/ld.elf_so/arch/mips/Makefile.inc    |   18 +-
 libexec/ld.elf_so/arch/mips/ld.so.script    |  151 -----
 libexec/ld.elf_so/arch/mips/mips_reloc.c    |  370 ++++++++++--
 libexec/ld.elf_so/arch/mips/rtld_start.S    |   57 +-
 libexec/ld.elf_so/arch/powerpc/Makefile.inc |   12 +-
 libexec/ld.elf_so/arch/powerpc/ld.so.script |  272 +++++++--
 libexec/ld.elf_so/arch/powerpc/ppc_reloc.c  |  312 +++++++---
 libexec/ld.elf_so/arch/powerpc/rtld_start.S |  136 ++--
 libexec/ld.elf_so/arch/sh3/Makefile.inc     |   12 +-
 libexec/ld.elf_so/arch/sh3/mdreloc.c        |  206 +++++++
 libexec/ld.elf_so/arch/sh3/rtld_start.S     |   65 +-
 libexec/ld.elf_so/arch/sparc/Makefile.inc   |   10 +-
 libexec/ld.elf_so/arch/sparc/mdreloc.c      |  269 +++++---
 libexec/ld.elf_so/arch/sparc/rtld_start.S   |   40 +-
 libexec/ld.elf_so/arch/sparc64/Makefile.inc |   10 +-
 libexec/ld.elf_so/arch/sparc64/mdreloc.c    |  513 ++++++++++-------
 libexec/ld.elf_so/arch/sparc64/rtld_start.S |  109 +-
 libexec/ld.elf_so/arch/vax/Makefile.inc     |   10 +-
 libexec/ld.elf_so/arch/vax/mdreloc.c        |  163 +++++
 libexec/ld.elf_so/arch/vax/rtld_start.S     |   36 +-
 libexec/ld.elf_so/arch/x86_64/Makefile.inc  |   10 +-
 libexec/ld.elf_so/arch/x86_64/mdreloc.c     |  292 +++++----
 libexec/ld.elf_so/arch/x86_64/rtld_start.S  |   20 +-
 libexec/ld.elf_so/debug.c                   |   24 +-
 libexec/ld.elf_so/debug.h                   |    6 +-
 libexec/ld.elf_so/headers.c                 |   87 +-
 libexec/ld.elf_so/ld.elf_so.1               |   81 +-
 libexec/ld.elf_so/load.c                    |  100 +--
 libexec/ld.elf_so/malloc.c                  |   40 +-
 libexec/ld.elf_so/map_object.c              |  264 ++++----
 libexec/ld.elf_so/paths.c                   |  339 ++++++-----
 libexec/ld.elf_so/reloc.c                   |  804 +--------------------------
 libexec/ld.elf_so/rtld.c                    |  501 +++++++---------
 libexec/ld.elf_so/rtld.h                    |  169 ++---
 libexec/ld.elf_so/rtldenv.h                 |   36 +-
 libexec/ld.elf_so/search.c                  |  172 ++---
 libexec/ld.elf_so/symbol.c                  |  246 ++++++--
 libexec/ld.elf_so/sysident.h                |   22 +-
 libexec/ld.elf_so/xmalloc.c                 |   14 +-
 libexec/ld.elf_so/xprintf.c                 |  163 +----
 usr.bin/ldd/ldd_elf/ldd.c                   |  199 +++---
 57 files changed, 4383 insertions(+), 3466 deletions(-)

diffs (truncated from 10703 to 300 lines):

diff -r c0c090220095 -r c7ee35ce59eb libexec/ld.elf_so/Makefile
--- a/libexec/ld.elf_so/Makefile        Thu May 27 09:08:28 2004 +0000
+++ b/libexec/ld.elf_so/Makefile        Fri May 28 08:31:22 2004 +0000
@@ -1,9 +1,9 @@
-#      $NetBSD: Makefile,v 1.48.2.2 2002/11/17 01:12:05 lukem Exp $
+#      $NetBSD: Makefile,v 1.48.2.3 2004/05/28 08:31:22 tron Exp $
 
 .include <bsd.own.mk>                  # for OBJECT_FMT definition
 
-ARCHSUBDIR= ${MACHINE_CPU}
-M= ${.CURDIR}/arch/${ARCHSUBDIR}
+ARCHSUBDIR=    ${MACHINE_CPU}
+M=             ${.CURDIR}/arch/${ARCHSUBDIR}
 
 .if ((${MACHINE_ARCH} == "alpha") ||                                   \
      (${MACHINE_ARCH} == "arm") || (${MACHINE_ARCH} == "armeb") ||     \
@@ -18,7 +18,7 @@
      (${MACHINE_ARCH} == "vax")) &&                                    \
     ${OBJECT_FMT} == "ELF" && ${MKPIC} != "no"
 
-PROG=  ld.elf_so
+PROG=          ld.elf_so
 
 # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source
 # is first.
@@ -26,31 +26,32 @@
 .include "$M/Makefile.inc"
 .endif
 
-CLIBOBJ!=      cd ${.CURDIR}/../../lib/libc && ${PRINTOBJDIR}
+CLIBOBJ!=      cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
 
-SRCS+= rtld.c reloc.c symbol.c malloc.c xmalloc.c xprintf.c debug.c \
-       map_object.c load.c search.c headers.c paths.c
+SRCS+=         rtld.c reloc.c symbol.c malloc.c xmalloc.c xprintf.c debug.c \
+               map_object.c load.c search.c headers.c paths.c
 
-BINDIR=${SHLINKDIR}
+BINDIR=                ${SHLINKDIR}
 
-CPPFLAGS+= -DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
-CPPFLAGS+= -I${.CURDIR}
-CPPFLAGS+= -DDEBUG -DRTLD_LOADER
-CPPFLAGS+= -D_RTLD_SOURCE
-#CPPFLAGS+= -DRTLD_DEBUG
-#CPPFLAGS+= -DRTLD_DEBUG_RELOC
-#DBG=  -g
+CPPFLAGS+=     -DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
+CPPFLAGS+=     -I${.CURDIR}
+CPPFLAGS+=     -DRTLD_LOADER
+CPPFLAGS+=     -D_RTLD_SOURCE
+#CPPFLAGS+=    -DDEBUG
+#CPPFLAGS+=    -DRTLD_DEBUG
+#CPPFLAGS+=    -DRTLD_DEBUG_RELOC
+#DBG=          -g
+DBG=           -O3 -fomit-frame-pointer
 
 .if ${SHLIBDIR} != ${LIBDIR}
-CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
+CPPFLAGS+=     -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
 .endif
 
-LDADD+=        -L${CLIBOBJ} -L${DESTDIR}${LIBDIR} -non_shared -lc_pic
-DPADD+=        ${CLIBOBJ}/libc_pic.a ${LIBC_PIC}
-
-# One of these may not exist at link time, so avoid make errors.
-${DPADD}:
-       @true
+LDADD+=                -L${CLIBOBJ} -L${DESTDIR}${LIBDIR} -non_shared -lc_pic
+.if ${MKPICINSTALL} != "no"
+DPADD+=                ${LIBC_PIC}
+.endif
+DPADD+=                ${CLIBOBJ}/libc_pic.a
 
 STRIPFLAG=
 
@@ -66,7 +67,7 @@
 .include <bsd.prog.mk>
 .else
 
-MAN=   ld.elf_so.1
+MAN=           ld.elf_so.1
 
 .include <bsd.man.mk>
 .endif
diff -r c0c090220095 -r c7ee35ce59eb libexec/ld.elf_so/README
--- a/libexec/ld.elf_so/README  Thu May 27 09:08:28 2004 +0000
+++ b/libexec/ld.elf_so/README  Fri May 28 08:31:22 2004 +0000
@@ -1,48 +1,6 @@
-$NetBSD: README,v 1.8 2001/12/20 06:49:03 thorpej Exp $
-
-BUGS/PROBLEMS:
-
-* rtld.c around line 184:
-
-       #iffdef __alpha__
-       /* XXX XXX XXX */
-       _rtld_objself.pltgot = NULL;
-       #endif
-
-  It's a workaround for a linker bug, and will go away when the linker is
-  fixed.
-
-* The method used to relocate ld.so is shoddy and fragile.  Currently it's
-  something like:
-
-  alpha, powerpc:
-       (1) assembly code relocates RELATIVE relocations in the GOT
-           (on some ports, all relative relocations; this will probably
-           have to be #ifdef'd in reloc.c), assuming that everything
-           in the GOT is a RELATIVE relocation.
-
-       (2) alpha only: C code relocates the rest of the loader,
-           excluding those RELATIVE relocations already done (via an ...
-           iffy heuristic).
-
-  arm, i386, m68k, sparc:
-       (1) C code relocates the loader in _rtld_init() carefully so that
-           it does not touch any globals.
-
-  mips:
-       (1) loads ld.elf_so at 0, so no relocating is necessary.
-
-  Something better (like that the glibc ELF ld.so does) should be done
-  eventually, where a single set of C code is compiled twice, once for
-  normal use, and once to be used to relocate the shared linker.  No
-  relocations should be processed in assembly language.
-
-* On the Alpha, this code Really needs to be checked to be sure that
-  it doesn't make calls that could use FP, while doing lazy binding.
+$NetBSD: README,v 1.8.2.1 2004/05/28 08:31:22 tron Exp $
 
 TO DO:
 
 * Support for coexistance of 32-bit and 64-bit ELF on platforms that can
   do that.
-
-* Support for relocating ld.elf_so on mips
diff -r c0c090220095 -r c7ee35ce59eb libexec/ld.elf_so/TODO
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/libexec/ld.elf_so/TODO    Fri May 28 08:31:22 2004 +0000
@@ -0,0 +1,33 @@
+rtld:
+* resolve MIPS binding lossage
+
+binutils/gcc:
+* alpha: why are there GLOB_DAT relocs in ld.elf_so?
+* alpha: bogus textrels in rtti info
+* mips: why are there global GOT relocs in ld.elf_so?
+* mips: bogus textrels in .rel.dyn
+* powerpc: make sure the .got section is always executable
+* powerpc: fix ld scripts so that .rodata is still used for PIC
+
+machine-specific #ifdefs:
+headers.c:#ifdef __mips__
+reloc.c:#if defined(__i386__) || defined(__arm__)
+rtld.c:#if !defined(__arm__) && !defined(__mips__) && !defined(__sh__)
+rtld.c:#ifndef __mips__
+rtld.c:#ifdef __mips__
+rtld.h:#ifdef __mips__
+symbol.c:#ifndef __mips__
+
+issues to research:
+* sh, x86_64 have different absolute and GLOB_DAT relocs; nothing else does
+* sh, vax, x86_64 use addend on PLT; nothing else does
+
+
+rela: alpha hppa m68k powerpc sh sparc sparc64 vax x86_64
+rel: arm i386 mips
+
+untested/sketchy: hppa sh x86_64
+
+
+- mycroft
+  2003/09/24
diff -r c0c090220095 -r c7ee35ce59eb libexec/ld.elf_so/arch/alpha/Makefile.inc
--- a/libexec/ld.elf_so/arch/alpha/Makefile.inc Thu May 27 09:08:28 2004 +0000
+++ b/libexec/ld.elf_so/arch/alpha/Makefile.inc Fri May 28 08:31:22 2004 +0000
@@ -1,12 +1,11 @@
-#      $NetBSD: Makefile.inc,v 1.8 2001/12/20 19:20:02 thorpej Exp $
+#      $NetBSD: Makefile.inc,v 1.8.2.1 2004/05/28 08:31:22 tron Exp $
 
-SRCS+= rtld_start.S alpha_reloc.c
+SRCS+=         rtld_start.S alpha_reloc.c
 
 # XXX Should not be in CPPFLAGS!
-CPPFLAGS+= -fpic -mno-fp-regs
+CPPFLAGS+=     -fpic -mno-fp-regs
 
-CPPFLAGS+= -DELFSIZE=64
-#CPPFLAGS+= -DRTLD_DEBUG_ALPHA
+CPPFLAGS+=     -DELFSIZE=64
+#CPPFLAGS+=    -DRTLD_DEBUG_ALPHA
 
-LDFLAGS+= -Bshareable -Bsymbolic -e _rtld_start
-LDFLAGS+= --script ${.CURDIR}/arch/alpha/ld.so.script
+LDFLAGS+=      -Bshareable -Bsymbolic -e _rtld_start
diff -r c0c090220095 -r c7ee35ce59eb libexec/ld.elf_so/arch/alpha/alpha_reloc.c
--- a/libexec/ld.elf_so/arch/alpha/alpha_reloc.c        Thu May 27 09:08:28 2004 +0000
+++ b/libexec/ld.elf_so/arch/alpha/alpha_reloc.c        Fri May 28 08:31:22 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: alpha_reloc.c,v 1.2.2.1 2002/11/30 14:21:52 he Exp $   */
+/*     $NetBSD: alpha_reloc.c,v 1.2.2.2 2004/05/28 08:31:22 tron Exp $ */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -35,25 +35,51 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * Copyright 1996, 1997, 1998, 1999 John D. Polstra.   
+ * 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.
+ *          
+ * 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/types.h>
 #include <sys/stat.h>
+#include <string.h>
 
 #include "rtld.h"
 #include "debug.h"
 
 #ifdef RTLD_DEBUG_ALPHA
-#define        adbg(x)         if (dodebug) xprintf x
+#define        adbg(x)         xprintf x
 #else
 #define        adbg(x)         /* nothing */
 #endif
 
-/*
- * _rtld_setup_alpha_pltgot:
- *
- *     Set up the Alpha pltgot glue.
- */
+void _rtld_bind_start(void);
+void _rtld_bind_start_old(void);
+void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
+caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
+
 void
-_rtld_setup_alpha_pltgot(const Obj_Entry *obj, bool dodebug)
+_rtld_setup_pltgot(const Obj_Entry *obj)
 {
        uint32_t word0;
 
@@ -112,3 +138,340 @@
 
        __asm __volatile("imb");
 }
+
+/*
+ * 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));
+
+       return (res);
+}
+
+static __inline void
+store_ptr(void *where, Elf_Addr val)
+{
+
+       memcpy(where, &val, sizeof(val));
+}
+
+void
+_rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase)
+{
+       const Elf_Rela *rela = 0, *relalim;
+       Elf_Addr relasz = 0;
+       Elf_Addr *where;



Home | Main Index | Thread Index | Old Index