Blame sysdeps/ia64/dl-machine.h

Packit 6c4009
/* Machine-dependent ELF dynamic relocation inline functions.  IA-64 version.
Packit 6c4009
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
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
#ifndef dl_machine_h
Packit 6c4009
#define dl_machine_h 1
Packit 6c4009
Packit 6c4009
#define ELF_MACHINE_NAME "ia64"
Packit 6c4009
Packit 6c4009
#include <assert.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <link.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <dl-fptr.h>
Packit 6c4009
#include <tls.h>
Packit 6c4009
Packit 6c4009
/* Translate a processor specific dynamic tag to the index
Packit 6c4009
   in l_info array.  */
Packit 6c4009
#define DT_IA_64(x) (DT_IA_64_##x - DT_LOPROC + DT_NUM)
Packit 6c4009
Packit 6c4009
static inline void __attribute__ ((always_inline))
Packit 6c4009
__ia64_init_bootstrap_fdesc_table (struct link_map *map)
Packit 6c4009
{
Packit 6c4009
  Elf64_Addr *boot_table;
Packit 6c4009
Packit 6c4009
  /* careful: this will be called before got has been relocated... */
Packit 6c4009
  asm (";; addl %0 = @gprel (_dl_boot_fptr_table), gp" : "=r"(boot_table));
Packit 6c4009
Packit 6c4009
  map->l_mach.fptr_table_len = ELF_MACHINE_BOOT_FPTR_TABLE_LEN;
Packit 6c4009
  map->l_mach.fptr_table = boot_table;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info)		\
Packit 6c4009
	__ia64_init_bootstrap_fdesc_table (BOOTSTRAP_MAP);
