xref: /openbsd/libexec/ld.so/mips64/archdep.h (revision 73471bf0)
1 /*	$OpenBSD: archdep.h,v 1.16 2021/11/14 22:07:39 guenther Exp $ */
2 
3 /*
4  * Copyright (c) 1998-2002 Opsycon AB, Sweden.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef _MIPS_ARCHDEP_H_
30 #define _MIPS_ARCHDEP_H_
31 
32 #define	RELOC_TAG	DT_REL
33 #define	MACHID		EM_MIPS		/* ELF e_machine ID value checked */
34 
35 #include <elf.h>
36 #include <machine/reloc.h>
37 #include "syscall.h"
38 #include "util.h"
39 
40 
41 /* Only used in lib/csu/mips64/boot_md.h */
42 #define RELOC_DYN(relp, symp, adrp, val)				\
43 do {									\
44 	if (ELF_R_TYPE(relp->r_info) == R_MIPS_REL32_64) {		\
45 		if (ELF_R_SYM(relp->r_info) != 0)			\
46 			*adrp += symp->st_value + val;			\
47 		else							\
48 			*adrp += val;					\
49 	} else if (ELF_R_TYPE(relp->r_info) != R_MIPS_NONE) {		\
50 		_dl_exit(ELF_R_TYPE(relp->r_info)+100);			\
51 	}								\
52 } while (0)
53 
54 #define RELOC_GOT(obj, off)						\
55 do {									\
56 	struct boot_dyn *__dynld = obj;					\
57 	long __loff = off;						\
58 	Elf_Addr *gotp;							\
59 	int i, n;							\
60 	const Elf_Sym *sp;						\
61 									\
62 	/* Do all local gots */						\
63 	gotp = __dynld->dt_pltgot;					\
64 	n = __dynld->dt_proc[DT_MIPS_LOCAL_GOTNO - DT_LOPROC];		\
65 									\
66 	for (i = ((gotp[1] & 0x0000000080000000) ? 2 : 1); i < n; i++) {\
67 		gotp[i] += __loff;					\
68 	}								\
69 	gotp += n;							\
70 									\
71 	/* Do symbol referencing gots. There should be no global... */	\
72 	n =  __dynld->dt_proc[DT_MIPS_SYMTABNO - DT_LOPROC] -		\
73 	  __dynld->dt_proc[DT_MIPS_GOTSYM - DT_LOPROC];			\
74 	sp = __dynld->dt_symtab;					\
75 	sp += __dynld->dt_proc[DT_MIPS_GOTSYM - DT_LOPROC];		\
76 									\
77 	while (n--) {							\
78 		if (sp->st_shndx == SHN_UNDEF ||			\
79 		    sp->st_shndx == SHN_COMMON) {			\
80 			if (ELF_ST_BIND(sp->st_info) != STB_WEAK)	\
81 				_dl_exit(7);				\
82 		} else if (ELF_ST_TYPE(sp->st_info) == STT_FUNC) {	\
83 			*gotp += __loff;				\
84 		} else {						\
85 			*gotp = sp->st_value + __loff;			\
86 		}							\
87 		gotp++;							\
88 		sp++;							\
89 	}								\
90 } while (0)
91 
92 #endif /* _MIPS_ARCHDEP_H_ */
93