Path: blob/main/libexec/rtld-elf/aarch64/rtld_machdep.h
34875 views
/*-1* Copyright (c) 1999, 2000 John D. Polstra.2* Copyright (c) 2014 the FreeBSD Foundation3* All rights reserved.4*5* Portions of this software were developed by Andrew Turner6* under sponsorship from the FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#ifndef RTLD_MACHDEP_H31#define RTLD_MACHDEP_H 13233#include <sys/types.h>34#include <machine/atomic.h>35#include <machine/tls.h>3637struct Struct_Obj_Entry;3839#define MD_OBJ_ENTRY \40bool variant_pcs : 1; /* Object has a variant pcs function */4142/* Return the address of the .dynamic section in the dynamic linker. */43#define rtld_dynamic(obj) \44({ \45Elf_Addr _dynamic_addr; \46asm volatile("adr %0, _DYNAMIC" : "=&r"(_dynamic_addr)); \47(const Elf_Dyn *)_dynamic_addr; \48})4950bool arch_digest_dynamic(struct Struct_Obj_Entry *obj, const Elf_Dyn *dynp);5152bool arch_digest_note(struct Struct_Obj_Entry *obj, const Elf_Note *note);5354Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,55const struct Struct_Obj_Entry *defobj, const struct Struct_Obj_Entry *obj,56const Elf_Rel *rel);5758#define make_function_pointer(def, defobj) \59((defobj)->relocbase + (def)->st_value)6061#define call_initfini_pointer(obj, target) \62(((InitFunc)(target))())6364#define call_init_pointer(obj, target) \65(((InitArrFunc)(target))(main_argc, main_argv, environ))6667/*68* Pass zeros into the ifunc resolver so we can change them later. The first69* 8 arguments on arm64 are passed in registers so make them known values70* if we decide to use them later. Because of this ifunc resolvers can assume71* no arguments are passed in, and if this changes later will be able to72* compare the argument with 0 to see if it is set.73*/74#define call_ifunc_resolver(ptr) \75(((Elf_Addr (*)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, \76uint64_t, uint64_t, uint64_t))ptr)(0, 0, 0, 0, 0, 0, 0, 0))7778#define round(size, align) \79(((size) + (align) - 1) & ~((align) - 1))80#define calculate_first_tls_offset(size, align, offset) \81round(16, align)82#define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \83round(prev_offset + prev_size, align)84#define calculate_tls_post_size(align) \85round(TLS_TCB_SIZE, align) - TLS_TCB_SIZE8687typedef struct {88unsigned long ti_module;89unsigned long ti_offset;90} tls_index;9192extern void *__tls_get_addr(tls_index *ti);9394#define md_abi_variant_hook(x)9596#endif979899