2N/A/* dl.c - arch-dependent part of loadable module support */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/dl.h>
2N/A#include <grub/elf.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/err.h>
2N/A#include <grub/mm.h>
2N/A
2N/Avoid
2N/Agrub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
2N/A grub_size_t *got)
2N/A{
2N/A const Elf64_Ehdr *e = ehdr;
2N/A grub_size_t cntt = 0, cntg = 0;;
2N/A const Elf64_Shdr *s;
2N/A unsigned i;
2N/A
2N/A /* Find a symbol table. */
2N/A for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu32 (e->e_shoff));
2N/A i < grub_le_to_cpu16 (e->e_shnum);
2N/A i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize)))
2N/A if (grub_le_to_cpu32 (s->sh_type) == SHT_SYMTAB)
2N/A break;
2N/A
2N/A if (i == grub_le_to_cpu16 (e->e_shnum))
2N/A return;
2N/A
2N/A for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu32 (e->e_shoff));
2N/A i < grub_le_to_cpu16 (e->e_shnum);
2N/A i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize)))
2N/A if (grub_le_to_cpu32 (s->sh_type) == SHT_RELA)
2N/A {
2N/A Elf64_Rela *rel, *max;
2N/A
2N/A for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu32 (s->sh_offset)),
2N/A max = rel + grub_le_to_cpu32 (s->sh_size) / grub_le_to_cpu16 (s->sh_entsize);
2N/A rel < max; rel++)
2N/A switch (ELF64_R_TYPE (grub_le_to_cpu32 (rel->r_info)))
2N/A {
2N/A case R_IA64_PCREL21B:
2N/A cntt++;
2N/A break;
2N/A case R_IA64_LTOFF_FPTR22:
2N/A case R_IA64_LTOFF22X:
2N/A case R_IA64_LTOFF22:
2N/A cntg++;
2N/A break;
2N/A }
2N/A }
2N/A *tramp = cntt;
2N/A *got = cntg;
2N/A}
2N/A