From ae80d12e5f55ad491d1f1e6fe094bc291d908903 Mon Sep 17 00:00:00 2001 From: Christophe Lyon Date: Wed, 4 Jul 2018 17:55:22 +0200 Subject: Add runtime support needed for C++ exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements __gnu_Unwind_Find_got(), which is called from libgcc while unwinding. * libc/sysdeps/linux/arm/Makefile.arch (CSRC): Add find._got.c. * libc/sysdeps/linux/arm/find_got.c: New file. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon --- libc/sysdeps/linux/arm/find_got.c | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 libc/sysdeps/linux/arm/find_got.c (limited to 'libc/sysdeps/linux/arm/find_got.c') diff --git a/libc/sysdeps/linux/arm/find_got.c b/libc/sysdeps/linux/arm/find_got.c new file mode 100644 index 000000000..129238872 --- /dev/null +++ b/libc/sysdeps/linux/arm/find_got.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +#if __FDPIC__ +#include + +struct got_callback_data +{ + _Unwind_Ptr pc; + _Unwind_Ptr got; +}; + +static __always_inline int +__dl_addr_in_loadaddr(void *p, struct elf32_fdpic_loadaddr loadaddr) +{ + struct elf32_fdpic_loadmap *map = loadaddr.map; + int c; + + for (c = 0; c < map->nsegs; c++) + if ((void *)map->segs[c].addr <= p && + (char *)p < (char *)map->segs[c].addr + map->segs[c].p_memsz) + return 1; + + return 0; +} + +/* Callback to return the GOT value if the module contains PC. */ +static int +find_got_callback (struct dl_phdr_info * info, size_t size, void * ptr) +{ + int match = 0; + struct got_callback_data *data = (struct got_callback_data *) ptr; + + if (__dl_addr_in_loadaddr((void *) data->pc, info->dlpi_addr)) { + match = 1; + data->got = (_Unwind_Ptr) info->dlpi_addr.got_value; + } + + return match; +} + +/* Find the GOT that corresponds to the module containing PC. */ +_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc); +_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc) +{ + struct got_callback_data data; + + data.pc = pc; + if (dl_iterate_phdr (find_got_callback, &data) <= 0) + return 0; + + return data.got; +} +#endif + -- cgit v1.2.3