/*-1* Copyright (c) 2019 Leandro Lupori2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8*9* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND10* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE11* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE12* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE13* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL14* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS15* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)16* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT17* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY18* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF19* SUCH DAMAGE.20*/2122static uint32_t cpu_features;23static uint32_t cpu_features2;2425static void26ifunc_init(const Elf_Auxinfo *aux)27{28/* Digest the auxiliary vector. */29for (; aux->a_type != AT_NULL; aux++) {30switch (aux->a_type) {31case AT_HWCAP:32cpu_features = (uint32_t)aux->a_un.a_val;33break;34case AT_HWCAP2:35cpu_features2 = (uint32_t)aux->a_un.a_val;36break;37}38}39}4041static void42crt1_handle_rela(const Elf_Rela *r)43{44typedef Elf_Addr (*ifunc_resolver_t)(45uint32_t, uint32_t, uint64_t, uint64_t,46uint64_t, uint64_t, uint64_t, uint64_t);47Elf_Addr *ptr, *where, target;4849switch (ELF_R_TYPE(r->r_info)) {50case R_PPC_IRELATIVE:51ptr = (Elf_Addr *)r->r_addend;52where = (Elf_Addr *)r->r_offset;53target = ((ifunc_resolver_t)ptr)(cpu_features, cpu_features2,540, 0, 0, 0, 0, 0);55*where = target;56break;57}58}596061