Blame sysdeps/mips/dl-machine.h

Packit 6c4009
/* Machine-dependent ELF dynamic relocation inline functions.  MIPS version.
Packit 6c4009
   Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Kazumoto Kojima <kkojima@info.kanagawa-u.ac.jp>.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/*  FIXME: Profiling of shared libraries is not implemented yet.  */
Packit 6c4009
#ifndef dl_machine_h
Packit 6c4009
#define dl_machine_h
Packit 6c4009
Packit 6c4009
#define ELF_MACHINE_NAME "MIPS"
Packit 6c4009
Packit 6c4009
#include <entry.h>
Packit 6c4009
Packit 6c4009
#ifndef ENTRY_POINT
Packit 6c4009
#error ENTRY_POINT needs to be defined for MIPS.
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#include <sgidefs.h>
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include <sys/asm.h>
Packit 6c4009
#include <dl-tls.h>
Packit 6c4009
Packit 6c4009
/* The offset of gp from GOT might be system-dependent.  It's set by
Packit 6c4009
   ld.  The same value is also */
Packit 6c4009
#define OFFSET_GP_GOT 0x7ff0
Packit 6c4009
Packit 6c4009
#ifndef _RTLD_PROLOGUE
Packit 6c4009
# define _RTLD_PROLOGUE(entry)						\
Packit 6c4009
	".globl\t" __STRING(entry) "\n\t"				\
Packit 6c4009
	".ent\t" __STRING(entry) "\n\t"					\
Packit 6c4009
	".type\t" __STRING(entry) ", @function\n"			\
Packit 6c4009
	__STRING(entry) ":\n\t"
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifndef _RTLD_EPILOGUE
Packit 6c4009
# define _RTLD_EPILOGUE(entry)						\
Packit 6c4009
	".end\t" __STRING(entry) "\n\t"					\
Packit 6c4009
	".size\t" __STRING(entry) ", . - " __STRING(entry) "\n\t"
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.
Packit 6c4009
   This only makes sense on MIPS when using PLTs, so choose the
Packit 6c4009
   PLT relocation (not encountered when not using PLTs).  */
Packit 6c4009
#define ELF_MACHINE_JMP_SLOT			R_MIPS_JUMP_SLOT
Packit 6c4009
#define elf_machine_type_class(type) \
Packit 6c4009
  ((((type) == ELF_MACHINE_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)	\
Packit 6c4009
   | (((type) == R_MIPS_COPY) * ELF_RTYPE_CLASS_COPY))
Packit 6c4009
Packit 6c4009
#define ELF_MACHINE_PLT_REL 1
Packit 6c4009
#define ELF_MACHINE_NO_REL 0
Packit 6c4009
#define ELF_MACHINE_NO_RELA 0
Packit 6c4009
Packit 6c4009
/* Translate a processor specific dynamic tag to the index
Packit 6c4009
   in l_info array.  */
Packit 6c4009
#define DT_MIPS(x) (DT_MIPS_##x - DT_LOPROC + DT_NUM)
Packit 6c4009
Packit 6c4009
/* If there is a DT_MIPS_RLD_MAP_REL or DT_MIPS_RLD_MAP entry in the dynamic
Packit 6c4009
   section, fill in the debug map pointer with the run-time address of the
Packit 6c4009
   r_debug structure.  */
Packit 6c4009
#define ELF_MACHINE_DEBUG_SETUP(l,r) \
Packit 6c4009
do { if ((l)->l_info[DT_MIPS (RLD_MAP_REL)]) \
Packit 6c4009
       { \
Packit 6c4009
	 char *ptr = (char *)(l)->l_info[DT_MIPS (RLD_MAP_REL)]; \
Packit 6c4009
	 ptr += (l)->l_info[DT_MIPS (RLD_MAP_REL)]->d_un.d_val; \
Packit 6c4009
	 *(ElfW(Addr) *)ptr = (ElfW(Addr)) (r); \
Packit 6c4009
       } \
Packit 6c4009
     else if ((l)->l_info[DT_MIPS (RLD_MAP)]) \
Packit 6c4009
       *(ElfW(Addr) *)((l)->l_info[DT_MIPS (RLD_MAP)]->d_un.d_ptr) = \
Packit 6c4009
       (ElfW(Addr)) (r); \
Packit 6c4009
   } while (0)
Packit 6c4009
Packit 6c4009
#if ((defined __mips_nan2008 && !defined HAVE_MIPS_NAN2008) \
Packit 6c4009
     || (!defined __mips_nan2008 && defined HAVE_MIPS_NAN2008))