Packit 6c4009
Packit 6c4009
/* Return nonzero iff ELF header is compatible with the running host.  */
Packit 6c4009
static inline int __attribute__ ((unused))
Packit 6c4009
elf_machine_matches_host (const Elf64_Ehdr *ehdr)
Packit 6c4009
{
Packit 6c4009
  return ehdr->e_machine == EM_IA_64;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return the link-time address of _DYNAMIC.  */
Packit 6c4009
static inline Elf64_Addr __attribute__ ((unused, const))
Packit 6c4009
elf_machine_dynamic (void)
Packit 6c4009
{
Packit 6c4009
  Elf64_Addr *p;
Packit 6c4009
Packit 6c4009
  __asm__ (
Packit 6c4009
	".section .sdata\n"
Packit 6c4009
	"	.type __dynamic_ltv#, @object\n"
Packit 6c4009
	"	.size __dynamic_ltv#, 8\n"
Packit 6c4009
	"__dynamic_ltv:\n"
Packit 6c4009
	"	data8	@ltv(_DYNAMIC#)\n"
Packit 6c4009
	".previous\n"
Packit 6c4009
	"	addl	%0 = @gprel(__dynamic_ltv#), gp ;;"
Packit 6c4009
	: "=r" (p));
Packit 6c4009
Packit 6c4009
  return *p;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return the run-time load address of the shared object.  */
Packit 6c4009
static inline Elf64_Addr __attribute__ ((unused))
Packit 6c4009
elf_machine_load_address (void)
Packit 6c4009
{
Packit 6c4009
  Elf64_Addr ip;
Packit 6c4009
  int *p;
Packit 6c4009
Packit 6c4009
  __asm__ (
Packit 6c4009
	"1:	mov %0 = ip\n"
Packit 6c4009
	".section .sdata\n"
Packit 6c4009
	"2:	data4	@ltv(1b)\n"
Packit 6c4009
	"       .align 8\n"
Packit 6c4009
	".previous\n"
Packit 6c4009
	"	addl	%1 = @gprel(2b), gp ;;"
Packit 6c4009
	: "=r" (ip), "=r" (p));
Packit 6c4009
Packit 6c4009
  return ip - (Elf64_Addr) *p;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Set up the loaded object described by L so its unrelocated PLT
Packit 6c4009
   entries will jump to the on-demand fixup code in dl-runtime.c.  */
Packit 6c4009
Packit 6c4009
static inline int __attribute__ ((unused, always_inline))
Packit 6c4009
elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
Packit 6c4009
{
Packit 6c4009
  extern void _dl_runtime_resolve (void);
Packit 6c4009
  extern void _dl_runtime_profile (void);
Packit 6c4009
Packit 6c4009
  if (lazy)
Packit 6c4009
    {
Packit 6c4009
      register Elf64_Addr gp __asm__ ("gp");
Packit 6c4009
      Elf64_Addr *reserve, doit;
Packit 6c4009
Packit 6c4009
      /*
Packit 6c4009
       * Careful with the typecast here or it will try to add l-l_addr
Packit 6c4009
       * pointer elements
Packit 6c4009
       */
Packit 6c4009
      reserve = ((Elf64_Addr *)
Packit 6c4009
		 (l->l_info[DT_IA_64 (PLT_RESERVE)]->d_un.d_ptr + l->l_addr));
Packit 6c4009
      /* Identify this shared object.  */
Packit 6c4009
      reserve[0] = (Elf64_Addr) l;
Packit 6c4009
Packit 6c4009
      /* This function will be called to perform the relocation.  */
Packit 6c4009
      if (!profile)
Packit 6c4009
	doit = (Elf64_Addr) ELF_PTR_TO_FDESC (&_dl_runtime_resolve)->ip;
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  if (GLRO(dl_profile) != NULL
Packit 6c4009
	      && _dl_name_match_p (GLRO(dl_profile), l))
Packit 6c4009
	    {
Packit 6c4009
	      /* This is the object we are looking for.  Say that we really
Packit 6c4009
		 want profiling and the timers are started.  */
Packit 6c4009
	      GL(dl_profile_map) = l;
Packit 6c4009
	    }
Packit 6c4009
	  doit = (Elf64_Addr) ELF_PTR_TO_FDESC (&_dl_runtime_profile)->ip;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      reserve[1] = doit;
Packit 6c4009
      reserve[2] = gp;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return lazy;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Names of the architecture-specific auditing callback functions.  */
Packit 6c4009
#define ARCH_LA_PLTENTER ia64_gnu_pltenter
Packit 6c4009
#define ARCH_LA_PLTEXIT ia64_gnu_pltexit
Packit 6c4009
Packit 6c4009
/* Undo the adds out0 = 16, sp below to get at the value we want in
Packit 6c4009
   __libc_stack_end.  */
Packit 6c4009
#define DL_STACK_END(cookie) \
Packit 6c4009
  ((void *) (((long) (cookie)) - 16))
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
Packit 6c4009
#define RTLD_START asm (						      \
Packit 6c4009
".text\n"								      \
Packit 6c4009
"	.global _start#\n"						      \
Packit 6c4009
"	.proc _start#\n"						      \
Packit 6c4009
"_start:\n"								      \
Packit 6c4009
"0:	{ .mii\n"							      \
Packit 6c4009
"	  .prologue\n"							      \
Packit 6c4009
"	  .save rp, r0\n"						      \
Packit 6c4009
"	  .body\n"							      \
Packit 6c4009
"	  .prologue\n"							      \
Packit 6c4009
"	  .save ar.pfs, r32\n"						      \
Packit 6c4009
"	  alloc loc0 = ar.pfs, 0, 3, 4, 0\n"				      \
Packit 6c4009
"	  .body\n"							      \
Packit 6c4009
"	  mov r2 = ip\n"						      \
Packit 6c4009
"	  addl r3 = @gprel(0b), r0\n"					      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mlx\n"							      \
Packit 6c4009
"	  /* Calculate the GP, and save a copy in loc1.  */\n"		      \
Packit 6c4009
"	  sub gp = r2, r3\n"						      \
Packit 6c4009
"	  movl r8 = 0x9804c0270033f\n"					      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mii\n"							      \
Packit 6c4009
"	  mov ar.fpsr = r8\n"						      \
Packit 6c4009
"	  sub loc1 = r2, r3\n"						      \
Packit 6c4009
"	  /* _dl_start wants a pointer to the pointer to the arg block and\n" \
Packit 6c4009
"	     the arg block starts with an integer, thus the magic 16. */\n"   \
Packit 6c4009
"	  adds out0 = 16, sp\n"						      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .bbb\n"							      \
Packit 6c4009
"	  br.call.sptk.many b0 = _dl_start#\n"				      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	.endp _start#\n"						      \
Packit 6c4009
"	/* FALLTHRU */\n"						      \
Packit 6c4009
"	.global _dl_start_user#\n"					      \
Packit 6c4009
"	.proc _dl_start_user#\n"					      \
Packit 6c4009
"_dl_start_user:\n"							      \
Packit 6c4009
"	 .prologue\n"							      \
Packit 6c4009
"	 .save rp, r0\n"						      \
Packit 6c4009
"	  .body\n"							      \
Packit 6c4009
"	 .prologue\n"							      \
Packit 6c4009
"	 .save ar.pfs, r32\n"						      \
Packit 6c4009
"	 .body\n"							      \
Packit 6c4009
"	{ .mii\n"							      \
Packit 6c4009
"	  addl r3 = @gprel(_dl_skip_args), gp\n"			      \
Packit 6c4009
"	  adds r11 = 24, sp	/* Load the address of argv. */\n"	      \
Packit 6c4009
"	  /* Save the pointer to the user entry point fptr in loc2.  */\n"    \
Packit 6c4009
"	  mov loc2 = ret0\n"						      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mii\n"							      \
Packit 6c4009
"	  ld4 r3 = [r3]\n"						      \
Packit 6c4009
"	  adds r10 = 16, sp	/* Load the address of argc. */\n"	      \
Packit 6c4009
"	  mov out2 = r11\n"						      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	  /* See if we were run as a command with the executable file\n"      \
Packit 6c4009
"	     name as an extra leading argument.  If so, adjust the argv\n"    \
Packit 6c4009
"	     pointer to skip _dl_skip_args words.\n"			      \
Packit 6c4009
"	     Note that _dl_skip_args is an integer, not a long - Jes\n"	      \
Packit 6c4009
"\n"									      \
Packit 6c4009
"	     The stack pointer has to be 16 byte aligned. We cannot simply\n" \
Packit 6c4009
"	     addjust the stack pointer. We have to move the whole argv and\n" \
Packit 6c4009
"	     envp and adjust _dl_argv by _dl_skip_args.  H.J.  */\n"	      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mib\n"							      \
Packit 6c4009
"	  ld8 out1 = [r10]	/* is argc actually stored as a long\n"	      \
Packit 6c4009
"				   or as an int? */\n"			      \
Packit 6c4009
"	  addl r2 = @ltoff(_dl_argv), gp\n"				      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mmi\n"							      \
Packit 6c4009
"	  ld8 r2 = [r2]		/* Get the address of _dl_argv. */\n"	      \
Packit 6c4009
"	  sub out1 = out1, r3	/* Get the new argc. */\n"		      \
Packit 6c4009
"	  shladd r3 = r3, 3, r0\n"					      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{\n"								      \
Packit 6c4009
"	  .mib\n"							      \
Packit 6c4009
"	  ld8 r17 = [r2]	/* Get _dl_argv. */\n"			      \
Packit 6c4009
"	  add r15 = r11, r3	/* The address of the argv we move */\n"      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	/* ??? Could probably merge these two loops into 3 bundles.\n"	      \
Packit 6c4009
"	   using predication to control which set of copies we're on.  */\n"  \
Packit 6c4009
"1:	/* Copy argv. */\n"						      \
Packit 6c4009
"	{ .mfi\n"							      \
Packit 6c4009
"	  ld8 r16 = [r15], 8	/* Load the value in the old argv. */\n"      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mib\n"							      \
Packit 6c4009
"	  st8 [r11] = r16, 8	/* Store it in the new argv. */\n"	      \
Packit 6c4009
"	  cmp.ne p6, p7 = 0, r16\n"					      \
Packit 6c4009
"(p6)	  br.cond.dptk.few 1b\n"					      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mmi\n"							      \
Packit 6c4009
"	  mov out3 = r11\n"						      \
Packit 6c4009
"	  sub r17 = r17, r3	/* Substract _dl_skip_args. */\n"	      \
Packit 6c4009
"	  addl out0 = @gprel(_rtld_local), gp\n"			      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"1:	/* Copy env. */\n"						      \
Packit 6c4009
"	{ .mfi\n"							      \
Packit 6c4009
"	  ld8 r16 = [r15], 8	/* Load the value in the old env. */\n"	      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mib\n"							      \
Packit 6c4009
"	  st8 [r11] = r16, 8	/* Store it in the new env. */\n"	      \
Packit 6c4009
"	  cmp.ne p6, p7 = 0, r16\n"					      \
Packit 6c4009
"(p6)	  br.cond.dptk.few 1b\n"					      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mmb\n"							      \
Packit 6c4009
"	  st8 [r10] = out1		/* Record the new argc. */\n"	      \
Packit 6c4009
"	  ld8 out0 = [out0]		/* get the linkmap */\n"	      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mmb\n"							      \
Packit 6c4009
"	  st8 [r2] = r17		/* Load the new _dl_argv. */\n"	      \
Packit 6c4009
"	  br.call.sptk.many b0 = _dl_init#\n"				      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	/* Pass our finalizer function to the user,\n"			      \
Packit 6c4009
"	   and jump to the user's entry point.  */\n"			      \
Packit 6c4009
"	{ .mmi\n"							      \
Packit 6c4009
"	  ld8 r3 = [loc2], 8\n"						      \
Packit 6c4009
"	  mov b0 = r0\n"						      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mmi\n"							      \
Packit 6c4009
"	  addl ret0 = @ltoff(@fptr(_dl_fini#)), gp\n"			      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	  mov b6 = r3\n"						      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mmi\n"							      \
Packit 6c4009
"	  ld8 ret0 = [ret0]\n"						      \
Packit 6c4009
"	  ld8 gp = [loc2]\n"						      \
Packit 6c4009
"	  mov ar.pfs = loc0\n"						      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	{ .mfb\n"							      \
Packit 6c4009
"	  br.sptk.many b6\n"						      \
Packit 6c4009
"	  ;;\n"								      \
Packit 6c4009
"	}\n"								      \
Packit 6c4009
"	.endp _dl_start_user#\n"					      \
Packit 6c4009
".previous\n");
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifndef RTLD_START_SPECIAL_INIT
Packit 6c4009
#define RTLD_START_SPECIAL_INIT /* nothing */
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or TLS
Packit 6c4009
   variable, so undefined references should not be allowed to define the
Packit 6c4009
   value.
Packit 6c4009
   ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
Packit 6c4009
   of the main executable's symbols, as for a COPY reloc, which we don't
Packit 6c4009
   use.  */
Packit 6c4009
/* ??? Ignore *MSB for now.  */
Packit 6c4009
#define elf_machine_type_class(type) \
Packit 6c4009
  (((type) == R_IA64_IPLTLSB || (type) == R_IA64_DTPMOD64LSB		      \
Packit 6c4009
    || (type) == R_IA64_DTPREL64LSB || (type) == R_IA64_TPREL64LSB)	      \
Packit 6c4009
   * ELF_RTYPE_CLASS_PLT)
Packit 6c4009
Packit 6c4009
/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
Packit 6c4009
#define ELF_MACHINE_JMP_SLOT	 R_IA64_IPLTLSB
Packit 6c4009
Packit 6c4009
/* According to the IA-64 specific documentation, Rela is always used.  */
Packit 6c4009
#define ELF_MACHINE_NO_REL 1
Packit 6c4009
#define ELF_MACHINE_NO_RELA 0
Packit 6c4009
Packit 6c4009
/* Return the address of the entry point. */
Packit 6c4009
#define ELF_MACHINE_START_ADDRESS(map, start)			\
Packit 6c4009
({								\
Packit 6c4009
	ElfW(Addr) addr;					\
Packit 6c4009
	DL_DT_FUNCTION_ADDRESS(map, start, static, addr)	\
Packit 6c4009
	addr;							\
Packit 6c4009
})
Packit 6c4009
Packit 6c4009
/* Fixup a PLT entry to bounce directly to the function at VALUE.  */
Packit 6c4009
static inline struct fdesc __attribute__ ((always_inline))
Packit 6c4009
elf_machine_fixup_plt (struct link_map *l, lookup_t t,
Packit 6c4009
		       const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
Packit 6c4009
		       const Elf64_Rela *reloc,
Packit 6c4009
		       Elf64_Addr *reloc_addr, struct fdesc value)
Packit 6c4009
{
Packit 6c4009
  /* l is the link_map for the caller, t is the link_map for the object
Packit 6c4009
   * being called */
Packit 6c4009
  /* got has already been relocated in elf_get_dynamic_info() */
Packit 6c4009
  reloc_addr[1] = value.gp;
Packit 6c4009
  /* we need a "release" here to ensure that the gp is visible before
Packit 6c4009
     the code entry point is updated: */
Packit 6c4009
  ((volatile Elf64_Addr *) reloc_addr)[0] = value.ip;
Packit 6c4009
  return value;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Return the final value of a plt relocation.  */
Packit 6c4009
static inline struct fdesc
Packit 6c4009
elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc,
Packit 6c4009
		       struct fdesc value)
Packit 6c4009
{
Packit 6c4009
  /* No need to handle rel vs rela since IA64 is rela only */
Packit 6c4009
  return (struct fdesc) { value.ip + reloc->r_addend, value.gp };
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif /* !dl_machine_h */
Packit 6c4009
Packit 6c4009
#ifdef RESOLVE_MAP
Packit 6c4009
Packit 6c4009
#define R_IA64_TYPE(R)	 ((R) & -8)
Packit 6c4009
#define R_IA64_FORMAT(R) ((R) & 7)
Packit 6c4009
Packit 6c4009
#define R_IA64_FORMAT_32MSB	4
Packit 6c4009
#define R_IA64_FORMAT_32LSB	5
Packit 6c4009
#define R_IA64_FORMAT_64MSB	6
Packit 6c4009
#define R_IA64_FORMAT_64LSB	7
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Perform the relocation specified by RELOC and SYM (which is fully
Packit 6c4009
   resolved).  MAP is the object containing the reloc.  */
Packit 6c4009
auto inline void
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
elf_machine_rela (struct link_map *map,
Packit 6c4009
		  const Elf64_Rela *reloc,
Packit 6c4009
		  const Elf64_Sym *sym,
Packit 6c4009
		  const struct r_found_version *version,
Packit 6c4009
		  void *const reloc_addr_arg,
Packit 6c4009
		  int skip_ifunc)
Packit 6c4009
{
Packit 6c4009
  Elf64_Addr *const reloc_addr = reloc_addr_arg;
Packit 6c4009
  const unsigned long int r_type = ELF64_R_TYPE (reloc->r_info);
Packit 6c4009
  Elf64_Addr value;
Packit 6c4009
Packit 6c4009
#if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC && !defined SHARED
Packit 6c4009
  /* This is defined in rtld.c, but nowhere in the static libc.a; make the
Packit 6c4009
     reference weak so static programs can still link.  This declaration
Packit 6c4009
     cannot be done when compiling rtld.c (i.e.  #ifdef RTLD_BOOTSTRAP)
Packit 6c4009
     because rtld.c contains the common defn for _dl_rtld_map, which is
Packit 6c4009
     incompatible with a weak decl in the same file.  */
Packit 6c4009
  weak_extern (_dl_rtld_map);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  /* We cannot use a switch here because we cannot locate the switch
Packit 6c4009
     jump table until we've self-relocated.  */
Packit 6c4009
Packit 6c4009
#if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
Packit 6c4009
  if (__builtin_expect (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_REL64LSB),
Packit 6c4009
			0))
Packit 6c4009
    {
Packit 6c4009
      assert (ELF64_R_TYPE (reloc->r_info) == R_IA64_REL64LSB);
Packit 6c4009
      value = *reloc_addr;
Packit 6c4009
# if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
Packit 6c4009
      /* Already done in dynamic linker.  */
Packit 6c4009
      if (map != &GL(dl_rtld_map))
Packit 6c4009
# endif
Packit 6c4009
	value += map->l_addr;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
#endif
Packit 6c4009
    if (__builtin_expect (r_type == R_IA64_NONE, 0))
Packit 6c4009
      return;
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      struct link_map *sym_map;
Packit 6c4009
Packit 6c4009
      /* RESOLVE_MAP() will return NULL if it fail to locate the symbol.  */
Packit 6c4009
      if ((sym_map = RESOLVE_MAP (&sym, version, r_type)))
Packit 6c4009
	{
Packit 6c4009
	  value = SYMBOL_ADDRESS (sym_map, sym, true) + reloc->r_addend;
Packit 6c4009
Packit 6c4009
	  if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_DIR64LSB))
Packit 6c4009
	    ;/* No adjustment.  */
Packit 6c4009
	  else if (r_type == R_IA64_IPLTLSB)
Packit 6c4009
	    {
Packit 6c4009
	      elf_machine_fixup_plt (NULL, NULL, NULL, NULL, reloc, reloc_addr,
Packit 6c4009
				     DL_FIXUP_MAKE_VALUE (sym_map, value));
Packit 6c4009
	      return;
Packit 6c4009
	    }
Packit 6c4009
	  else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_FPTR64LSB))
Packit 6c4009
	    value = _dl_make_fptr (sym_map, sym, value);
Packit 6c4009
	  else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_PCREL64LSB))
Packit 6c4009
	    value -= (Elf64_Addr) reloc_addr & -16;
Packit 6c4009
	  else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_DTPMOD64LSB))
Packit 6c4009
#ifdef RTLD_BOOTSTRAP
Packit 6c4009
	    /* During startup the dynamic linker is always index 1.  */
Packit 6c4009
	    value = 1;
Packit 6c4009
#else
Packit 6c4009
	    /* Get the information from the link map returned by the
Packit 6c4009
	       resolv function.  */
Packit 6c4009
	    value = sym_map->l_tls_modid;
Packit 6c4009
	  else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_DTPREL64LSB))
