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/Makefile.arch | 2 +- libc/sysdeps/linux/arm/find_got.c | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 libc/sysdeps/linux/arm/find_got.c (limited to 'libc/sysdeps/linux') diff --git a/libc/sysdeps/linux/arm/Makefile.arch b/libc/sysdeps/linux/arm/Makefile.arch index f9ac88b84..40a0184cb 100644 --- a/libc/sysdeps/linux/arm/Makefile.arch +++ b/libc/sysdeps/linux/arm/Makefile.arch @@ -23,7 +23,7 @@ $(eval $(call cache-output-var,IS_EABI,$(CC_IS_EABI_CHECK) -x c - -E -dM . */ + +#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