~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/objtool/arch/loongarch/orc.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 #include <linux/objtool_types.h>
  3 #include <asm/orc_types.h>
  4 
  5 #include <objtool/check.h>
  6 #include <objtool/orc.h>
  7 #include <objtool/warn.h>
  8 #include <objtool/endianness.h>
  9 
 10 int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
 11 {
 12         struct cfi_reg *fp = &cfi->regs[CFI_FP];
 13         struct cfi_reg *ra = &cfi->regs[CFI_RA];
 14 
 15         memset(orc, 0, sizeof(*orc));
 16 
 17         if (!cfi) {
 18                 /*
 19                  * This is usually either unreachable nops/traps (which don't
 20                  * trigger unreachable instruction warnings), or
 21                  * STACK_FRAME_NON_STANDARD functions.
 22                  */
 23                 orc->type = ORC_TYPE_UNDEFINED;
 24                 return 0;
 25         }
 26 
 27         switch (cfi->type) {
 28         case UNWIND_HINT_TYPE_UNDEFINED:
 29                 orc->type = ORC_TYPE_UNDEFINED;
 30                 return 0;
 31         case UNWIND_HINT_TYPE_END_OF_STACK:
 32                 orc->type = ORC_TYPE_END_OF_STACK;
 33                 return 0;
 34         case UNWIND_HINT_TYPE_CALL:
 35                 orc->type = ORC_TYPE_CALL;
 36                 break;
 37         case UNWIND_HINT_TYPE_REGS:
 38                 orc->type = ORC_TYPE_REGS;
 39                 break;
 40         case UNWIND_HINT_TYPE_REGS_PARTIAL:
 41                 orc->type = ORC_TYPE_REGS_PARTIAL;
 42                 break;
 43         default:
 44                 WARN_INSN(insn, "unknown unwind hint type %d", cfi->type);
 45                 return -1;
 46         }
 47 
 48         orc->signal = cfi->signal;
 49 
 50         switch (cfi->cfa.base) {
 51         case CFI_SP:
 52                 orc->sp_reg = ORC_REG_SP;
 53                 break;
 54         case CFI_FP:
 55                 orc->sp_reg = ORC_REG_FP;
 56                 break;
 57         default:
 58                 WARN_INSN(insn, "unknown CFA base reg %d", cfi->cfa.base);
 59                 return -1;
 60         }
 61 
 62         switch (fp->base) {
 63         case CFI_UNDEFINED:
 64                 orc->fp_reg = ORC_REG_UNDEFINED;
 65                 orc->fp_offset = 0;
 66                 break;
 67         case CFI_CFA:
 68                 orc->fp_reg = ORC_REG_PREV_SP;
 69                 orc->fp_offset = fp->offset;
 70                 break;
 71         case CFI_FP:
 72                 orc->fp_reg = ORC_REG_FP;
 73                 break;
 74         default:
 75                 WARN_INSN(insn, "unknown FP base reg %d", fp->base);
 76                 return -1;
 77         }
 78 
 79         switch (ra->base) {
 80         case CFI_UNDEFINED:
 81                 orc->ra_reg = ORC_REG_UNDEFINED;
 82                 orc->ra_offset = 0;
 83                 break;
 84         case CFI_CFA:
 85                 orc->ra_reg = ORC_REG_PREV_SP;
 86                 orc->ra_offset = ra->offset;
 87                 break;
 88         case CFI_FP:
 89                 orc->ra_reg = ORC_REG_FP;
 90                 break;
 91         default:
 92                 WARN_INSN(insn, "unknown RA base reg %d", ra->base);
 93                 return -1;
 94         }
 95 
 96         orc->sp_offset = cfi->cfa.offset;
 97 
 98         return 0;
 99 }
100 
101 int write_orc_entry(struct elf *elf, struct section *orc_sec,
102                     struct section *ip_sec, unsigned int idx,
103                     struct section *insn_sec, unsigned long insn_off,
104                     struct orc_entry *o)
105 {
106         struct orc_entry *orc;
107 
108         /* populate ORC data */
109         orc = (struct orc_entry *)orc_sec->data->d_buf + idx;
110         memcpy(orc, o, sizeof(*orc));
111 
112         /* populate reloc for ip */
113         if (!elf_init_reloc_text_sym(elf, ip_sec, idx * sizeof(int), idx,
114                                      insn_sec, insn_off))
115                 return -1;
116 
117         return 0;
118 }
119 
120 static const char *reg_name(unsigned int reg)
121 {
122         switch (reg) {
123         case ORC_REG_SP:
124                 return "sp";
125         case ORC_REG_FP:
126                 return "fp";
127         case ORC_REG_PREV_SP:
128                 return "prevsp";
129         default:
130                 return "?";
131         }
132 }
133 
134 static const char *orc_type_name(unsigned int type)
135 {
136         switch (type) {
137         case UNWIND_HINT_TYPE_CALL:
138                 return "call";
139         case UNWIND_HINT_TYPE_REGS:
140                 return "regs";
141         case UNWIND_HINT_TYPE_REGS_PARTIAL:
142                 return "regs (partial)";
143         default:
144                 return "?";
145         }
146 }
147 
148 static void print_reg(unsigned int reg, int offset)
149 {
150         if (reg == ORC_REG_UNDEFINED)
151                 printf(" (und) ");
152         else
153                 printf("%s + %3d", reg_name(reg), offset);
154 
155 }
156 
157 void orc_print_dump(struct elf *dummy_elf, struct orc_entry *orc, int i)
158 {
159         printf("type:%s", orc_type_name(orc[i].type));
160 
161         printf(" sp:");
162         print_reg(orc[i].sp_reg, orc[i].sp_offset);
163 
164         printf(" fp:");
165         print_reg(orc[i].fp_reg, orc[i].fp_offset);
166 
167         printf(" ra:");
168         print_reg(orc[i].ra_reg, orc[i].ra_offset);
169 
170         printf(" signal:%d\n", orc[i].signal);
171 }
172 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php