| 1 | /* |
| 2 | * libhugetlbfs - Easy use of Linux hugepages |
| 3 | * Copyright (C) 2008 Adam Litke, IBM Corporation. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public License |
| 7 | * as published by the Free Software Foundation; either version 2.1 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <elf.h> |
| 21 | #include <link.h> |
| 22 | |
| 23 | #include "libhugetlbfs_internal.h" |
| 24 | |
| 25 | /* |
| 26 | * The powerpc 32-bit ELF ABI defines the location and size of the plt as |
| 27 | * follows (see the ELF ABI and powerpc32 supplement for details): |
| 28 | * |
| 29 | * Location: (data segment p_vaddr) + (data segment p_filesz) |
| 30 | * Size: (dynamic symbol table DT_PTRELSZ entry) + 72 |
| 31 | * |
| 32 | * plt entries have likely been initialized when the libhugetlbfs remapping |
| 33 | * code runs, we must copy these entries when preparing the data segment. Tell |
| 34 | * the arch-independent code how many bytes to copy. |
| 35 | */ |
| 36 | ElfW(Word) plt_extrasz(ElfW(Dyn) *dyntab) |
| 37 | { |
| 38 | int i; |
| 39 | ElfW(Word) pltrelsz = 0; |
| 40 | |
| 41 | /* Find the needed information in the dynamic section */ |
| 42 | for (i = 0; dyntab[i].d_tag != DT_NULL; i++) |
| 43 | if (dyntab[i].d_tag == DT_PLTRELSZ) |
| 44 | pltrelsz = dyntab[i].d_un.d_val; |
| 45 | |
| 46 | /* pltrelsz indicates the size of all plt entries used to cache |
| 47 | * symbol lookups, but does not include the reserved entry at PLT[0]. |
| 48 | * 72 bytes is the ABI-defined size of a plt entry. |
| 49 | */ |
| 50 | if (pltrelsz) |
| 51 | return pltrelsz + 72; |
| 52 | else |
| 53 | return 0; |
| 54 | } |