Packit 6c4009
	    value -= sym_map->l_addr;
Packit 6c4009
#endif
Packit 6c4009
	  else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_TPREL64LSB))
Packit 6c4009
	    {
Packit 6c4009
#ifndef RTLD_BOOTSTRAP
Packit 6c4009
	      CHECK_STATIC_TLS (map, sym_map);
Packit 6c4009
#endif
Packit 6c4009
	      value += sym_map->l_tls_offset - sym_map->l_addr;
Packit 6c4009
	    }
Packit 6c4009
	  else
Packit 6c4009
	    _dl_reloc_bad_type (map, r_type, 0);
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	value = 0;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* ??? Ignore MSB and Instruction format for now.  */
Packit 6c4009
  if (R_IA64_FORMAT (r_type) == R_IA64_FORMAT_64LSB)
Packit 6c4009
    *reloc_addr = value;
Packit 6c4009
  else if (R_IA64_FORMAT (r_type) == R_IA64_FORMAT_32LSB)
Packit 6c4009
    *(int *) reloc_addr = value;
Packit 6c4009
  else if (r_type == R_IA64_IPLTLSB)
Packit 6c4009
    {
Packit 6c4009
      reloc_addr[0] = 0;
Packit 6c4009
      reloc_addr[1] = 0;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    _dl_reloc_bad_type (map, r_type, 0);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Let do-rel.h know that on IA-64 if l_addr is 0, all RELATIVE relocs
Packit 6c4009
   can be skipped.  */
Packit 6c4009
#define ELF_MACHINE_REL_RELATIVE 1
Packit 6c4009
Packit 6c4009
auto inline void
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
Packit 6c4009
			   void *const reloc_addr_arg)
