ld.so: Replace DL_RO_DYN_SECTION with dl_relocate_ld [BZ #28340]
[platform/upstream/glibc.git] / sysdeps / mips / ldsodefs.h
1 /* Run-time dynamic linker data structures for loaded ELF shared objects.
2    Copyright (C) 2000-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <https://www.gnu.org/licenses/>.  */
18
19 #ifndef _MIPS_LDSODEFS_H
20 #define _MIPS_LDSODEFS_H 1
21
22 #include <elf.h>
23
24 struct La_mips_32_regs;
25 struct La_mips_32_retval;
26 struct La_mips_64_regs;
27 struct La_mips_64_retval;
28
29 #define ELF_MACHINE_GNU_HASH_ADDRIDX (DT_MIPS_XHASH - DT_LOPROC + DT_NUM)
30
31 /* Calculate the index of a symbol in MIPS xhash.  */
32 #define ELF_MACHINE_HASH_SYMIDX(map, hasharr) \
33   ((map)->l_mach.mips_xlat_zero[(hasharr) - (map)->l_gnu_chain_zero])
34
35 /* Setup MIPS xhash.  */
36 #define ELF_MACHINE_XHASH_SETUP(hash32, symbias, map)                       \
37   do                                                                        \
38     {                                                                       \
39       (hash32) += (map)->l_info[DT_MIPS (SYMTABNO)]->d_un.d_val - (symbias); \
40       (map)->l_mach.mips_xlat_zero = (hash32) - (symbias);                  \
41     }                                                                       \
42   while (0)
43
44 #define ARCH_PLTENTER_MEMBERS                                               \
45     Elf32_Addr (*mips_o32_gnu_pltenter) (Elf32_Sym *, unsigned int,         \
46                                          uintptr_t *, uintptr_t *,          \
47                                          struct La_mips_32_regs *,          \
48                                          unsigned int *, const char *name,  \
49                                          long int *framesizep);             \
50     Elf32_Addr (*mips_n32_gnu_pltenter) (Elf32_Sym *, unsigned int,         \
51                                          uintptr_t *, uintptr_t *,          \
52                                          struct La_mips_64_regs *,          \
53                                          unsigned int *, const char *name,  \
54                                          long int *framesizep);             \
55     Elf64_Addr (*mips_n64_gnu_pltenter) (Elf64_Sym *, unsigned int,         \
56                                          uintptr_t *, uintptr_t *,          \
57                                          struct La_mips_64_regs *,          \
58                                          unsigned int *, const char *name,  \
59                                          long int *framesizep);
60
61 #define ARCH_PLTEXIT_MEMBERS                                                \
62     unsigned int (*mips_o32_gnu_pltexit) (Elf32_Sym *, unsigned int,        \
63                                           uintptr_t *, uintptr_t *,         \
64                                           const struct La_mips_32_regs *,   \
65                                           struct La_mips_32_retval *,       \
66                                           const char *);                    \
67     unsigned int (*mips_n32_gnu_pltexit) (Elf32_Sym *, unsigned int,        \
68                                           uintptr_t *, uintptr_t *,         \
69                                           const struct La_mips_64_regs *,   \
70                                           struct La_mips_64_retval *,       \
71                                           const char *);                    \
72     unsigned int (*mips_n64_gnu_pltexit) (Elf64_Sym *, unsigned int,        \
73                                           uintptr_t *, uintptr_t *,         \
74                                           const struct La_mips_64_regs *,   \
75                                           struct La_mips_64_retval *,       \
76                                           const char *);
77
78 #include_next <ldsodefs.h>
79
80 /* The 64-bit MIPS ELF ABI uses an unusual reloc format.  Each
81    relocation entry specifies up to three actual relocations, all at
82    the same address.  The first relocation which required a symbol
83    uses the symbol in the r_sym field.  The second relocation which
84    requires a symbol uses the symbol in the r_ssym field.  If all
85    three relocations require a symbol, the third one uses a zero
86    value.
87
88    We define these structures in internal headers because we're not
89    sure we want to make them part of the ABI yet.  Eventually, some of
90    this may move into elf/elf.h.  */
91
92 /* An entry in a 64 bit SHT_REL section.  */
93
94 typedef struct
95 {
96   Elf32_Word    r_sym;          /* Symbol index */
97   unsigned char r_ssym;         /* Special symbol for 2nd relocation */
98   unsigned char r_type3;        /* 3rd relocation type */
99   unsigned char r_type2;        /* 2nd relocation type */
100   unsigned char r_type1;        /* 1st relocation type */
101 } _Elf64_Mips_R_Info;
102
103 typedef union
104 {
105   Elf64_Xword   r_info_number;
106   _Elf64_Mips_R_Info r_info_fields;
107 } _Elf64_Mips_R_Info_union;
108
109 typedef struct
110 {
111   Elf64_Addr    r_offset;               /* Address */
112   _Elf64_Mips_R_Info_union r_info;      /* Relocation type and symbol index */
113 } Elf64_Mips_Rel;
114
115 typedef struct
116 {
117   Elf64_Addr    r_offset;               /* Address */
118   _Elf64_Mips_R_Info_union r_info;      /* Relocation type and symbol index */
119   Elf64_Sxword  r_addend;               /* Addend */
120 } Elf64_Mips_Rela;
121
122 #define ELF64_MIPS_R_SYM(i) \
123   ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym)
124 #define ELF64_MIPS_R_TYPE(i) \
125   (((_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1 \
126    | ((Elf32_Word)(__extension__ (_Elf64_Mips_R_Info_union)(i) \
127                    ).r_info_fields.r_type2 << 8) \
128    | ((Elf32_Word)(__extension__ (_Elf64_Mips_R_Info_union)(i) \
129                    ).r_info_fields.r_type3 << 16) \
130    | ((Elf32_Word)(__extension__ (_Elf64_Mips_R_Info_union)(i) \
131                    ).r_info_fields.r_ssym << 24))
132 #define ELF64_MIPS_R_INFO(sym, type) \
133   (__extension__ (_Elf64_Mips_R_Info_union) \
134    (__extension__ (_Elf64_Mips_R_Info) \
135    { (sym), ELF64_MIPS_R_SSYM (type), \
136        ELF64_MIPS_R_TYPE3 (type), \
137        ELF64_MIPS_R_TYPE2 (type), \
138        ELF64_MIPS_R_TYPE1 (type) \
139    }).r_info_number)
140 /* These macros decompose the value returned by ELF64_MIPS_R_TYPE, and
141    compose it back into a value that it can be used as an argument to
142    ELF64_MIPS_R_INFO.  */
143 #define ELF64_MIPS_R_SSYM(i) (((i) >> 24) & 0xff)
144 #define ELF64_MIPS_R_TYPE3(i) (((i) >> 16) & 0xff)
145 #define ELF64_MIPS_R_TYPE2(i) (((i) >> 8) & 0xff)
146 #define ELF64_MIPS_R_TYPE1(i) ((i) & 0xff)
147 #define ELF64_MIPS_R_TYPEENC(type1, type2, type3, ssym) \
148   ((type1) \
149    | ((Elf32_Word)(type2) << 8) \
150    | ((Elf32_Word)(type3) << 16) \
151    | ((Elf32_Word)(ssym) << 24))
152
153 #undef ELF64_R_SYM
154 #define ELF64_R_SYM(i) ELF64_MIPS_R_SYM (i)
155 #undef ELF64_R_TYPE
156 #define ELF64_R_TYPE(i) ELF64_MIPS_R_TYPE (i)
157 #undef ELF64_R_INFO
158 #define ELF64_R_INFO(sym, type) ELF64_MIPS_R_INFO ((sym), (type))
159
160 #endif