Packit 6c4009
# error "Configuration inconsistency: __mips_nan2008 != HAVE_MIPS_NAN2008, overridden CFLAGS?"
Packit 6c4009
#endif
Packit 6c4009
#ifdef __mips_nan2008
Packit 6c4009
# define ELF_MACHINE_NAN2008 EF_MIPS_NAN2008
Packit 6c4009
#else
Packit 6c4009
# define ELF_MACHINE_NAN2008 0
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Return nonzero iff ELF header is compatible with the running host.  */
Packit 6c4009
static inline int __attribute_used__
Packit 6c4009
elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
Packit 6c4009
{
Packit 6c4009
#if _MIPS_SIM == _ABIO32 || _MIPS_SIM == _ABIN32
Packit 6c4009
  /* Don't link o32 and n32 together.  */
Packit 6c4009
  if (((ehdr->e_flags & EF_MIPS_ABI2) != 0) != (_MIPS_SIM == _ABIN32))
Packit 6c4009
    return 0;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  /* Don't link 2008-NaN and legacy-NaN objects together.  */
Packit 6c4009
  if ((ehdr->e_flags & EF_MIPS_NAN2008) != ELF_MACHINE_NAN2008)
Packit 6c4009
    return 0;
Packit 6c4009
Packit 6c4009
  /* Ensure that the old O32 FP64 ABI is never loaded, it is not supported
Packit 6c4009
     on linux.  */
Packit 6c4009
  if (ehdr->e_flags & EF_MIPS_FP64)
Packit 6c4009
    return 0;
Packit 6c4009
Packit 6c4009
  switch (ehdr->e_machine)
Packit 6c4009
    {
Packit 6c4009
    case EM_MIPS:
Packit 6c4009
    case EM_MIPS_RS3_LE:
Packit 6c4009
      return 1;
Packit 6c4009
    default:
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static inline ElfW(Addr) *
Packit 6c4009
elf_mips_got_from_gpreg (ElfW(Addr) gpreg)
Packit 6c4009
{
Packit 6c4009
  /* FIXME: the offset of gp from GOT may be system-dependent. */
Packit 6c4009
  return (ElfW(Addr) *) (gpreg - OFFSET_GP_GOT);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Return the link-time address of _DYNAMIC.  Conveniently, this is the
Packit 6c4009
   first element of the GOT.  This must be inlined in a function which
Packit 6c4009
   uses global data.  We assume its $gp points to the primary GOT.  */
Packit 6c4009
static inline ElfW(Addr)
Packit 6c4009
elf_machine_dynamic (void)
Packit 6c4009
{
Packit 6c4009
  register ElfW(Addr) gp __asm__ ("$28");
Packit 6c4009
  return *elf_mips_got_from_gpreg (gp);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define STRINGXP(X) __STRING(X)
Packit 6c4009
#define STRINGXV(X) STRINGV_(X)
Packit 6c4009
#define STRINGV_(...) # __VA_ARGS__
Packit 6c4009
Packit 6c4009
/* Return the run-time load address of the shared object.  */
Packit 6c4009
static inline ElfW(Addr)
Packit 6c4009
elf_machine_load_address (void)
Packit 6c4009
{
Packit 6c4009
  ElfW(Addr) addr;
Packit 6c4009
#ifndef __mips16
Packit 6c4009
  asm ("	.set noreorder\n"
Packit 6c4009
       "	" STRINGXP (PTR_LA) " %0, 0f\n"
Packit 6c4009
# if !defined __mips_isa_rev || __mips_isa_rev < 6
Packit 6c4009
       "	bltzal $0, 0f\n"
Packit 6c4009
       "	nop\n"
Packit 6c4009
       "0:	" STRINGXP (PTR_SUBU) " %0, $31, %0\n"
Packit 6c4009
# else
Packit 6c4009
       "0:	addiupc $31, 0\n"
Packit 6c4009
       "	" STRINGXP (PTR_SUBU) " %0, $31, %0\n"
Packit 6c4009
# endif
Packit 6c4009
       "	.set reorder\n"
Packit 6c4009
       :	"=r" (addr)
Packit 6c4009
       :	/* No inputs */
Packit 6c4009
       :	"$31");
Packit 6c4009
#else
Packit 6c4009
  ElfW(Addr) tmp;
Packit 6c4009
  asm ("	.set noreorder\n"
Packit 6c4009
       "	move %1,$gp\n"
Packit 6c4009
       "	lw %1,%%got(0f)(%1)\n"
Packit 6c4009
       "0:	.fill 0\n"		/* Clear the ISA bit on 0:.  */
Packit 6c4009
       "	la %0,0b\n"
Packit 6c4009
       "	addiu %1,%%lo(0b)\n"
Packit 6c4009
       "	subu %0,%1\n"
Packit 6c4009
       "	.set reorder\n"
Packit 6c4009
       :	"=d" (addr), "=d" (tmp)
Packit 6c4009
       :	/* No inputs */);
Packit 6c4009
#endif
Packit 6c4009
  return addr;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* The MSB of got[1] of a gnu object is set to identify gnu objects.  */
Packit 6c4009
#if _MIPS_SIM == _ABI64
Packit 6c4009
# define ELF_MIPS_GNU_GOT1_MASK	0x8000000000000000L
Packit 6c4009
#else
Packit 6c4009
# define ELF_MIPS_GNU_GOT1_MASK	0x80000000L
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* We can't rely on elf_machine_got_rel because _dl_object_relocation_scope
Packit 6c4009
   fiddles with global data.  */
Packit 6c4009
#define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info)			\
Packit 6c4009
do {									\
Packit 6c4009
  struct link_map *map = BOOTSTRAP_MAP;					\
Packit 6c4009
  ElfW(Sym) *sym;							\
Packit 6c4009
  ElfW(Addr) *got;							\
Packit 6c4009
  int i, n;								\
Packit 6c4009
									\
Packit 6c4009
  got = (ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);			\
Packit 6c4009
									\
Packit 6c4009
  if (__builtin_expect (map->l_addr == 0, 1))				\
Packit 6c4009
    break;								\
Packit 6c4009
									\
Packit 6c4009
  /* got[0] is reserved. got[1] is also reserved for the dynamic object	\
Packit 6c4009
     generated by gnu ld. Skip these reserved entries from		\
Packit 6c4009
     relocation.  */							\
Packit 6c4009
  i = (got[1] & ELF_MIPS_GNU_GOT1_MASK)? 2 : 1;				\
Packit 6c4009
  n = map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;			\
Packit 6c4009
									\
Packit 6c4009
  /* Add the run-time displacement to all local got entries. */		\
Packit 6c4009
  while (i < n)								\
Packit 6c4009
    got[i++] += map->l_addr;						\
Packit 6c4009
									\
Packit 6c4009
  /* Handle global got entries. */					\
Packit 6c4009
  got += n;								\
Packit 6c4009
  sym = (ElfW(Sym) *) D_PTR(map, l_info[DT_SYMTAB])			\
Packit 6c4009
       + map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;			\
Packit 6c4009
  i = (map->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val			\
Packit 6c4009
       - map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val);			\
Packit 6c4009
									\
Packit 6c4009
  while (i--)								\
Packit 6c4009
    {									\
Packit 6c4009
      if (sym->st_shndx == SHN_UNDEF || sym->st_shndx == SHN_COMMON)	\
Packit 6c4009
	*got = SYMBOL_ADDRESS (map, sym, true);				\
Packit 6c4009
      else if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC			\
Packit 6c4009
	       && *got != sym->st_value)				\
Packit 6c4009
	*got += map->l_addr;						\
Packit 6c4009
      else if (ELFW(ST_TYPE) (sym->st_info) == STT_SECTION)		\
Packit 6c4009
	{								\
Packit 6c4009
	  if (sym->st_other == 0)					\
Packit 6c4009
	    *got += map->l_addr;					\
Packit 6c4009
	}								\
Packit 6c4009
      else								\
Packit 6c4009
	*got = SYMBOL_ADDRESS (map, sym, true);				\
Packit 6c4009
									\
Packit 6c4009
      got++;								\
Packit 6c4009
      sym++;								\
Packit 6c4009
    }									\
Packit 6c4009
} while(0)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Mask identifying addresses reserved for the user program,
Packit 6c4009
   where the dynamic linker should not map anything.  */
Packit 6c4009
#define ELF_MACHINE_USER_ADDRESS_MASK	0x80000000UL
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Initial entry point code for the dynamic linker.
Packit 6c4009
   The C function `_dl_start' is the real entry point;
Packit 6c4009
   its return value is the user program's entry point.
Packit 6c4009
   Note how we have to be careful about two things:
Packit 6c4009
Packit 6c4009
   1) That we allocate a minimal stack of 24 bytes for
Packit 6c4009
      every function call, the MIPS ABI states that even
Packit 6c4009
      if all arguments are passed in registers the procedure
Packit 6c4009
      called can use the 16 byte area pointed to by $sp
Packit 6c4009
      when it is called to store away the arguments passed
Packit 6c4009
      to it.
Packit 6c4009
Packit 6c4009
   2) That under Unix the entry is named __start
Packit 6c4009
      and not just plain _start.  */
Packit 6c4009
Packit 6c4009
#ifndef __mips16
Packit 6c4009
# if !defined __mips_isa_rev || __mips_isa_rev < 6
Packit 6c4009
#  define LCOFF STRINGXP(.Lcof2)
Packit 6c4009
#  define LOAD_31 STRINGXP(bltzal $8) "," STRINGXP(.Lcof2)
Packit 6c4009
# else
Packit 6c4009
#  define LCOFF STRINGXP(.Lcof1)
Packit 6c4009
#  define LOAD_31 "addiupc $31, 0"
Packit 6c4009
# endif
Packit 6c4009
# define RTLD_START asm (\
Packit 6c4009
	".text\n\
Packit 6c4009
	" _RTLD_PROLOGUE(ENTRY_POINT) "\
Packit 6c4009
	" STRINGXV(SETUP_GPX($25)) "\n\
Packit 6c4009
	" STRINGXV(SETUP_GPX64($18,$25)) "\n\
Packit 6c4009
	# i386 ABI book says that the first entry of GOT holds\n\
Packit 6c4009
	# the address of the dynamic structure. Though MIPS ABI\n\
Packit 6c4009
	# doesn't say nothing about this, I emulate this here.\n\
Packit 6c4009
	" STRINGXP(PTR_LA) " $4, _DYNAMIC\n\
Packit 6c4009
	# Subtract OFFSET_GP_GOT\n\
Packit 6c4009
	" STRINGXP(PTR_S) " $4, -0x7ff0($28)\n\
Packit 6c4009
	move $4, $29\n\
Packit 6c4009
	" STRINGXP(PTR_SUBIU) " $29, 16\n\
Packit 6c4009
	\n\
Packit 6c4009
	" STRINGXP(PTR_LA) " $8, " LCOFF "\n\
Packit 6c4009
.Lcof1:	" LOAD_31 "\n\
Packit 6c4009
.Lcof2:	" STRINGXP(PTR_SUBU) " $8, $31, $8\n\
Packit 6c4009
	\n\
Packit 6c4009
	" STRINGXP(PTR_LA) " $25, _dl_start\n\
Packit 6c4009
	" STRINGXP(PTR_ADDU) " $25, $8\n\
Packit 6c4009
	jalr $25\n\
Packit 6c4009
	\n\
Packit 6c4009
	" STRINGXP(PTR_ADDIU) " $29, 16\n\
Packit 6c4009
	# Get the value of label '_dl_start_user' in t9 ($25).\n\
Packit 6c4009
	" STRINGXP(PTR_LA) " $25, _dl_start_user\n\
Packit 6c4009
	" _RTLD_EPILOGUE(ENTRY_POINT) "\
Packit 6c4009
	\n\
Packit 6c4009
	\n\
Packit 6c4009
	" _RTLD_PROLOGUE(_dl_start_user) "\
Packit 6c4009
	" STRINGXP(SETUP_GP) "\n\
Packit 6c4009
	" STRINGXV(SETUP_GP64($18,_dl_start_user)) "\n\
Packit 6c4009
	move $16, $28\n\
Packit 6c4009
	# Save the user entry point address in a saved register.\n\
Packit 6c4009
	move $17, $2\n\
Packit 6c4009
	# See if we were run as a command with the executable file\n\
Packit 6c4009
	# name as an extra leading argument.\n\
Packit 6c4009
	lw $2, _dl_skip_args\n\
Packit 6c4009
	beq $2, $0, 1f\n\
Packit 6c4009
	# Load the original argument count.\n\
Packit 6c4009
	" STRINGXP(PTR_L) " $4, 0($29)\n\
Packit 6c4009
	# Subtract _dl_skip_args from it.\n\
Packit 6c4009
	subu $4, $2\n\
Packit 6c4009
	# Adjust the stack pointer to skip _dl_skip_args words.\n\
Packit 6c4009
	sll $2, " STRINGXP (PTRLOG) "\n\
Packit 6c4009
	" STRINGXP(PTR_ADDU) " $29, $2\n\
Packit 6c4009
	# Save back the modified argument count.\n\
Packit 6c4009
	" STRINGXP(PTR_S) " $4, 0($29)\n\
Packit 6c4009
1:	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
Packit 6c4009
	" STRINGXP(PTR_L) " $4, _rtld_local\n\
Packit 6c4009
	" STRINGXP(PTR_L) /* or lw???  fixme */ " $5, 0($29)\n\
Packit 6c4009
	" STRINGXP(PTR_LA) " $6, " STRINGXP (PTRSIZE) "($29)\n\
Packit 6c4009
	sll $7, $5, " STRINGXP (PTRLOG) "\n\
Packit 6c4009
	" STRINGXP(PTR_ADDU) " $7, $7, $6\n\
Packit 6c4009
	" STRINGXP(PTR_ADDU) " $7, $7, " STRINGXP (PTRSIZE) " \n\
Packit 6c4009
	# Make sure the stack pointer is aligned for _dl_init.\n\
Packit 6c4009
	and $2, $29, -2 * " STRINGXP(SZREG) "\n\
Packit 6c4009
	move $8, $29\n\
Packit 6c4009
	" STRINGXP(PTR_SUBIU) " $29, $2, 32\n\
Packit 6c4009
	" STRINGXP(PTR_S) " $8, (32 - " STRINGXP(SZREG) ")($29)\n\
Packit 6c4009
	" STRINGXP(SAVE_GP(16)) "\n\
Packit 6c4009
	# Call the function to run the initializers.\n\
Packit 6c4009
	jal _dl_init\n\
Packit 6c4009
	# Restore the stack pointer for _start.\n\
Packit 6c4009
	" STRINGXP(PTR_L)  " $29, (32 - " STRINGXP(SZREG) ")($29)\n\
Packit 6c4009
	# Pass our finalizer function to the user in $2 as per ELF ABI.\n\
Packit 6c4009
	" STRINGXP(PTR_LA) " $2, _dl_fini\n\
Packit 6c4009
	# Jump to the user entry point.\n\
Packit 6c4009
	move $25, $17\n\
Packit 6c4009
	jr $25\n\t"\
Packit 6c4009
	_RTLD_EPILOGUE(_dl_start_user)\
Packit 6c4009
	".previous"\
Packit 6c4009
);
Packit 6c4009
Packit 6c4009
#else /* __mips16 */
Packit 6c4009
/* MIPS16 version.  We currently only support O32 under MIPS16; the proper
Packit 6c4009
   assembly preprocessor abstractions will need to be added if other ABIs
Packit 6c4009
   are to be supported.  */
Packit 6c4009
Packit 6c4009
# define RTLD_START asm (\
Packit 6c4009
	".text\n\
Packit 6c4009
	.set mips16\n\
Packit 6c4009
	" _RTLD_PROLOGUE (ENTRY_POINT) "\
Packit 6c4009
	# Construct GP value in $3.\n\
Packit 6c4009
	li $3, %hi(_gp_disp)\n\
Packit 6c4009
	addiu $4, $pc, %lo(_gp_disp)\n\
Packit 6c4009
	sll $3, 16\n\
Packit 6c4009
	addu $3, $4\n\
Packit 6c4009
	move $28, $3\n\
Packit 6c4009
	lw $4, %got(_DYNAMIC)($3)\n\
Packit 6c4009
	sw $4, -0x7ff0($3)\n\
Packit 6c4009
	move $4, $sp\n\
Packit 6c4009
	addiu $sp, -16\n\
Packit 6c4009
	# _dl_start() is sufficiently near to use pc-relative\n\
Packit 6c4009
	# load address.\n\
Packit 6c4009
	la $3, _dl_start\n\
Packit 6c4009
	move $25, $3\n\
Packit 6c4009
	jalr $3\n\
Packit 6c4009
	addiu $sp, 16\n\
Packit 6c4009
	" _RTLD_EPILOGUE (ENTRY_POINT) "\
Packit 6c4009
	\n\
Packit 6c4009
	\n\
Packit 6c4009
	" _RTLD_PROLOGUE (_dl_start_user) "\
Packit 6c4009
	li $16, %hi(_gp_disp)\n\
Packit 6c4009
	addiu $4, $pc, %lo(_gp_disp)\n\
Packit 6c4009
	sll $16, 16\n\
Packit 6c4009
	addu $16, $4\n\
Packit 6c4009
	move $17, $2\n\
Packit 6c4009
	move $28, $16\n\
Packit 6c4009
	lw $4, %got(_dl_skip_args)($16)\n\
Packit 6c4009
	lw $4, 0($4)\n\
Packit 6c4009
	beqz $4, 1f\n\
Packit 6c4009
	# Load the original argument count.\n\
Packit 6c4009
	lw $5, 0($sp)\n\
Packit 6c4009
	# Subtract _dl_skip_args from it.\n\
Packit 6c4009
	subu $5, $4\n\
Packit 6c4009
	# Adjust the stack pointer to skip _dl_skip_args words.\n\
Packit 6c4009
	sll $4, " STRINGXP (PTRLOG) "\n\
Packit 6c4009
	move $6, $sp\n\
Packit 6c4009
	addu $6, $4\n\
Packit 6c4009
	move $sp, $6\n\
Packit 6c4009
	# Save back the modified argument count.\n\
Packit 6c4009
	sw $5, 0($sp)\n\
Packit 6c4009
1:	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env) \n\
Packit 6c4009
	lw $4, %got(_rtld_local)($16)\n\
Packit 6c4009
	lw $4, 0($4)\n\
Packit 6c4009
	lw $5, 0($sp)\n\
Packit 6c4009
	addiu $6, $sp, " STRINGXP (PTRSIZE) "\n\
Packit 6c4009
	sll $7, $5, " STRINGXP (PTRLOG) "\n\
Packit 6c4009
	addu $7, $6\n\
Packit 6c4009
	addu $7, " STRINGXP (PTRSIZE) "\n\
Packit 6c4009
	# Make sure the stack pointer is aligned for _dl_init.\n\
Packit 6c4009
	li $2, 2 * " STRINGXP (SZREG) "\n\
Packit 6c4009
	neg $2, $2\n\
Packit 6c4009
	move $3, $sp\n\
Packit 6c4009
	and $2, $3\n\
Packit 6c4009
	sw $3, -" STRINGXP (SZREG) "($2)\n\
Packit 6c4009
	addiu $2, -32\n\
Packit 6c4009
	move $sp, $2\n\
Packit 6c4009
	sw $16, 16($sp)\n\
Packit 6c4009
	# Call the function to run the initializers.\n\
Packit 6c4009
	lw $2, %call16(_dl_init)($16)\n\
Packit 6c4009
	move $25, $2\n\
Packit 6c4009
	jalr $2\n\
Packit 6c4009
	# Restore the stack pointer for _start.\n\
Packit 6c4009
	lw $2, 32-" STRINGXP (SZREG) "($sp)\n\
Packit 6c4009
	move $sp, $2\n\
Packit 6c4009
	move $28, $16\n\
Packit 6c4009
	# Pass our finalizer function to the user in $2 as per ELF ABI.\n\
Packit 6c4009
	lw $2, %call16(_dl_fini)($16)\n\
Packit 6c4009
	# Jump to the user entry point.\n\
Packit 6c4009
	move $25, $17\n\
Packit 6c4009
	jr $17\n\t"\
Packit 6c4009
	_RTLD_EPILOGUE (_dl_start_user)\
Packit 6c4009
	".previous"\
Packit 6c4009
);
Packit 6c4009
Packit 6c4009
#endif /* __mips16 */
Packit 6c4009
Packit 6c4009
/* Names of the architecture-specific auditing callback functions.  */
Packit 6c4009
# if _MIPS_SIM == _ABIO32
Packit 6c4009
#  define ARCH_LA_PLTENTER mips_o32_gnu_pltenter
Packit 6c4009
#  define ARCH_LA_PLTEXIT mips_o32_gnu_pltexit
Packit 6c4009
# elif _MIPS_SIM == _ABIN32
Packit 6c4009
#  define ARCH_LA_PLTENTER mips_n32_gnu_pltenter
Packit 6c4009
#  define ARCH_LA_PLTEXIT mips_n32_gnu_pltexit
Packit 6c4009
# else
Packit 6c4009
#  define ARCH_LA_PLTENTER mips_n64_gnu_pltenter
Packit 6c4009
#  define ARCH_LA_PLTEXIT mips_n64_gnu_pltexit
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
/* We define an initialization function.  This is called very early in
Packit 6c4009
   _dl_sysdep_start.  */
Packit 6c4009
#define DL_PLATFORM_INIT dl_platform_init ()
Packit 6c4009
Packit 6c4009
static inline void __attribute__ ((unused))
Packit 6c4009
dl_platform_init (void)
Packit 6c4009
{
Packit 6c4009
  if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
Packit 6c4009
    /* Avoid an empty string which would disturb us.  */
Packit 6c4009
    GLRO(dl_platform) = NULL;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* For a non-writable PLT, rewrite the .got.plt entry at RELOC_ADDR to
Packit 6c4009
   point at the symbol with address VALUE.  For a writable PLT, rewrite
Packit 6c4009
   the corresponding PLT entry instead.  */
Packit 6c4009
static inline ElfW(Addr)
Packit 6c4009
elf_machine_fixup_plt (struct link_map *map, lookup_t t,
Packit 6c4009
		       const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
Packit 6c4009
		       const ElfW(Rel) *reloc,
Packit 6c4009
		       ElfW(Addr) *reloc_addr, ElfW(Addr) value)
Packit 6c4009
{
Packit 6c4009
  return *reloc_addr = value;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static inline ElfW(Addr)
Packit 6c4009
elf_machine_plt_value (struct link_map *map, const ElfW(Rel) *reloc,
Packit 6c4009
		       ElfW(Addr) value)
Packit 6c4009
{
Packit 6c4009
  return value;
Packit 6c4009
}
Packit 6c4009
Packit Service 3e830d
/* The semantics of zero/non-zero values of undefined symbols differs
Packit Service 3e830d
   depending on whether the non-PIC ABI is in use.  Under the non-PIC
Packit Service 3e830d
   ABI, a non-zero value indicates that there is an address reference
Packit Service 3e830d
   to the symbol and thus it must always be resolved (except when
Packit Service 3e830d
   resolving a jump slot relocation) to the PLT entry whose address is
Packit Service 3e830d
   provided as the symbol's value; a zero value indicates that this
Packit Service 3e830d
   canonical-address behaviour is not required.  Yet under the classic
Packit Service 3e830d
   MIPS psABI, a zero value indicates that there is an address
Packit Service 3e830d
   reference to the function and the dynamic linker must resolve the
Packit Service 3e830d
   symbol immediately upon loading.  To avoid conflict, symbols for
Packit Service 3e830d
   which the dynamic linker must assume the non-PIC ABI semantics are
Packit Service 3e830d
   marked with the STO_MIPS_PLT flag.  */
Packit Service 3e830d
#define ELF_MACHINE_SYM_NO_MATCH(sym) \
Packit Service 3e830d
  ((sym)->st_shndx == SHN_UNDEF && !((sym)->st_other & STO_MIPS_PLT))
Packit Service 3e830d
Packit 6c4009
#endif /* !dl_machine_h */
Packit 6c4009
Packit 6c4009
#ifdef RESOLVE_MAP
Packit 6c4009
Packit 6c4009
/* Perform a relocation described by R_INFO at the location pointed to
Packit 6c4009
   by RELOC_ADDR.  SYM is the relocation symbol specified by R_INFO and
Packit 6c4009
   MAP is the object containing the reloc.  */
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__ ((always_inline))
Packit 6c4009
elf_machine_reloc (struct link_map *map, ElfW(Addr) r_info,
Packit 6c4009
		   const ElfW(Sym) *sym, const struct r_found_version *version,
Packit 6c4009
		   void *reloc_addr, ElfW(Addr) r_addend, int inplace_p)
Packit 6c4009
{
Packit 6c4009
  const unsigned long int r_type = ELFW(R_TYPE) (r_info);
Packit 6c4009
  ElfW(Addr) *addr_field = (ElfW(Addr) *) reloc_addr;
Packit 6c4009
Packit 6c4009
#if !defined RTLD_BOOTSTRAP && !defined SHARED
Packit 6c4009
  /* This is defined in rtld.c, but nowhere in the static libc.a;
Packit 6c4009
     make the reference weak so static programs can still link.  This
Packit 6c4009
     declaration cannot be done when compiling rtld.c (i.e.  #ifdef
Packit 6c4009
     RTLD_BOOTSTRAP) because rtld.c contains the common defn for
Packit 6c4009
     _dl_rtld_map, which is incompatible with a weak decl in the same
Packit 6c4009
     file.  */
Packit 6c4009
  weak_extern (GL(dl_rtld_map));
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  switch (r_type)
Packit 6c4009
    {
Packit 6c4009
#if !defined (RTLD_BOOTSTRAP)
Packit 6c4009
# if _MIPS_SIM == _ABI64
Packit 6c4009
    case R_MIPS_TLS_DTPMOD64:
Packit 6c4009
    case R_MIPS_TLS_DTPREL64:
Packit 6c4009
    case R_MIPS_TLS_TPREL64:
Packit 6c4009
# else
Packit 6c4009
    case R_MIPS_TLS_DTPMOD32:
Packit 6c4009
    case R_MIPS_TLS_DTPREL32:
Packit 6c4009
    case R_MIPS_TLS_TPREL32:
Packit 6c4009
# endif
Packit 6c4009
      {
Packit 6c4009
	struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
Packit 6c4009
Packit 6c4009
	switch (r_type)
Packit 6c4009
	  {
Packit 6c4009
	  case R_MIPS_TLS_DTPMOD64:
Packit 6c4009
	  case R_MIPS_TLS_DTPMOD32:
Packit 6c4009
	    if (sym_map)
Packit 6c4009
	      *addr_field = sym_map->l_tls_modid;
Packit 6c4009
	    break;
Packit 6c4009
Packit 6c4009
	  case R_MIPS_TLS_DTPREL64:
Packit 6c4009
	  case R_MIPS_TLS_DTPREL32:
Packit 6c4009
	    if (sym)
Packit 6c4009
	      {
Packit 6c4009
		if (inplace_p)
Packit 6c4009
		  r_addend = *addr_field;
Packit 6c4009
		*addr_field = r_addend + TLS_DTPREL_VALUE (sym);
Packit 6c4009
	      }
Packit 6c4009
	    break;
Packit 6c4009
Packit 6c4009
	  case R_MIPS_TLS_TPREL32:
Packit 6c4009
	  case R_MIPS_TLS_TPREL64:
Packit 6c4009
	    if (sym)
Packit 6c4009
	      {
Packit 6c4009
		CHECK_STATIC_TLS (map, sym_map);
Packit 6c4009
		if (inplace_p)
Packit 6c4009
		  r_addend = *addr_field;
Packit 6c4009
		*addr_field = r_addend + TLS_TPREL_VALUE (sym_map, sym);
Packit 6c4009
	      }
Packit 6c4009
	    break;
Packit 6c4009
	  }
Packit 6c4009
Packit 6c4009
	break;
Packit 6c4009
      }
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#if _MIPS_SIM == _ABI64
Packit 6c4009
    case (R_MIPS_64 << 8) | R_MIPS_REL32:
Packit 6c4009
#else
Packit 6c4009
    case R_MIPS_REL32:
Packit 6c4009
#endif
Packit 6c4009
      {
Packit 6c4009
	int symidx = ELFW(R_SYM) (r_info);
Packit 6c4009
	ElfW(Addr) reloc_value;
Packit 6c4009
Packit 6c4009
	if (inplace_p)
Packit 6c4009
	  /* Support relocations on mis-aligned offsets.  */
Packit 6c4009
	  __builtin_memcpy (&reloc_value, reloc_addr, sizeof (reloc_value));
Packit 6c4009
	else
Packit 6c4009
	  reloc_value = r_addend;
Packit 6c4009
Packit 6c4009
	if (symidx)
Packit 6c4009
	  {
Packit 6c4009
	    const ElfW(Word) gotsym
Packit 6c4009
	      = (const ElfW(Word)) map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;
Packit 6c4009
Packit 6c4009
	    if ((ElfW(Word))symidx < gotsym)
Packit 6c4009
	      {
Packit 6c4009
		/* This wouldn't work for a symbol imported from other
Packit 6c4009
		   libraries for which there's no GOT entry, but MIPS
Packit 6c4009
		   requires every symbol referenced in a dynamic
Packit 6c4009
		   relocation to have a GOT entry in the primary GOT,
Packit 6c4009
		   so we only get here for locally-defined symbols.
Packit 6c4009
		   For section symbols, we should *NOT* be adding
Packit 6c4009
		   sym->st_value (per the definition of the meaning of
Packit 6c4009
		   S in reloc expressions in the ELF64 MIPS ABI),
Packit 6c4009
		   since it should have already been added to
Packit 6c4009
		   reloc_value by the linker, but older versions of
Packit 6c4009
		   GNU ld didn't add it, and newer versions don't emit
Packit 6c4009
		   useless relocations to section symbols any more, so
Packit 6c4009
		   it is safe to keep on adding sym->st_value, even
Packit 6c4009
		   though it's not ABI compliant.  Some day we should
Packit 6c4009
		   bite the bullet and stop doing this.  */
Packit 6c4009
#ifndef RTLD_BOOTSTRAP
Packit 6c4009
		if (map != &GL(dl_rtld_map))
Packit 6c4009
#endif
Packit 6c4009
		  reloc_value += SYMBOL_ADDRESS (map, sym, true);
Packit 6c4009
	      }
Packit 6c4009
	    else
Packit 6c4009
	      {
Packit 6c4009
#ifndef RTLD_BOOTSTRAP
Packit 6c4009
		const ElfW(Addr) *got
Packit 6c4009
		  = (const ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
Packit 6c4009
		const ElfW(Word) local_gotno
Packit 6c4009
		  = (const ElfW(Word))
Packit 6c4009
		    map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;
Packit 6c4009
Packit 6c4009
		reloc_value += got[symidx + local_gotno - gotsym];
Packit 6c4009
#endif
Packit 6c4009
	      }
Packit 6c4009
	  }
Packit 6c4009
	else
Packit 6c4009
#ifndef RTLD_BOOTSTRAP
Packit 6c4009
	  if (map != &GL(dl_rtld_map))
Packit 6c4009
#endif
Packit 6c4009
	    reloc_value += map->l_addr;
Packit 6c4009
Packit 6c4009
	__builtin_memcpy (reloc_addr, &reloc_value, sizeof (reloc_value));
Packit 6c4009
      }
Packit 6c4009
      break;
Packit 6c4009
#ifndef RTLD_BOOTSTRAP
Packit 6c4009
#if _MIPS_SIM == _ABI64
Packit 6c4009
    case (R_MIPS_64 << 8) | R_MIPS_GLOB_DAT:
Packit 6c4009
#else
Packit 6c4009
    case R_MIPS_GLOB_DAT:
Packit 6c4009
#endif
Packit 6c4009
      {
Packit 6c4009
	int symidx = ELFW(R_SYM) (r_info);
Packit 6c4009
	const ElfW(Word) gotsym
Packit 6c4009
	  = (const ElfW(Word)) map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;
Packit 6c4009
Packit 6c4009
	if (__builtin_expect ((ElfW(Word)) symidx >= gotsym, 1))
Packit 6c4009
	  {
Packit 6c4009
	    const ElfW(Addr) *got
Packit 6c4009
	      = (const ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
Packit 6c4009
	    const ElfW(Word) local_gotno
Packit 6c4009
	      = ((const ElfW(Word))
Packit 6c4009
		 map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val);
Packit 6c4009
Packit 6c4009
	    ElfW(Addr) reloc_value = got[symidx + local_gotno - gotsym];
Packit 6c4009
	    __builtin_memcpy (reloc_addr, &reloc_value, sizeof (reloc_value));
Packit 6c4009
	  }
Packit 6c4009
      }
Packit 6c4009
      break;
Packit 6c4009
#endif
Packit 6c4009
    case R_MIPS_NONE:		/* Alright, Wilbur.  */
Packit 6c4009
      break;
Packit 6c4009
Packit 6c4009
    case R_MIPS_JUMP_SLOT:
Packit 6c4009
      {
Packit 6c4009
	struct link_map *sym_map;
Packit 6c4009
	ElfW(Addr) value;
Packit 6c4009
Packit 6c4009
	/* The addend for a jump slot relocation must always be zero:
Packit 6c4009
	   calls via the PLT always branch to the symbol's address and
Packit 6c4009
	   not to the address plus a non-zero offset.  */
Packit 6c4009
	if (r_addend != 0)
Packit 6c4009
	  _dl_signal_error (0, map->l_name, NULL,
Packit 6c4009
			    "found jump slot relocation with non-zero addend");
Packit 6c4009
Packit 6c4009
	sym_map = RESOLVE_MAP (&sym, version, r_type);
Packit 6c4009
	value = SYMBOL_ADDRESS (sym_map, sym, true);
Packit 6c4009
	*addr_field = value;
Packit 6c4009
Packit 6c4009
	break;
Packit 6c4009
      }
Packit 6c4009
Packit 6c4009
    case R_MIPS_COPY:
Packit 6c4009
      {
Packit 6c4009
	const ElfW(Sym) *const refsym = sym;
Packit 6c4009
	struct link_map *sym_map;
Packit 6c4009
	ElfW(Addr) value;
Packit 6c4009
Packit 6c4009
	/* Calculate the address of the symbol.  */
Packit 6c4009
	sym_map = RESOLVE_MAP (&sym, version, r_type);
Packit 6c4009
	value = SYMBOL_ADDRESS (sym_map, sym, true);
Packit 6c4009
Packit 6c4009
	if (__builtin_expect (sym == NULL, 0))
Packit 6c4009
	  /* This can happen in trace mode if an object could not be
Packit 6c4009
	     found.  */
Packit 6c4009
	  break;
Packit 6c4009
	if (__builtin_expect (sym->st_size > refsym->st_size, 0)
Packit 6c4009
	    || (__builtin_expect (sym->st_size < refsym->st_size, 0)
Packit 6c4009
		&& GLRO(dl_verbose)))
Packit 6c4009
	  {
Packit 6c4009
	    const char *strtab;
Packit 6c4009
Packit 6c4009
	    strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
Packit 6c4009
	    _dl_error_printf ("\
Packit 6c4009
  %s: Symbol `%s' has different size in shared object, consider re-linking\n",
Packit 6c4009
			      RTLD_PROGNAME, strtab + refsym->st_name);
Packit 6c4009
	  }
Packit 6c4009
	memcpy (reloc_addr, (void *) value,
Packit 6c4009
		sym->st_size < refsym->st_size
Packit 6c4009
		? sym->st_size : refsym->st_size);
Packit 6c4009
	break;
Packit 6c4009
      }
Packit 6c4009
Packit 6c4009
#if _MIPS_SIM == _ABI64
Packit 6c4009
    case R_MIPS_64:
Packit 6c4009
      /* For full compliance with the ELF64 ABI, one must precede the
Packit 6c4009
	 _REL32/_64 pair of relocations with a _64 relocation, such
Packit 6c4009
	 that the in-place addend is read as a 64-bit value.  IRIX
Packit 6c4009
	 didn't pick up on this requirement, so we treat the
Packit 6c4009
	 _REL32/_64 relocation as a 64-bit relocation even if it's by
Packit 6c4009
	 itself.  For ABI compliance, we ignore such _64 dummy
Packit 6c4009
	 relocations.  For RELA, this may be simply removed, since
Packit 6c4009
	 it's totally unnecessary.  */
Packit 6c4009
      if (ELFW(R_SYM) (r_info) == 0)
Packit 6c4009
	break;
Packit 6c4009
      /* Fall through.  */
Packit 6c4009
#endif
Packit 6c4009
    default:
Packit 6c4009
      _dl_reloc_bad_type (map, r_type, 0);
Packit 6c4009
      break;
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
Packit 6c4009
   MAP is the object containing the reloc.  */
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__ ((always_inline))
Packit 6c4009
elf_machine_rel (struct link_map *map, const ElfW(Rel) *reloc,
Packit 6c4009
		 const ElfW(Sym) *sym, const struct r_found_version *version,
Packit 6c4009
		 void *const reloc_addr, int skip_ifunc)
Packit 6c4009
{
Packit 6c4009
  elf_machine_reloc (map, reloc->r_info, sym, version, reloc_addr, 0, 1);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__((always_inline))
Packit 6c4009
elf_machine_rel_relative (ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
Packit 6c4009
			  void *const reloc_addr)
Packit 6c4009
{
Packit 6c4009
  /* XXX Nothing to do.  There is no relative relocation, right?  */
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__((always_inline))
Packit 6c4009
elf_machine_lazy_rel (struct link_map *map,
Packit 6c4009
		      ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
Packit 6c4009
		      int skip_ifunc)
Packit 6c4009
{
Packit 6c4009
  ElfW(Addr) *const reloc_addr = (void *) (l_addr + reloc->r_offset);
Packit 6c4009
  const unsigned int r_type = ELFW(R_TYPE) (reloc->r_info);
Packit 6c4009
  /* Check for unexpected PLT reloc type.  */
Packit 6c4009
  if (__builtin_expect (r_type == R_MIPS_JUMP_SLOT, 1))
Packit 6c4009
    {
Packit 6c4009
      if (__builtin_expect (map->l_mach.plt, 0) == 0)
Packit 6c4009
	{
Packit 6c4009
	  /* Nothing is required here since we only support lazy
Packit 6c4009
	     relocation in executables.  */
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	*reloc_addr = map->l_mach.plt;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    _dl_reloc_bad_type (map, r_type, 1);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__ ((always_inline))
Packit 6c4009
elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
Packit 6c4009
		  const ElfW(Sym) *sym, const struct r_found_version *version,
Packit 6c4009
		  void *const reloc_addr, int skip_ifunc)
Packit 6c4009
{
Packit 6c4009
  elf_machine_reloc (map, reloc->r_info, sym, version, reloc_addr,
Packit 6c4009
		     reloc->r_addend, 0);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__((always_inline))
Packit 6c4009
elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
Packit 6c4009
			   void *const reloc_addr)
Packit 6c4009
{
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#ifndef RTLD_BOOTSTRAP
Packit 6c4009
/* Relocate GOT. */
Packit 6c4009
auto inline void
Packit 6c4009
__attribute__((always_inline))
Packit 6c4009
elf_machine_got_rel (struct link_map *map, int lazy)
Packit 6c4009
{
Packit 6c4009
  ElfW(Addr) *got;
Packit 6c4009
  ElfW(Sym) *sym;
Packit 6c4009
  const ElfW(Half) *vernum;
Packit 6c4009
  int i, n, symidx;
Packit 6c4009
Packit 6c4009
#define RESOLVE_GOTSYM(sym,vernum,sym_index,reloc)			  \
Packit 6c4009
    ({									  \
Packit 6c4009
      const ElfW(Sym) *ref = sym;					  \
Packit 6c4009
      const struct r_found_version *version __attribute__ ((unused))	  \
Packit 6c4009
	= vernum ? &map->l_versions[vernum[sym_index] & 0x7fff] : NULL;	  \
Packit 6c4009
      struct link_map *sym_map;						  \
Packit 6c4009
      sym_map = RESOLVE_MAP (&ref, version, reloc);			  \
Packit 6c4009
      SYMBOL_ADDRESS (sym_map, ref, true);				  \
Packit 6c4009
    })
Packit 6c4009
Packit 6c4009
  if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
Packit 6c4009
    vernum = (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
Packit 6c4009
  else
Packit 6c4009
    vernum = NULL;
Packit 6c4009
Packit 6c4009
  got = (ElfW(Addr) *) D_PTR (map, l_info[DT_PLTGOT]);
Packit 6c4009
Packit 6c4009
  n = map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;
Packit 6c4009
  /* The dynamic linker's local got entries have already been relocated.  */
Packit 6c4009
  if (map != &GL(dl_rtld_map))
Packit 6c4009
    {
Packit 6c4009
      /* got[0] is reserved. got[1] is also reserved for the dynamic object
Packit 6c4009
	 generated by gnu ld. Skip these reserved entries from relocation.  */
Packit 6c4009
      i = (got[1] & ELF_MIPS_GNU_GOT1_MASK)? 2 : 1;
Packit 6c4009
Packit 6c4009
      /* Add the run-time displacement to all local got entries if
Packit 6c4009
	 needed.  */
Packit 6c4009
      if (__builtin_expect (map->l_addr != 0, 0))
Packit 6c4009
	{
Packit 6c4009
	  while (i < n)
Packit 6c4009
	    got[i++] += map->l_addr;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Handle global got entries. */
Packit 6c4009
  got += n;
Packit 6c4009
  /* Keep track of the symbol index.  */
Packit 6c4009
  symidx = map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val;
Packit 6c4009
  sym = (ElfW(Sym) *) D_PTR (map, l_info[DT_SYMTAB]) + symidx;
Packit 6c4009
  i = (map->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val
Packit 6c4009
       - map->l_info[DT_MIPS (GOTSYM)]->d_un.d_val);
Packit 6c4009
Packit 6c4009
  /* This loop doesn't handle Quickstart.  */
Packit 6c4009
  while (i--)
Packit 6c4009
    {
Packit 6c4009
      if (sym->st_shndx == SHN_UNDEF)
Packit 6c4009
	{
Packit 6c4009
	  if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC && sym->st_value
Packit 6c4009
	      && !(sym->st_other & STO_MIPS_PLT))
Packit 6c4009
	    {
Packit 6c4009
	      if (lazy)
Packit 6c4009
		*got = SYMBOL_ADDRESS (map, sym, true);
Packit 6c4009
	      else
Packit 6c4009
		/* This is a lazy-binding stub, so we don't need the
Packit 6c4009
		   canonical address.  */
Packit 6c4009
		*got = RESOLVE_GOTSYM (sym, vernum, symidx, R_MIPS_JUMP_SLOT);
Packit 6c4009
	    }
Packit 6c4009
	  else
Packit 6c4009
	    *got = RESOLVE_GOTSYM (sym, vernum, symidx, R_MIPS_32);
Packit 6c4009
	}
Packit 6c4009
      else if (sym->st_shndx == SHN_COMMON)
Packit 6c4009
	*got = RESOLVE_GOTSYM (sym, vernum, symidx, R_MIPS_32);
Packit 6c4009
      else if (ELFW(ST_TYPE) (sym->st_info) == STT_FUNC
Packit 6c4009
	       && *got != sym->st_value)
Packit 6c4009
	{
Packit 6c4009
	  if (lazy)
Packit 6c4009
	    *got += map->l_addr;
Packit 6c4009
	  else
Packit 6c4009
	    /* This is a lazy-binding stub, so we don't need the
Packit 6c4009
	       canonical address.  */
Packit 6c4009
	    *got = RESOLVE_GOTSYM (sym, vernum, symidx, R_MIPS_JUMP_SLOT);
Packit 6c4009
	}
Packit 6c4009
      else if (ELFW(ST_TYPE) (sym->st_info) == STT_SECTION)
Packit 6c4009
	{
Packit 6c4009
	  if (sym->st_other == 0)
Packit 6c4009
	    *got += map->l_addr;
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	*got = RESOLVE_GOTSYM (sym, vernum, symidx, R_MIPS_32);
Packit 6c4009
Packit 6c4009
      ++got;
Packit 6c4009
      ++sym;
Packit 6c4009
      ++symidx;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
#undef RESOLVE_GOTSYM
Packit 6c4009
}
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Set up the loaded object described by L so its stub function
Packit 6c4009
   will jump to the on-demand fixup code __dl_runtime_resolve.  */
Packit 6c4009
Packit 6c4009
auto inline int
Packit 6c4009
__attribute__((always_inline))
Packit 6c4009
elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
Packit 6c4009
{
Packit 6c4009
# ifndef RTLD_BOOTSTRAP
Packit 6c4009
  ElfW(Addr) *got;
Packit 6c4009
  extern void _dl_runtime_resolve (ElfW(Word));
Packit 6c4009
  extern void _dl_runtime_pltresolve (void);
Packit 6c4009
  extern int _dl_mips_gnu_objects;
Packit 6c4009
Packit 6c4009
  if (lazy)
Packit 6c4009
    {
Packit 6c4009
      /* The GOT entries for functions have not yet been filled in.
Packit 6c4009
	 Their initial contents will arrange when called to put an
Packit 6c4009
	 offset into the .dynsym section in t8, the return address
Packit 6c4009
	 in t7 and then jump to _GLOBAL_OFFSET_TABLE[0].  */
Packit 6c4009
      got = (ElfW(Addr) *) D_PTR (l, l_info[DT_PLTGOT]);
Packit 6c4009
Packit 6c4009
      /* This function will get called to fix up the GOT entry indicated by
Packit 6c4009
	 the register t8, and then jump to the resolved address.  */
Packit 6c4009
      got[0] = (ElfW(Addr)) &_dl_runtime_resolve;
Packit 6c4009
Packit 6c4009
      /* Store l to _GLOBAL_OFFSET_TABLE[1] for gnu object. The MSB
Packit 6c4009
	 of got[1] of a gnu object is set to identify gnu objects.
Packit 6c4009
	 Where we can store l for non gnu objects? XXX  */
Packit 6c4009
      if ((got[1] & ELF_MIPS_GNU_GOT1_MASK) != 0)
Packit 6c4009
	got[1] = ((ElfW(Addr)) l | ELF_MIPS_GNU_GOT1_MASK);
Packit 6c4009
      else
Packit 6c4009
	_dl_mips_gnu_objects = 0;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Relocate global offset table.  */
Packit 6c4009
  elf_machine_got_rel (l, lazy);
Packit 6c4009
Packit 6c4009
  /* If using PLTs, fill in the first two entries of .got.plt.  */
Packit 6c4009
  if (l->l_info[DT_JMPREL] && lazy)
Packit 6c4009
    {
Packit 6c4009
      ElfW(Addr) *gotplt;
Packit 6c4009
      gotplt = (ElfW(Addr) *) D_PTR (l, l_info[DT_MIPS (PLTGOT)]);
Packit 6c4009
      /* If a library is prelinked but we have to relocate anyway,
Packit 6c4009
	 we have to be able to undo the prelinking of .got.plt.
Packit 6c4009
	 The prelinker saved the address of .plt for us here.  */
Packit 6c4009
      if (gotplt[1])
Packit 6c4009
	l->l_mach.plt = gotplt[1] + l->l_addr;
Packit 6c4009
      gotplt[0] = (ElfW(Addr)) &_dl_runtime_pltresolve;
Packit 6c4009
      gotplt[1] = (ElfW(Addr)) l;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
# endif
Packit 6c4009
  return lazy;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif /* RESOLVE_MAP */