Packit 6c4009
{
Packit 6c4009
  Elf64_Addr *const reloc_addr = reloc_addr_arg;
Packit 6c4009
  /* ??? Ignore MSB and Instruction format for now.  */
Packit 6c4009
  assert (ELF64_R_TYPE (reloc->r_info) == R_IA64_REL64LSB);
Packit 6c4009
Packit 6c4009
  *reloc_addr += l_addr;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Perform a RELATIVE reloc on the .got entry that transfers to the .plt.  */
Packit 6c4009
auto inline void
Packit 6c4009
__attribute ((always_inline))
Packit 6c4009
elf_machine_lazy_rel (struct link_map *map,
Packit 6c4009
		      Elf64_Addr l_addr, const Elf64_Rela *reloc,
Packit 6c4009
		      int skip_ifunc)
Packit 6c4009
{
Packit 6c4009
  Elf64_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
Packit 6c4009
  const unsigned long int r_type = ELF64_R_TYPE (reloc->r_info);
Packit 6c4009
Packit 6c4009
  if (r_type == R_IA64_IPLTLSB)
Packit 6c4009
    {
Packit 6c4009
      reloc_addr[0] += l_addr;
Packit 6c4009
      reloc_addr[1] += l_addr;
Packit 6c4009
    }
Packit 6c4009
  else if (r_type == R_IA64_NONE)
Packit 6c4009
    return;
Packit 6c4009
  else
Packit 6c4009
    _dl_reloc_bad_type (map, r_type, 1);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif /* RESOLVE_MAP */