Blame elf64ppc.c

Packit 2d622a
/*
Packit 2d622a
 * libhugetlbfs - Easy use of Linux hugepages
Packit 2d622a
 * Copyright (C) 2008 Adam Litke, IBM Corporation.
Packit 2d622a
 *
Packit 2d622a
 * This library is free software; you can redistribute it and/or
Packit 2d622a
 * modify it under the terms of the GNU Lesser General Public License
Packit 2d622a
 * as published by the Free Software Foundation; either version 2.1 of
Packit 2d622a
 * the License, or (at your option) any later version.
Packit 2d622a
 *
Packit 2d622a
 * This library is distributed in the hope that it will be useful, but
Packit 2d622a
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 2d622a
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 2d622a
 * Lesser General Public License for more details.
Packit 2d622a
 *
Packit 2d622a
 * You should have received a copy of the GNU Lesser General Public
Packit 2d622a
 * License along with this library; if not, write to the Free Software
Packit 2d622a
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Packit 2d622a
 */
Packit 2d622a
Packit 2d622a
#include <elf.h>
Packit 2d622a
#include <link.h>
Packit 2d622a
Packit 2d622a
#include "libhugetlbfs_internal.h"
Packit 2d622a
Packit 2d622a
/*
Packit 2d622a
 * The powerpc 64-bit ELF ABI defines the location and size of the plt as
Packit 2d622a
 * follows (see the ELF ABI and powerpc64 supplement for details):
Packit 2d622a
 *
Packit 2d622a
 * Location:   (data segment p_vaddr) + (data segment p_filesz)
Packit 2d622a
 * Size:       (dynamic symbol table DT_PTRELSZ entry) + 24
Packit 2d622a
 *
Packit 2d622a
 * plt entries have likely been initialized when the libhugetlbfs remapping
Packit 2d622a
 * code runs, we must copy these entries when preparing the data segment.  Tell
Packit 2d622a
 * the arch-independent code how many bytes to copy.
Packit 2d622a
 */
Packit 2d622a
ElfW(Word) plt_extrasz(ElfW(Dyn) *dyntab)
Packit 2d622a
{
Packit 2d622a
	int i;
Packit 2d622a
	ElfW(Word) pltrelsz = 0;
Packit 2d622a
Packit 2d622a
	/* Find the needed information in the dynamic section */
Packit 2d622a
	for (i = 0; dyntab[i].d_tag != DT_NULL; i++)
Packit 2d622a
		if (dyntab[i].d_tag == DT_PLTRELSZ)
Packit 2d622a
			pltrelsz = dyntab[i].d_un.d_val;
Packit 2d622a
Packit 2d622a
	/* pltrelsz indicates the size of all plt entries used to cache
Packit 2d622a
	 * symbol lookups, but does not include the reserved entry at PLT[0].
Packit 2d622a
	 * 24 bytes is the ABI-defined size of a plt entry.
Packit 2d622a
	 */
Packit 2d622a
	if (pltrelsz)
Packit 2d622a
		return pltrelsz + 24;
Packit 2d622a
	else
Packit 2d622a
		return 0;
Packit 2d622a
}