xref: /freebsd/lib/libc/csu/aarch64/reloc.c (revision 9684658e35ab033c79e0519e3681d9a194976b71)
151015e6dSKonstantin Belousov /*-
251015e6dSKonstantin Belousov  * Copyright (c) 2019 Leandro Lupori
351015e6dSKonstantin Belousov  * Copyright (c) 2021 The FreeBSD Foundation
451015e6dSKonstantin Belousov  *
551015e6dSKonstantin Belousov  * Portions of this software were developed by Andrew Turner
651015e6dSKonstantin Belousov  * under sponsorship from the FreeBSD Foundation.
751015e6dSKonstantin Belousov  *
851015e6dSKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
951015e6dSKonstantin Belousov  * modification, are permitted provided that the following conditions
1051015e6dSKonstantin Belousov  * are met:
1151015e6dSKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
1251015e6dSKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
1351015e6dSKonstantin Belousov  *
1451015e6dSKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1551015e6dSKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1651015e6dSKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1751015e6dSKonstantin Belousov  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1851015e6dSKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1951015e6dSKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2051015e6dSKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2151015e6dSKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2251015e6dSKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2351015e6dSKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2451015e6dSKonstantin Belousov  * SUCH DAMAGE.
2551015e6dSKonstantin Belousov  */
2651015e6dSKonstantin Belousov 
27*9684658eSJessica Clarke #include <sys/cdefs.h>
28*9684658eSJessica Clarke 
29*9684658eSJessica Clarke static void
ifunc_init(const Elf_Auxinfo * aux __unused)30*9684658eSJessica Clarke ifunc_init(const Elf_Auxinfo *aux __unused)
31*9684658eSJessica Clarke {
32*9684658eSJessica Clarke }
33*9684658eSJessica Clarke 
3451015e6dSKonstantin Belousov static void
crt1_handle_rela(const Elf_Rela * r)3551015e6dSKonstantin Belousov crt1_handle_rela(const Elf_Rela *r)
3651015e6dSKonstantin Belousov {
3751015e6dSKonstantin Belousov 	typedef Elf_Addr (*ifunc_resolver_t)(
3851015e6dSKonstantin Belousov 	    uint64_t, uint64_t, uint64_t, uint64_t,
3951015e6dSKonstantin Belousov 	    uint64_t, uint64_t, uint64_t, uint64_t);
4051015e6dSKonstantin Belousov 	Elf_Addr *ptr, *where, target;
4151015e6dSKonstantin Belousov 
4251015e6dSKonstantin Belousov 	switch (ELF_R_TYPE(r->r_info)) {
4351015e6dSKonstantin Belousov 	case R_AARCH64_IRELATIVE:
4451015e6dSKonstantin Belousov 		ptr = (Elf_Addr *)r->r_addend;
4551015e6dSKonstantin Belousov 		where = (Elf_Addr *)r->r_offset;
4651015e6dSKonstantin Belousov 		target = ((ifunc_resolver_t)ptr)(0, 0, 0, 0, 0, 0, 0, 0);
4751015e6dSKonstantin Belousov 		*where = target;
4851015e6dSKonstantin Belousov 		break;
4951015e6dSKonstantin Belousov 	}
5051015e6dSKonstantin Belousov }
51