1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
12 #include <objtool/builtin.h>
13 #include <objtool/cfi.h>
14 #include <objtool/arch.h>
15 #include <objtool/check.h>
16 #include <objtool/special.h>
17 #include <objtool/warn.h>
18 #include <objtool/endianness.h>
20 #include <linux/objtool.h>
21 #include <linux/hashtable.h>
22 #include <linux/kernel.h>
23 #include <linux/static_call_types.h>
26 struct list_head list;
27 struct instruction *insn;
31 static unsigned long nr_cfi, nr_cfi_reused, nr_cfi_cache;
33 static struct cfi_init_state initial_func_cfi;
34 static struct cfi_state init_cfi;
35 static struct cfi_state func_cfi;
37 struct instruction *find_insn(struct objtool_file *file,
38 struct section *sec, unsigned long offset)
40 struct instruction *insn;
42 hash_for_each_possible(file->insn_hash, insn, hash, sec_offset_hash(sec, offset)) {
43 if (insn->sec == sec && insn->offset == offset)
50 static struct instruction *next_insn_same_sec(struct objtool_file *file,
51 struct instruction *insn)
53 struct instruction *next = list_next_entry(insn, list);
55 if (!next || &next->list == &file->insn_list || next->sec != insn->sec)
61 static struct instruction *next_insn_same_func(struct objtool_file *file,
62 struct instruction *insn)
64 struct instruction *next = list_next_entry(insn, list);
65 struct symbol *func = insn->func;
70 if (&next->list != &file->insn_list && next->func == func)
73 /* Check if we're already in the subfunction: */
74 if (func == func->cfunc)
77 /* Move to the subfunction: */
78 return find_insn(file, func->cfunc->sec, func->cfunc->offset);
81 static struct instruction *prev_insn_same_sym(struct objtool_file *file,
82 struct instruction *insn)
84 struct instruction *prev = list_prev_entry(insn, list);
86 if (&prev->list != &file->insn_list && prev->func == insn->func)
92 #define func_for_each_insn(file, func, insn) \
93 for (insn = find_insn(file, func->sec, func->offset); \
95 insn = next_insn_same_func(file, insn))
97 #define sym_for_each_insn(file, sym, insn) \
98 for (insn = find_insn(file, sym->sec, sym->offset); \
99 insn && &insn->list != &file->insn_list && \
100 insn->sec == sym->sec && \
101 insn->offset < sym->offset + sym->len; \
102 insn = list_next_entry(insn, list))
104 #define sym_for_each_insn_continue_reverse(file, sym, insn) \
105 for (insn = list_prev_entry(insn, list); \
106 &insn->list != &file->insn_list && \
107 insn->sec == sym->sec && insn->offset >= sym->offset; \
108 insn = list_prev_entry(insn, list))
110 #define sec_for_each_insn_from(file, insn) \
111 for (; insn; insn = next_insn_same_sec(file, insn))
113 #define sec_for_each_insn_continue(file, insn) \
114 for (insn = next_insn_same_sec(file, insn); insn; \
115 insn = next_insn_same_sec(file, insn))
117 static bool is_jump_table_jump(struct instruction *insn)
119 struct alt_group *alt_group = insn->alt_group;
121 if (insn->jump_table)
124 /* Retpoline alternative for a jump table? */
125 return alt_group && alt_group->orig_group &&
126 alt_group->orig_group->first_insn->jump_table;
129 static bool is_sibling_call(struct instruction *insn)
132 * Assume only ELF functions can make sibling calls. This ensures
133 * sibling call detection consistency between vmlinux.o and individual
139 /* An indirect jump is either a sibling call or a jump to a table. */
140 if (insn->type == INSN_JUMP_DYNAMIC)
141 return !is_jump_table_jump(insn);
143 /* add_jump_destinations() sets insn->call_dest for sibling calls. */
144 return (is_static_jump(insn) && insn->call_dest);
148 * This checks to see if the given function is a "noreturn" function.
150 * For global functions which are outside the scope of this object file, we
151 * have to keep a manual list of them.
153 * For local functions, we have to detect them manually by simply looking for
154 * the lack of a return instruction.
156 static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
160 struct instruction *insn;
164 * Unfortunately these have to be hard coded because the noreturn
165 * attribute isn't provided in ELF data.
167 static const char * const global_noreturns[] = {
174 "__module_put_and_kthread_exit",
175 "kthread_complete_and_exit",
180 "machine_real_restart",
181 "rewind_stack_and_make_dead",
182 "kunit_try_catch_throw",
184 "cpu_bringup_and_idle",
189 "__ubsan_handle_builtin_unreachable",
190 "ex_handler_msr_mce",
196 if (func->bind == STB_WEAK)
199 if (func->bind == STB_GLOBAL)
200 for (i = 0; i < ARRAY_SIZE(global_noreturns); i++)
201 if (!strcmp(func->name, global_noreturns[i]))
207 insn = find_insn(file, func->sec, func->offset);
211 func_for_each_insn(file, func, insn) {
214 if (insn->type == INSN_RETURN)
222 * A function can have a sibling call instead of a return. In that
223 * case, the function's dead-end status depends on whether the target
224 * of the sibling call returns.
226 func_for_each_insn(file, func, insn) {
227 if (is_sibling_call(insn)) {
228 struct instruction *dest = insn->jump_dest;
231 /* sibling call to another file */
234 /* local sibling call */
235 if (recursion == 5) {
237 * Infinite recursion: two functions have
238 * sibling calls to each other. This is a very
239 * rare case. It means they aren't dead ends.
244 return __dead_end_function(file, dest->func, recursion+1);
251 static bool dead_end_function(struct objtool_file *file, struct symbol *func)
253 return __dead_end_function(file, func, 0);
256 static void init_cfi_state(struct cfi_state *cfi)
260 for (i = 0; i < CFI_NUM_REGS; i++) {
261 cfi->regs[i].base = CFI_UNDEFINED;
262 cfi->vals[i].base = CFI_UNDEFINED;
264 cfi->cfa.base = CFI_UNDEFINED;
265 cfi->drap_reg = CFI_UNDEFINED;
266 cfi->drap_offset = -1;
269 static void init_insn_state(struct objtool_file *file, struct insn_state *state,
272 memset(state, 0, sizeof(*state));
273 init_cfi_state(&state->cfi);
276 * We need the full vmlinux for noinstr validation, otherwise we can
277 * not correctly determine insn->call_dest->sec (external symbols do
278 * not have a section).
280 if (opts.link && opts.noinstr && sec)
281 state->noinstr = sec->noinstr;
284 static struct cfi_state *cfi_alloc(void)
286 struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
288 WARN("calloc failed");
296 static struct hlist_head *cfi_hash;
298 static inline bool cficmp(struct cfi_state *cfi1, struct cfi_state *cfi2)
300 return memcmp((void *)cfi1 + sizeof(cfi1->hash),
301 (void *)cfi2 + sizeof(cfi2->hash),
302 sizeof(struct cfi_state) - sizeof(struct hlist_node));
305 static inline u32 cfi_key(struct cfi_state *cfi)
307 return jhash((void *)cfi + sizeof(cfi->hash),
308 sizeof(*cfi) - sizeof(cfi->hash), 0);
311 static struct cfi_state *cfi_hash_find_or_add(struct cfi_state *cfi)
313 struct hlist_head *head = &cfi_hash[hash_min(cfi_key(cfi), cfi_bits)];
314 struct cfi_state *obj;
316 hlist_for_each_entry(obj, head, hash) {
317 if (!cficmp(cfi, obj)) {
325 hlist_add_head(&obj->hash, head);
330 static void cfi_hash_add(struct cfi_state *cfi)
332 struct hlist_head *head = &cfi_hash[hash_min(cfi_key(cfi), cfi_bits)];
334 hlist_add_head(&cfi->hash, head);
337 static void *cfi_hash_alloc(unsigned long size)
339 cfi_bits = max(10, ilog2(size));
340 cfi_hash = mmap(NULL, sizeof(struct hlist_head) << cfi_bits,
341 PROT_READ|PROT_WRITE,
342 MAP_PRIVATE|MAP_ANON, -1, 0);
343 if (cfi_hash == (void *)-1L) {
344 WARN("mmap fail cfi_hash");
346 } else if (opts.stats) {
347 printf("cfi_bits: %d\n", cfi_bits);
353 static unsigned long nr_insns;
354 static unsigned long nr_insns_visited;
357 * Call the arch-specific instruction decoder for all the instructions and add
358 * them to the global instruction list.
360 static int decode_instructions(struct objtool_file *file)
364 unsigned long offset;
365 struct instruction *insn;
368 for_each_sec(file, sec) {
370 if (!(sec->sh.sh_flags & SHF_EXECINSTR))
373 if (strcmp(sec->name, ".altinstr_replacement") &&
374 strcmp(sec->name, ".altinstr_aux") &&
375 strncmp(sec->name, ".discard.", 9))
378 if (!strcmp(sec->name, ".noinstr.text") ||
379 !strcmp(sec->name, ".entry.text") ||
380 !strncmp(sec->name, ".text.__x86.", 12))
383 for (offset = 0; offset < sec->sh.sh_size; offset += insn->len) {
384 insn = malloc(sizeof(*insn));
386 WARN("malloc failed");
389 memset(insn, 0, sizeof(*insn));
390 INIT_LIST_HEAD(&insn->alts);
391 INIT_LIST_HEAD(&insn->stack_ops);
392 INIT_LIST_HEAD(&insn->call_node);
395 insn->offset = offset;
397 ret = arch_decode_instruction(file, sec, offset,
398 sec->sh.sh_size - offset,
399 &insn->len, &insn->type,
406 * By default, "ud2" is a dead end unless otherwise
407 * annotated, because GCC 7 inserts it for certain
408 * divide-by-zero cases.
410 if (insn->type == INSN_BUG)
411 insn->dead_end = true;
413 hash_add(file->insn_hash, &insn->hash, sec_offset_hash(sec, insn->offset));
414 list_add_tail(&insn->list, &file->insn_list);
418 list_for_each_entry(func, &sec->symbol_list, list) {
419 if (func->type != STT_FUNC || func->alias != func)
422 if (!find_insn(file, sec, func->offset)) {
423 WARN("%s(): can't find starting instruction",
428 sym_for_each_insn(file, func, insn) {
430 if (insn->type == INSN_ENDBR && list_empty(&insn->call_node)) {
431 if (insn->offset == insn->func->offset) {
432 list_add_tail(&insn->call_node, &file->endbr_list);
435 file->nr_endbr_int++;
443 printf("nr_insns: %lu\n", nr_insns);
453 * Read the pv_ops[] .data table to find the static initialized values.
455 static int add_pv_ops(struct objtool_file *file, const char *symname)
457 struct symbol *sym, *func;
458 unsigned long off, end;
462 sym = find_symbol_by_name(file->elf, symname);
467 end = off + sym->len;
469 rel = find_reloc_by_dest_range(file->elf, sym->sec, off, end - off);
474 if (func->type == STT_SECTION)
475 func = find_symbol_by_offset(rel->sym->sec, rel->addend);
477 idx = (rel->offset - sym->offset) / sizeof(unsigned long);
479 objtool_pv_add(file, idx, func);
481 off = rel->offset + 1;
490 * Allocate and initialize file->pv_ops[].
492 static int init_pv_ops(struct objtool_file *file)
494 static const char *pv_ops_tables[] = {
510 sym = find_symbol_by_name(file->elf, "pv_ops");
514 nr = sym->len / sizeof(unsigned long);
515 file->pv_ops = calloc(sizeof(struct pv_state), nr);
519 for (idx = 0; idx < nr; idx++)
520 INIT_LIST_HEAD(&file->pv_ops[idx].targets);
522 for (idx = 0; (pv_ops = pv_ops_tables[idx]); idx++)
523 add_pv_ops(file, pv_ops);
528 static struct instruction *find_last_insn(struct objtool_file *file,
531 struct instruction *insn = NULL;
533 unsigned int end = (sec->sh.sh_size > 10) ? sec->sh.sh_size - 10 : 0;
535 for (offset = sec->sh.sh_size - 1; offset >= end && !insn; offset--)
536 insn = find_insn(file, sec, offset);
542 * Mark "ud2" instructions and manually annotated dead ends.
544 static int add_dead_ends(struct objtool_file *file)
548 struct instruction *insn;
551 * Check for manually annotated dead ends.
553 sec = find_section_by_name(file->elf, ".rela.discard.unreachable");
557 list_for_each_entry(reloc, &sec->reloc_list, list) {
558 if (reloc->sym->type != STT_SECTION) {
559 WARN("unexpected relocation symbol type in %s", sec->name);
562 insn = find_insn(file, reloc->sym->sec, reloc->addend);
564 insn = list_prev_entry(insn, list);
565 else if (reloc->addend == reloc->sym->sec->sh.sh_size) {
566 insn = find_last_insn(file, reloc->sym->sec);
568 WARN("can't find unreachable insn at %s+0x%" PRIx64,
569 reloc->sym->sec->name, reloc->addend);
573 WARN("can't find unreachable insn at %s+0x%" PRIx64,
574 reloc->sym->sec->name, reloc->addend);
578 insn->dead_end = true;
583 * These manually annotated reachable checks are needed for GCC 4.4,
584 * where the Linux unreachable() macro isn't supported. In that case
585 * GCC doesn't know the "ud2" is fatal, so it generates code as if it's
588 sec = find_section_by_name(file->elf, ".rela.discard.reachable");
592 list_for_each_entry(reloc, &sec->reloc_list, list) {
593 if (reloc->sym->type != STT_SECTION) {
594 WARN("unexpected relocation symbol type in %s", sec->name);
597 insn = find_insn(file, reloc->sym->sec, reloc->addend);
599 insn = list_prev_entry(insn, list);
600 else if (reloc->addend == reloc->sym->sec->sh.sh_size) {
601 insn = find_last_insn(file, reloc->sym->sec);
603 WARN("can't find reachable insn at %s+0x%" PRIx64,
604 reloc->sym->sec->name, reloc->addend);
608 WARN("can't find reachable insn at %s+0x%" PRIx64,
609 reloc->sym->sec->name, reloc->addend);
613 insn->dead_end = false;
619 static int create_static_call_sections(struct objtool_file *file)
622 struct static_call_site *site;
623 struct instruction *insn;
624 struct symbol *key_sym;
625 char *key_name, *tmp;
628 sec = find_section_by_name(file->elf, ".static_call_sites");
630 INIT_LIST_HEAD(&file->static_call_list);
631 WARN("file already has .static_call_sites section, skipping");
635 if (list_empty(&file->static_call_list))
639 list_for_each_entry(insn, &file->static_call_list, call_node)
642 sec = elf_create_section(file->elf, ".static_call_sites", SHF_WRITE,
643 sizeof(struct static_call_site), idx);
648 list_for_each_entry(insn, &file->static_call_list, call_node) {
650 site = (struct static_call_site *)sec->data->d_buf + idx;
651 memset(site, 0, sizeof(struct static_call_site));
653 /* populate reloc for 'addr' */
654 if (elf_add_reloc_to_insn(file->elf, sec,
655 idx * sizeof(struct static_call_site),
657 insn->sec, insn->offset))
660 /* find key symbol */
661 key_name = strdup(insn->call_dest->name);
666 if (strncmp(key_name, STATIC_CALL_TRAMP_PREFIX_STR,
667 STATIC_CALL_TRAMP_PREFIX_LEN)) {
668 WARN("static_call: trampoline name malformed: %s", key_name);
671 tmp = key_name + STATIC_CALL_TRAMP_PREFIX_LEN - STATIC_CALL_KEY_PREFIX_LEN;
672 memcpy(tmp, STATIC_CALL_KEY_PREFIX_STR, STATIC_CALL_KEY_PREFIX_LEN);
674 key_sym = find_symbol_by_name(file->elf, tmp);
677 WARN("static_call: can't find static_call_key symbol: %s", tmp);
682 * For modules(), the key might not be exported, which
683 * means the module can make static calls but isn't
684 * allowed to change them.
686 * In that case we temporarily set the key to be the
687 * trampoline address. This is fixed up in
688 * static_call_add_module().
690 key_sym = insn->call_dest;
694 /* populate reloc for 'key' */
695 if (elf_add_reloc(file->elf, sec,
696 idx * sizeof(struct static_call_site) + 4,
697 R_X86_64_PC32, key_sym,
698 is_sibling_call(insn) * STATIC_CALL_SITE_TAIL))
707 static int create_retpoline_sites_sections(struct objtool_file *file)
709 struct instruction *insn;
713 sec = find_section_by_name(file->elf, ".retpoline_sites");
715 WARN("file already has .retpoline_sites, skipping");
720 list_for_each_entry(insn, &file->retpoline_call_list, call_node)
726 sec = elf_create_section(file->elf, ".retpoline_sites", 0,
729 WARN("elf_create_section: .retpoline_sites");
734 list_for_each_entry(insn, &file->retpoline_call_list, call_node) {
736 int *site = (int *)sec->data->d_buf + idx;
739 if (elf_add_reloc_to_insn(file->elf, sec,
742 insn->sec, insn->offset)) {
743 WARN("elf_add_reloc_to_insn: .retpoline_sites");
753 static int create_return_sites_sections(struct objtool_file *file)
755 struct instruction *insn;
759 sec = find_section_by_name(file->elf, ".return_sites");
761 WARN("file already has .return_sites, skipping");
766 list_for_each_entry(insn, &file->return_thunk_list, call_node)
772 sec = elf_create_section(file->elf, ".return_sites", 0,
775 WARN("elf_create_section: .return_sites");
780 list_for_each_entry(insn, &file->return_thunk_list, call_node) {
782 int *site = (int *)sec->data->d_buf + idx;
785 if (elf_add_reloc_to_insn(file->elf, sec,
788 insn->sec, insn->offset)) {
789 WARN("elf_add_reloc_to_insn: .return_sites");
799 static int create_ibt_endbr_seal_sections(struct objtool_file *file)
801 struct instruction *insn;
805 sec = find_section_by_name(file->elf, ".ibt_endbr_seal");
807 WARN("file already has .ibt_endbr_seal, skipping");
812 list_for_each_entry(insn, &file->endbr_list, call_node)
816 printf("ibt: ENDBR at function start: %d\n", file->nr_endbr);
817 printf("ibt: ENDBR inside functions: %d\n", file->nr_endbr_int);
818 printf("ibt: superfluous ENDBR: %d\n", idx);
824 sec = elf_create_section(file->elf, ".ibt_endbr_seal", 0,
827 WARN("elf_create_section: .ibt_endbr_seal");
832 list_for_each_entry(insn, &file->endbr_list, call_node) {
834 int *site = (int *)sec->data->d_buf + idx;
837 if (elf_add_reloc_to_insn(file->elf, sec,
840 insn->sec, insn->offset)) {
841 WARN("elf_add_reloc_to_insn: .ibt_endbr_seal");
851 static int create_mcount_loc_sections(struct objtool_file *file)
855 struct instruction *insn;
858 sec = find_section_by_name(file->elf, "__mcount_loc");
860 INIT_LIST_HEAD(&file->mcount_loc_list);
861 WARN("file already has __mcount_loc section, skipping");
865 if (list_empty(&file->mcount_loc_list))
869 list_for_each_entry(insn, &file->mcount_loc_list, call_node)
872 sec = elf_create_section(file->elf, "__mcount_loc", 0, sizeof(unsigned long), idx);
877 list_for_each_entry(insn, &file->mcount_loc_list, call_node) {
879 loc = (unsigned long *)sec->data->d_buf + idx;
880 memset(loc, 0, sizeof(unsigned long));
882 if (elf_add_reloc_to_insn(file->elf, sec,
883 idx * sizeof(unsigned long),
885 insn->sec, insn->offset))
895 * Warnings shouldn't be reported for ignored functions.
897 static void add_ignores(struct objtool_file *file)
899 struct instruction *insn;
904 sec = find_section_by_name(file->elf, ".rela.discard.func_stack_frame_non_standard");
908 list_for_each_entry(reloc, &sec->reloc_list, list) {
909 switch (reloc->sym->type) {
915 func = find_func_by_offset(reloc->sym->sec, reloc->addend);
921 WARN("unexpected relocation symbol type in %s: %d", sec->name, reloc->sym->type);
925 func_for_each_insn(file, func, insn)
931 * This is a whitelist of functions that is allowed to be called with AC set.
932 * The list is meant to be minimal and only contains compiler instrumentation
933 * ABI and a few functions used to implement *_{to,from}_user() functions.
935 * These functions must not directly change AC, but may PUSHF/POPF.
937 static const char *uaccess_safe_builtin[] = {
941 /* KASAN out-of-line */
942 "__asan_loadN_noabort",
943 "__asan_load1_noabort",
944 "__asan_load2_noabort",
945 "__asan_load4_noabort",
946 "__asan_load8_noabort",
947 "__asan_load16_noabort",
948 "__asan_storeN_noabort",
949 "__asan_store1_noabort",
950 "__asan_store2_noabort",
951 "__asan_store4_noabort",
952 "__asan_store8_noabort",
953 "__asan_store16_noabort",
954 "__kasan_check_read",
955 "__kasan_check_write",
957 "__asan_report_load_n_noabort",
958 "__asan_report_load1_noabort",
959 "__asan_report_load2_noabort",
960 "__asan_report_load4_noabort",
961 "__asan_report_load8_noabort",
962 "__asan_report_load16_noabort",
963 "__asan_report_store_n_noabort",
964 "__asan_report_store1_noabort",
965 "__asan_report_store2_noabort",
966 "__asan_report_store4_noabort",
967 "__asan_report_store8_noabort",
968 "__asan_report_store16_noabort",
970 "__kcsan_check_access",
975 "kcsan_found_watchpoint",
976 "kcsan_setup_watchpoint",
977 "kcsan_check_scoped_accesses",
978 "kcsan_disable_current",
979 "kcsan_enable_current_nowarn",
984 "__tsan_write_range",
995 "__tsan_read_write1",
996 "__tsan_read_write2",
997 "__tsan_read_write4",
998 "__tsan_read_write8",
999 "__tsan_read_write16",
1000 "__tsan_atomic8_load",
1001 "__tsan_atomic16_load",
1002 "__tsan_atomic32_load",
1003 "__tsan_atomic64_load",
1004 "__tsan_atomic8_store",
1005 "__tsan_atomic16_store",
1006 "__tsan_atomic32_store",
1007 "__tsan_atomic64_store",
1008 "__tsan_atomic8_exchange",
1009 "__tsan_atomic16_exchange",
1010 "__tsan_atomic32_exchange",
1011 "__tsan_atomic64_exchange",
1012 "__tsan_atomic8_fetch_add",
1013 "__tsan_atomic16_fetch_add",
1014 "__tsan_atomic32_fetch_add",
1015 "__tsan_atomic64_fetch_add",
1016 "__tsan_atomic8_fetch_sub",
1017 "__tsan_atomic16_fetch_sub",
1018 "__tsan_atomic32_fetch_sub",
1019 "__tsan_atomic64_fetch_sub",
1020 "__tsan_atomic8_fetch_and",
1021 "__tsan_atomic16_fetch_and",
1022 "__tsan_atomic32_fetch_and",
1023 "__tsan_atomic64_fetch_and",
1024 "__tsan_atomic8_fetch_or",
1025 "__tsan_atomic16_fetch_or",
1026 "__tsan_atomic32_fetch_or",
1027 "__tsan_atomic64_fetch_or",
1028 "__tsan_atomic8_fetch_xor",
1029 "__tsan_atomic16_fetch_xor",
1030 "__tsan_atomic32_fetch_xor",
1031 "__tsan_atomic64_fetch_xor",
1032 "__tsan_atomic8_fetch_nand",
1033 "__tsan_atomic16_fetch_nand",
1034 "__tsan_atomic32_fetch_nand",
1035 "__tsan_atomic64_fetch_nand",
1036 "__tsan_atomic8_compare_exchange_strong",
1037 "__tsan_atomic16_compare_exchange_strong",
1038 "__tsan_atomic32_compare_exchange_strong",
1039 "__tsan_atomic64_compare_exchange_strong",
1040 "__tsan_atomic8_compare_exchange_weak",
1041 "__tsan_atomic16_compare_exchange_weak",
1042 "__tsan_atomic32_compare_exchange_weak",
1043 "__tsan_atomic64_compare_exchange_weak",
1044 "__tsan_atomic8_compare_exchange_val",
1045 "__tsan_atomic16_compare_exchange_val",
1046 "__tsan_atomic32_compare_exchange_val",
1047 "__tsan_atomic64_compare_exchange_val",
1048 "__tsan_atomic_thread_fence",
1049 "__tsan_atomic_signal_fence",
1053 "__sanitizer_cov_trace_pc",
1054 "__sanitizer_cov_trace_const_cmp1",
1055 "__sanitizer_cov_trace_const_cmp2",
1056 "__sanitizer_cov_trace_const_cmp4",
1057 "__sanitizer_cov_trace_const_cmp8",
1058 "__sanitizer_cov_trace_cmp1",
1059 "__sanitizer_cov_trace_cmp2",
1060 "__sanitizer_cov_trace_cmp4",
1061 "__sanitizer_cov_trace_cmp8",
1062 "__sanitizer_cov_trace_switch",
1064 "ubsan_type_mismatch_common",
1065 "__ubsan_handle_type_mismatch",
1066 "__ubsan_handle_type_mismatch_v1",
1067 "__ubsan_handle_shift_out_of_bounds",
1069 "csum_partial_copy_generic",
1071 "copy_mc_fragile_handle_tail",
1072 "copy_mc_enhanced_fast_string",
1073 "ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
1077 static void add_uaccess_safe(struct objtool_file *file)
1079 struct symbol *func;
1085 for (name = uaccess_safe_builtin; *name; name++) {
1086 func = find_symbol_by_name(file->elf, *name);
1090 func->uaccess_safe = true;
1095 * FIXME: For now, just ignore any alternatives which add retpolines. This is
1096 * a temporary hack, as it doesn't allow ORC to unwind from inside a retpoline.
1097 * But it at least allows objtool to understand the control flow *around* the
1100 static int add_ignore_alternatives(struct objtool_file *file)
1102 struct section *sec;
1103 struct reloc *reloc;
1104 struct instruction *insn;
1106 sec = find_section_by_name(file->elf, ".rela.discard.ignore_alts");
1110 list_for_each_entry(reloc, &sec->reloc_list, list) {
1111 if (reloc->sym->type != STT_SECTION) {
1112 WARN("unexpected relocation symbol type in %s", sec->name);
1116 insn = find_insn(file, reloc->sym->sec, reloc->addend);
1118 WARN("bad .discard.ignore_alts entry");
1122 insn->ignore_alts = true;
1128 __weak bool arch_is_retpoline(struct symbol *sym)
1133 __weak bool arch_is_rethunk(struct symbol *sym)
1138 #define NEGATIVE_RELOC ((void *)-1L)
1140 static struct reloc *insn_reloc(struct objtool_file *file, struct instruction *insn)
1142 if (insn->reloc == NEGATIVE_RELOC)
1149 insn->reloc = find_reloc_by_dest_range(file->elf, insn->sec,
1150 insn->offset, insn->len);
1152 insn->reloc = NEGATIVE_RELOC;
1160 static void remove_insn_ops(struct instruction *insn)
1162 struct stack_op *op, *tmp;
1164 list_for_each_entry_safe(op, tmp, &insn->stack_ops, list) {
1165 list_del(&op->list);
1170 static void annotate_call_site(struct objtool_file *file,
1171 struct instruction *insn, bool sibling)
1173 struct reloc *reloc = insn_reloc(file, insn);
1174 struct symbol *sym = insn->call_dest;
1180 * Alternative replacement code is just template code which is
1181 * sometimes copied to the original instruction. For now, don't
1182 * annotate it. (In the future we might consider annotating the
1183 * original instruction if/when it ever makes sense to do so.)
1185 if (!strcmp(insn->sec->name, ".altinstr_replacement"))
1188 if (sym->static_call_tramp) {
1189 list_add_tail(&insn->call_node, &file->static_call_list);
1193 if (sym->retpoline_thunk) {
1194 list_add_tail(&insn->call_node, &file->retpoline_call_list);
1199 * Many compilers cannot disable KCOV or sanitizer calls with a function
1200 * attribute so they need a little help, NOP out any such calls from
1203 if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) {
1205 reloc->type = R_NONE;
1206 elf_write_reloc(file->elf, reloc);
1209 elf_write_insn(file->elf, insn->sec,
1210 insn->offset, insn->len,
1211 sibling ? arch_ret_insn(insn->len)
1212 : arch_nop_insn(insn->len));
1214 insn->type = sibling ? INSN_RETURN : INSN_NOP;
1218 * We've replaced the tail-call JMP insn by two new
1219 * insn: RET; INT3, except we only have a single struct
1220 * insn here. Mark it retpoline_safe to avoid the SLS
1221 * warning, instead of adding another insn.
1223 insn->retpoline_safe = true;
1229 if (opts.mcount && sym->fentry) {
1231 WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
1234 reloc->type = R_NONE;
1235 elf_write_reloc(file->elf, reloc);
1238 elf_write_insn(file->elf, insn->sec,
1239 insn->offset, insn->len,
1240 arch_nop_insn(insn->len));
1242 insn->type = INSN_NOP;
1244 list_add_tail(&insn->call_node, &file->mcount_loc_list);
1248 if (!sibling && dead_end_function(file, sym))
1249 insn->dead_end = true;
1252 static void add_call_dest(struct objtool_file *file, struct instruction *insn,
1253 struct symbol *dest, bool sibling)
1255 insn->call_dest = dest;
1260 * Whatever stack impact regular CALLs have, should be undone
1261 * by the RETURN of the called function.
1263 * Annotated intra-function calls retain the stack_ops but
1264 * are converted to JUMP, see read_intra_function_calls().
1266 remove_insn_ops(insn);
1268 annotate_call_site(file, insn, sibling);
1271 static void add_retpoline_call(struct objtool_file *file, struct instruction *insn)
1274 * Retpoline calls/jumps are really dynamic calls/jumps in disguise,
1275 * so convert them accordingly.
1277 switch (insn->type) {
1279 insn->type = INSN_CALL_DYNAMIC;
1281 case INSN_JUMP_UNCONDITIONAL:
1282 insn->type = INSN_JUMP_DYNAMIC;
1284 case INSN_JUMP_CONDITIONAL:
1285 insn->type = INSN_JUMP_DYNAMIC_CONDITIONAL;
1291 insn->retpoline_safe = true;
1294 * Whatever stack impact regular CALLs have, should be undone
1295 * by the RETURN of the called function.
1297 * Annotated intra-function calls retain the stack_ops but
1298 * are converted to JUMP, see read_intra_function_calls().
1300 remove_insn_ops(insn);
1302 annotate_call_site(file, insn, false);
1305 static void add_return_call(struct objtool_file *file, struct instruction *insn)
1308 * Return thunk tail calls are really just returns in disguise,
1309 * so convert them accordingly.
1311 insn->type = INSN_RETURN;
1312 insn->retpoline_safe = true;
1314 list_add_tail(&insn->call_node, &file->return_thunk_list);
1317 static bool same_function(struct instruction *insn1, struct instruction *insn2)
1319 return insn1->func->pfunc == insn2->func->pfunc;
1322 static bool is_first_func_insn(struct objtool_file *file, struct instruction *insn)
1324 if (insn->offset == insn->func->offset)
1328 struct instruction *prev = prev_insn_same_sym(file, insn);
1330 if (prev && prev->type == INSN_ENDBR &&
1331 insn->offset == insn->func->offset + prev->len)
1339 * Find the destination instructions for all jumps.
1341 static int add_jump_destinations(struct objtool_file *file)
1343 struct instruction *insn, *jump_dest;
1344 struct reloc *reloc;
1345 struct section *dest_sec;
1346 unsigned long dest_off;
1348 for_each_insn(file, insn) {
1349 if (insn->jump_dest) {
1351 * handle_group_alt() may have previously set
1352 * 'jump_dest' for some alternatives.
1356 if (!is_static_jump(insn))
1359 reloc = insn_reloc(file, insn);
1361 dest_sec = insn->sec;
1362 dest_off = arch_jump_destination(insn);
1363 } else if (reloc->sym->type == STT_SECTION) {
1364 dest_sec = reloc->sym->sec;
1365 dest_off = arch_dest_reloc_offset(reloc->addend);
1366 } else if (reloc->sym->retpoline_thunk) {
1367 add_retpoline_call(file, insn);
1369 } else if (reloc->sym->return_thunk) {
1370 add_return_call(file, insn);
1372 } else if (insn->func) {
1374 * External sibling call or internal sibling call with
1377 add_call_dest(file, insn, reloc->sym, true);
1379 } else if (reloc->sym->sec->idx) {
1380 dest_sec = reloc->sym->sec;
1381 dest_off = reloc->sym->sym.st_value +
1382 arch_dest_reloc_offset(reloc->addend);
1384 /* non-func asm code jumping to another file */
1388 jump_dest = find_insn(file, dest_sec, dest_off);
1390 WARN_FUNC("can't find jump dest instruction at %s+0x%lx",
1391 insn->sec, insn->offset, dest_sec->name,
1397 * Cross-function jump.
1399 if (insn->func && jump_dest->func &&
1400 insn->func != jump_dest->func) {
1403 * For GCC 8+, create parent/child links for any cold
1404 * subfunctions. This is _mostly_ redundant with a
1405 * similar initialization in read_symbols().
1407 * If a function has aliases, we want the *first* such
1408 * function in the symbol table to be the subfunction's
1409 * parent. In that case we overwrite the
1410 * initialization done in read_symbols().
1412 * However this code can't completely replace the
1413 * read_symbols() code because this doesn't detect the
1414 * case where the parent function's only reference to a
1415 * subfunction is through a jump table.
1417 if (!strstr(insn->func->name, ".cold") &&
1418 strstr(jump_dest->func->name, ".cold")) {
1419 insn->func->cfunc = jump_dest->func;
1420 jump_dest->func->pfunc = insn->func;
1422 } else if (!same_function(insn, jump_dest) &&
1423 is_first_func_insn(file, jump_dest)) {
1425 * Internal sibling call without reloc or with
1426 * STT_SECTION reloc.
1428 add_call_dest(file, insn, jump_dest->func, true);
1433 insn->jump_dest = jump_dest;
1439 static struct symbol *find_call_destination(struct section *sec, unsigned long offset)
1441 struct symbol *call_dest;
1443 call_dest = find_func_by_offset(sec, offset);
1445 call_dest = find_symbol_by_offset(sec, offset);
1451 * Find the destination instructions for all calls.
1453 static int add_call_destinations(struct objtool_file *file)
1455 struct instruction *insn;
1456 unsigned long dest_off;
1457 struct symbol *dest;
1458 struct reloc *reloc;
1460 for_each_insn(file, insn) {
1461 if (insn->type != INSN_CALL)
1464 reloc = insn_reloc(file, insn);
1466 dest_off = arch_jump_destination(insn);
1467 dest = find_call_destination(insn->sec, dest_off);
1469 add_call_dest(file, insn, dest, false);
1474 if (!insn->call_dest) {
1475 WARN_FUNC("unannotated intra-function call", insn->sec, insn->offset);
1479 if (insn->func && insn->call_dest->type != STT_FUNC) {
1480 WARN_FUNC("unsupported call to non-function",
1481 insn->sec, insn->offset);
1485 } else if (reloc->sym->type == STT_SECTION) {
1486 dest_off = arch_dest_reloc_offset(reloc->addend);
1487 dest = find_call_destination(reloc->sym->sec, dest_off);
1489 WARN_FUNC("can't find call dest symbol at %s+0x%lx",
1490 insn->sec, insn->offset,
1491 reloc->sym->sec->name,
1496 add_call_dest(file, insn, dest, false);
1498 } else if (reloc->sym->retpoline_thunk) {
1499 add_retpoline_call(file, insn);
1502 add_call_dest(file, insn, reloc->sym, false);
1509 * The .alternatives section requires some extra special care over and above
1510 * other special sections because alternatives are patched in place.
1512 static int handle_group_alt(struct objtool_file *file,
1513 struct special_alt *special_alt,
1514 struct instruction *orig_insn,
1515 struct instruction **new_insn)
1517 struct instruction *last_orig_insn, *last_new_insn = NULL, *insn, *nop = NULL;
1518 struct alt_group *orig_alt_group, *new_alt_group;
1519 unsigned long dest_off;
1522 orig_alt_group = malloc(sizeof(*orig_alt_group));
1523 if (!orig_alt_group) {
1524 WARN("malloc failed");
1527 orig_alt_group->cfi = calloc(special_alt->orig_len,
1528 sizeof(struct cfi_state *));
1529 if (!orig_alt_group->cfi) {
1530 WARN("calloc failed");
1534 last_orig_insn = NULL;
1536 sec_for_each_insn_from(file, insn) {
1537 if (insn->offset >= special_alt->orig_off + special_alt->orig_len)
1540 insn->alt_group = orig_alt_group;
1541 last_orig_insn = insn;
1543 orig_alt_group->orig_group = NULL;
1544 orig_alt_group->first_insn = orig_insn;
1545 orig_alt_group->last_insn = last_orig_insn;
1548 new_alt_group = malloc(sizeof(*new_alt_group));
1549 if (!new_alt_group) {
1550 WARN("malloc failed");
1554 if (special_alt->new_len < special_alt->orig_len) {
1556 * Insert a fake nop at the end to make the replacement
1557 * alt_group the same size as the original. This is needed to
1558 * allow propagate_alt_cfi() to do its magic. When the last
1559 * instruction affects the stack, the instruction after it (the
1560 * nop) will propagate the new state to the shared CFI array.
1562 nop = malloc(sizeof(*nop));
1564 WARN("malloc failed");
1567 memset(nop, 0, sizeof(*nop));
1568 INIT_LIST_HEAD(&nop->alts);
1569 INIT_LIST_HEAD(&nop->stack_ops);
1571 nop->sec = special_alt->new_sec;
1572 nop->offset = special_alt->new_off + special_alt->new_len;
1573 nop->len = special_alt->orig_len - special_alt->new_len;
1574 nop->type = INSN_NOP;
1575 nop->func = orig_insn->func;
1576 nop->alt_group = new_alt_group;
1577 nop->ignore = orig_insn->ignore_alts;
1580 if (!special_alt->new_len) {
1586 sec_for_each_insn_from(file, insn) {
1587 struct reloc *alt_reloc;
1589 if (insn->offset >= special_alt->new_off + special_alt->new_len)
1592 last_new_insn = insn;
1594 insn->ignore = orig_insn->ignore_alts;
1595 insn->func = orig_insn->func;
1596 insn->alt_group = new_alt_group;
1599 * Since alternative replacement code is copy/pasted by the
1600 * kernel after applying relocations, generally such code can't
1601 * have relative-address relocation references to outside the
1602 * .altinstr_replacement section, unless the arch's
1603 * alternatives code can adjust the relative offsets
1606 alt_reloc = insn_reloc(file, insn);
1608 !arch_support_alt_relocation(special_alt, insn, alt_reloc)) {
1610 WARN_FUNC("unsupported relocation in alternatives section",
1611 insn->sec, insn->offset);
1615 if (!is_static_jump(insn))
1618 if (!insn->immediate)
1621 dest_off = arch_jump_destination(insn);
1622 if (dest_off == special_alt->new_off + special_alt->new_len) {
1623 insn->jump_dest = next_insn_same_sec(file, last_orig_insn);
1624 if (!insn->jump_dest) {
1625 WARN_FUNC("can't find alternative jump destination",
1626 insn->sec, insn->offset);
1632 if (!last_new_insn) {
1633 WARN_FUNC("can't find last new alternative instruction",
1634 special_alt->new_sec, special_alt->new_off);
1639 list_add(&nop->list, &last_new_insn->list);
1641 new_alt_group->orig_group = orig_alt_group;
1642 new_alt_group->first_insn = *new_insn;
1643 new_alt_group->last_insn = nop ? : last_new_insn;
1644 new_alt_group->cfi = orig_alt_group->cfi;
1649 * A jump table entry can either convert a nop to a jump or a jump to a nop.
1650 * If the original instruction is a jump, make the alt entry an effective nop
1651 * by just skipping the original instruction.
1653 static int handle_jump_alt(struct objtool_file *file,
1654 struct special_alt *special_alt,
1655 struct instruction *orig_insn,
1656 struct instruction **new_insn)
1658 if (orig_insn->type != INSN_JUMP_UNCONDITIONAL &&
1659 orig_insn->type != INSN_NOP) {
1661 WARN_FUNC("unsupported instruction at jump label",
1662 orig_insn->sec, orig_insn->offset);
1666 if (opts.hack_jump_label && special_alt->key_addend & 2) {
1667 struct reloc *reloc = insn_reloc(file, orig_insn);
1670 reloc->type = R_NONE;
1671 elf_write_reloc(file->elf, reloc);
1673 elf_write_insn(file->elf, orig_insn->sec,
1674 orig_insn->offset, orig_insn->len,
1675 arch_nop_insn(orig_insn->len));
1676 orig_insn->type = INSN_NOP;
1679 if (orig_insn->type == INSN_NOP) {
1680 if (orig_insn->len == 2)
1681 file->jl_nop_short++;
1683 file->jl_nop_long++;
1688 if (orig_insn->len == 2)
1693 *new_insn = list_next_entry(orig_insn, list);
1698 * Read all the special sections which have alternate instructions which can be
1699 * patched in or redirected to at runtime. Each instruction having alternate
1700 * instruction(s) has them added to its insn->alts list, which will be
1701 * traversed in validate_branch().
1703 static int add_special_section_alts(struct objtool_file *file)
1705 struct list_head special_alts;
1706 struct instruction *orig_insn, *new_insn;
1707 struct special_alt *special_alt, *tmp;
1708 struct alternative *alt;
1711 ret = special_get_alts(file->elf, &special_alts);
1715 list_for_each_entry_safe(special_alt, tmp, &special_alts, list) {
1717 orig_insn = find_insn(file, special_alt->orig_sec,
1718 special_alt->orig_off);
1720 WARN_FUNC("special: can't find orig instruction",
1721 special_alt->orig_sec, special_alt->orig_off);
1727 if (!special_alt->group || special_alt->new_len) {
1728 new_insn = find_insn(file, special_alt->new_sec,
1729 special_alt->new_off);
1731 WARN_FUNC("special: can't find new instruction",
1732 special_alt->new_sec,
1733 special_alt->new_off);
1739 if (special_alt->group) {
1740 if (!special_alt->orig_len) {
1741 WARN_FUNC("empty alternative entry",
1742 orig_insn->sec, orig_insn->offset);
1746 ret = handle_group_alt(file, special_alt, orig_insn,
1750 } else if (special_alt->jump_or_nop) {
1751 ret = handle_jump_alt(file, special_alt, orig_insn,
1757 alt = malloc(sizeof(*alt));
1759 WARN("malloc failed");
1764 alt->insn = new_insn;
1765 alt->skip_orig = special_alt->skip_orig;
1766 orig_insn->ignore_alts |= special_alt->skip_alt;
1767 list_add_tail(&alt->list, &orig_insn->alts);
1769 list_del(&special_alt->list);
1774 printf("jl\\\tNOP\tJMP\n");
1775 printf("short:\t%ld\t%ld\n", file->jl_nop_short, file->jl_short);
1776 printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long);
1783 static int add_jump_table(struct objtool_file *file, struct instruction *insn,
1784 struct reloc *table)
1786 struct reloc *reloc = table;
1787 struct instruction *dest_insn;
1788 struct alternative *alt;
1789 struct symbol *pfunc = insn->func->pfunc;
1790 unsigned int prev_offset = 0;
1793 * Each @reloc is a switch table relocation which points to the target
1796 list_for_each_entry_from(reloc, &table->sec->reloc_list, list) {
1798 /* Check for the end of the table: */
1799 if (reloc != table && reloc->jump_table_start)
1802 /* Make sure the table entries are consecutive: */
1803 if (prev_offset && reloc->offset != prev_offset + 8)
1806 /* Detect function pointers from contiguous objects: */
1807 if (reloc->sym->sec == pfunc->sec &&
1808 reloc->addend == pfunc->offset)
1811 dest_insn = find_insn(file, reloc->sym->sec, reloc->addend);
1815 /* Make sure the destination is in the same function: */
1816 if (!dest_insn->func || dest_insn->func->pfunc != pfunc)
1819 alt = malloc(sizeof(*alt));
1821 WARN("malloc failed");
1825 alt->insn = dest_insn;
1826 list_add_tail(&alt->list, &insn->alts);
1827 prev_offset = reloc->offset;
1831 WARN_FUNC("can't find switch jump table",
1832 insn->sec, insn->offset);
1840 * find_jump_table() - Given a dynamic jump, find the switch jump table
1841 * associated with it.
1843 static struct reloc *find_jump_table(struct objtool_file *file,
1844 struct symbol *func,
1845 struct instruction *insn)
1847 struct reloc *table_reloc;
1848 struct instruction *dest_insn, *orig_insn = insn;
1851 * Backward search using the @first_jump_src links, these help avoid
1852 * much of the 'in between' code. Which avoids us getting confused by
1856 insn && insn->func && insn->func->pfunc == func;
1857 insn = insn->first_jump_src ?: prev_insn_same_sym(file, insn)) {
1859 if (insn != orig_insn && insn->type == INSN_JUMP_DYNAMIC)
1862 /* allow small jumps within the range */
1863 if (insn->type == INSN_JUMP_UNCONDITIONAL &&
1865 (insn->jump_dest->offset <= insn->offset ||
1866 insn->jump_dest->offset > orig_insn->offset))
1869 table_reloc = arch_find_switch_table(file, insn);
1872 dest_insn = find_insn(file, table_reloc->sym->sec, table_reloc->addend);
1873 if (!dest_insn || !dest_insn->func || dest_insn->func->pfunc != func)
1883 * First pass: Mark the head of each jump table so that in the next pass,
1884 * we know when a given jump table ends and the next one starts.
1886 static void mark_func_jump_tables(struct objtool_file *file,
1887 struct symbol *func)
1889 struct instruction *insn, *last = NULL;
1890 struct reloc *reloc;
1892 func_for_each_insn(file, func, insn) {
1897 * Store back-pointers for unconditional forward jumps such
1898 * that find_jump_table() can back-track using those and
1899 * avoid some potentially confusing code.
1901 if (insn->type == INSN_JUMP_UNCONDITIONAL && insn->jump_dest &&
1902 insn->offset > last->offset &&
1903 insn->jump_dest->offset > insn->offset &&
1904 !insn->jump_dest->first_jump_src) {
1906 insn->jump_dest->first_jump_src = insn;
1907 last = insn->jump_dest;
1910 if (insn->type != INSN_JUMP_DYNAMIC)
1913 reloc = find_jump_table(file, func, insn);
1915 reloc->jump_table_start = true;
1916 insn->jump_table = reloc;
1921 static int add_func_jump_tables(struct objtool_file *file,
1922 struct symbol *func)
1924 struct instruction *insn;
1927 func_for_each_insn(file, func, insn) {
1928 if (!insn->jump_table)
1931 ret = add_jump_table(file, insn, insn->jump_table);
1940 * For some switch statements, gcc generates a jump table in the .rodata
1941 * section which contains a list of addresses within the function to jump to.
1942 * This finds these jump tables and adds them to the insn->alts lists.
1944 static int add_jump_table_alts(struct objtool_file *file)
1946 struct section *sec;
1947 struct symbol *func;
1953 for_each_sec(file, sec) {
1954 list_for_each_entry(func, &sec->symbol_list, list) {
1955 if (func->type != STT_FUNC)
1958 mark_func_jump_tables(file, func);
1959 ret = add_func_jump_tables(file, func);
1968 static void set_func_state(struct cfi_state *state)
1970 state->cfa = initial_func_cfi.cfa;
1971 memcpy(&state->regs, &initial_func_cfi.regs,
1972 CFI_NUM_REGS * sizeof(struct cfi_reg));
1973 state->stack_size = initial_func_cfi.cfa.offset;
1976 static int read_unwind_hints(struct objtool_file *file)
1978 struct cfi_state cfi = init_cfi;
1979 struct section *sec, *relocsec;
1980 struct unwind_hint *hint;
1981 struct instruction *insn;
1982 struct reloc *reloc;
1985 sec = find_section_by_name(file->elf, ".discard.unwind_hints");
1989 relocsec = sec->reloc;
1991 WARN("missing .rela.discard.unwind_hints section");
1995 if (sec->sh.sh_size % sizeof(struct unwind_hint)) {
1996 WARN("struct unwind_hint size mismatch");
2002 for (i = 0; i < sec->sh.sh_size / sizeof(struct unwind_hint); i++) {
2003 hint = (struct unwind_hint *)sec->data->d_buf + i;
2005 reloc = find_reloc_by_dest(file->elf, sec, i * sizeof(*hint));
2007 WARN("can't find reloc for unwind_hints[%d]", i);
2011 insn = find_insn(file, reloc->sym->sec, reloc->addend);
2013 WARN("can't find insn for unwind_hints[%d]", i);
2019 if (opts.ibt && hint->type == UNWIND_HINT_TYPE_REGS_PARTIAL) {
2020 struct symbol *sym = find_symbol_by_offset(insn->sec, insn->offset);
2022 if (sym && sym->bind == STB_GLOBAL &&
2023 insn->type != INSN_ENDBR && !insn->noendbr) {
2024 WARN_FUNC("UNWIND_HINT_IRET_REGS without ENDBR",
2025 insn->sec, insn->offset);
2029 if (hint->type == UNWIND_HINT_TYPE_FUNC) {
2030 insn->cfi = &func_cfi;
2037 if (arch_decode_hint_reg(hint->sp_reg, &cfi.cfa.base)) {
2038 WARN_FUNC("unsupported unwind_hint sp base reg %d",
2039 insn->sec, insn->offset, hint->sp_reg);
2043 cfi.cfa.offset = bswap_if_needed(hint->sp_offset);
2044 cfi.type = hint->type;
2045 cfi.end = hint->end;
2047 insn->cfi = cfi_hash_find_or_add(&cfi);
2053 static int read_noendbr_hints(struct objtool_file *file)
2055 struct section *sec;
2056 struct instruction *insn;
2057 struct reloc *reloc;
2059 sec = find_section_by_name(file->elf, ".rela.discard.noendbr");
2063 list_for_each_entry(reloc, &sec->reloc_list, list) {
2064 insn = find_insn(file, reloc->sym->sec, reloc->sym->offset + reloc->addend);
2066 WARN("bad .discard.noendbr entry");
2070 if (insn->type == INSN_ENDBR)
2071 WARN_FUNC("ANNOTATE_NOENDBR on ENDBR", insn->sec, insn->offset);
2079 static int read_retpoline_hints(struct objtool_file *file)
2081 struct section *sec;
2082 struct instruction *insn;
2083 struct reloc *reloc;
2085 sec = find_section_by_name(file->elf, ".rela.discard.retpoline_safe");
2089 list_for_each_entry(reloc, &sec->reloc_list, list) {
2090 if (reloc->sym->type != STT_SECTION) {
2091 WARN("unexpected relocation symbol type in %s", sec->name);
2095 insn = find_insn(file, reloc->sym->sec, reloc->addend);
2097 WARN("bad .discard.retpoline_safe entry");
2101 if (insn->type != INSN_JUMP_DYNAMIC &&
2102 insn->type != INSN_CALL_DYNAMIC) {
2103 WARN_FUNC("retpoline_safe hint not an indirect jump/call",
2104 insn->sec, insn->offset);
2108 insn->retpoline_safe = true;
2114 static int read_instr_hints(struct objtool_file *file)
2116 struct section *sec;
2117 struct instruction *insn;
2118 struct reloc *reloc;
2120 sec = find_section_by_name(file->elf, ".rela.discard.instr_end");
2124 list_for_each_entry(reloc, &sec->reloc_list, list) {
2125 if (reloc->sym->type != STT_SECTION) {
2126 WARN("unexpected relocation symbol type in %s", sec->name);
2130 insn = find_insn(file, reloc->sym->sec, reloc->addend);
2132 WARN("bad .discard.instr_end entry");
2139 sec = find_section_by_name(file->elf, ".rela.discard.instr_begin");
2143 list_for_each_entry(reloc, &sec->reloc_list, list) {
2144 if (reloc->sym->type != STT_SECTION) {
2145 WARN("unexpected relocation symbol type in %s", sec->name);
2149 insn = find_insn(file, reloc->sym->sec, reloc->addend);
2151 WARN("bad .discard.instr_begin entry");
2161 static int read_intra_function_calls(struct objtool_file *file)
2163 struct instruction *insn;
2164 struct section *sec;
2165 struct reloc *reloc;
2167 sec = find_section_by_name(file->elf, ".rela.discard.intra_function_calls");
2171 list_for_each_entry(reloc, &sec->reloc_list, list) {
2172 unsigned long dest_off;
2174 if (reloc->sym->type != STT_SECTION) {
2175 WARN("unexpected relocation symbol type in %s",
2180 insn = find_insn(file, reloc->sym->sec, reloc->addend);
2182 WARN("bad .discard.intra_function_call entry");
2186 if (insn->type != INSN_CALL) {
2187 WARN_FUNC("intra_function_call not a direct call",
2188 insn->sec, insn->offset);
2193 * Treat intra-function CALLs as JMPs, but with a stack_op.
2194 * See add_call_destinations(), which strips stack_ops from
2197 insn->type = INSN_JUMP_UNCONDITIONAL;
2199 dest_off = insn->offset + insn->len + insn->immediate;
2200 insn->jump_dest = find_insn(file, insn->sec, dest_off);
2201 if (!insn->jump_dest) {
2202 WARN_FUNC("can't find call dest at %s+0x%lx",
2203 insn->sec, insn->offset,
2204 insn->sec->name, dest_off);
2213 * Return true if name matches an instrumentation function, where calls to that
2214 * function from noinstr code can safely be removed, but compilers won't do so.
2216 static bool is_profiling_func(const char *name)
2219 * Many compilers cannot disable KCOV with a function attribute.
2221 if (!strncmp(name, "__sanitizer_cov_", 16))
2225 * Some compilers currently do not remove __tsan_func_entry/exit nor
2226 * __tsan_atomic_signal_fence (used for barrier instrumentation) with
2227 * the __no_sanitize_thread attribute, remove them. Once the kernel's
2228 * minimum Clang version is 14.0, this can be removed.
2230 if (!strncmp(name, "__tsan_func_", 12) ||
2231 !strcmp(name, "__tsan_atomic_signal_fence"))
2237 static int classify_symbols(struct objtool_file *file)
2239 struct section *sec;
2240 struct symbol *func;
2242 for_each_sec(file, sec) {
2243 list_for_each_entry(func, &sec->symbol_list, list) {
2244 if (func->bind != STB_GLOBAL)
2247 if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR,
2248 strlen(STATIC_CALL_TRAMP_PREFIX_STR)))
2249 func->static_call_tramp = true;
2251 if (arch_is_retpoline(func))
2252 func->retpoline_thunk = true;
2254 if (arch_is_rethunk(func))
2255 func->return_thunk = true;
2257 if (!strcmp(func->name, "__fentry__"))
2258 func->fentry = true;
2260 if (is_profiling_func(func->name))
2261 func->profiling_func = true;
2268 static void mark_rodata(struct objtool_file *file)
2270 struct section *sec;
2274 * Search for the following rodata sections, each of which can
2275 * potentially contain jump tables:
2277 * - .rodata: can contain GCC switch tables
2278 * - .rodata.<func>: same, if -fdata-sections is being used
2279 * - .rodata..c_jump_table: contains C annotated jump tables
2281 * .rodata.str1.* sections are ignored; they don't contain jump tables.
2283 for_each_sec(file, sec) {
2284 if (!strncmp(sec->name, ".rodata", 7) &&
2285 !strstr(sec->name, ".str1.")) {
2291 file->rodata = found;
2294 static int decode_sections(struct objtool_file *file)
2300 ret = init_pv_ops(file);
2304 ret = decode_instructions(file);
2309 add_uaccess_safe(file);
2311 ret = add_ignore_alternatives(file);
2316 * Must be before read_unwind_hints() since that needs insn->noendbr.
2318 ret = read_noendbr_hints(file);
2323 * Must be before add_{jump_call}_destination.
2325 ret = classify_symbols(file);
2330 * Must be before add_jump_destinations(), which depends on 'func'
2331 * being set for alternatives, to enable proper sibling call detection.
2333 ret = add_special_section_alts(file);
2337 ret = add_jump_destinations(file);
2342 * Must be before add_call_destination(); it changes INSN_CALL to
2345 ret = read_intra_function_calls(file);
2349 ret = add_call_destinations(file);
2354 * Must be after add_call_destinations() such that it can override
2355 * dead_end_function() marks.
2357 ret = add_dead_ends(file);
2361 ret = add_jump_table_alts(file);
2365 ret = read_unwind_hints(file);
2369 ret = read_retpoline_hints(file);
2373 ret = read_instr_hints(file);
2380 static bool is_fentry_call(struct instruction *insn)
2382 if (insn->type == INSN_CALL &&
2384 insn->call_dest->fentry)
2390 static bool has_modified_stack_frame(struct instruction *insn, struct insn_state *state)
2392 struct cfi_state *cfi = &state->cfi;
2395 if (cfi->cfa.base != initial_func_cfi.cfa.base || cfi->drap)
2398 if (cfi->cfa.offset != initial_func_cfi.cfa.offset)
2401 if (cfi->stack_size != initial_func_cfi.cfa.offset)
2404 for (i = 0; i < CFI_NUM_REGS; i++) {
2405 if (cfi->regs[i].base != initial_func_cfi.regs[i].base ||
2406 cfi->regs[i].offset != initial_func_cfi.regs[i].offset)
2413 static bool check_reg_frame_pos(const struct cfi_reg *reg,
2414 int expected_offset)
2416 return reg->base == CFI_CFA &&
2417 reg->offset == expected_offset;
2420 static bool has_valid_stack_frame(struct insn_state *state)
2422 struct cfi_state *cfi = &state->cfi;
2424 if (cfi->cfa.base == CFI_BP &&
2425 check_reg_frame_pos(&cfi->regs[CFI_BP], -cfi->cfa.offset) &&
2426 check_reg_frame_pos(&cfi->regs[CFI_RA], -cfi->cfa.offset + 8))
2429 if (cfi->drap && cfi->regs[CFI_BP].base == CFI_BP)
2435 static int update_cfi_state_regs(struct instruction *insn,
2436 struct cfi_state *cfi,
2437 struct stack_op *op)
2439 struct cfi_reg *cfa = &cfi->cfa;
2441 if (cfa->base != CFI_SP && cfa->base != CFI_SP_INDIRECT)
2445 if (op->dest.type == OP_DEST_PUSH || op->dest.type == OP_DEST_PUSHF)
2449 if (op->src.type == OP_SRC_POP || op->src.type == OP_SRC_POPF)
2452 /* add immediate to sp */
2453 if (op->dest.type == OP_DEST_REG && op->src.type == OP_SRC_ADD &&
2454 op->dest.reg == CFI_SP && op->src.reg == CFI_SP)
2455 cfa->offset -= op->src.offset;
2460 static void save_reg(struct cfi_state *cfi, unsigned char reg, int base, int offset)
2462 if (arch_callee_saved_reg(reg) &&
2463 cfi->regs[reg].base == CFI_UNDEFINED) {
2464 cfi->regs[reg].base = base;
2465 cfi->regs[reg].offset = offset;
2469 static void restore_reg(struct cfi_state *cfi, unsigned char reg)
2471 cfi->regs[reg].base = initial_func_cfi.regs[reg].base;
2472 cfi->regs[reg].offset = initial_func_cfi.regs[reg].offset;
2476 * A note about DRAP stack alignment:
2478 * GCC has the concept of a DRAP register, which is used to help keep track of
2479 * the stack pointer when aligning the stack. r10 or r13 is used as the DRAP
2480 * register. The typical DRAP pattern is:
2482 * 4c 8d 54 24 08 lea 0x8(%rsp),%r10
2483 * 48 83 e4 c0 and $0xffffffffffffffc0,%rsp
2484 * 41 ff 72 f8 pushq -0x8(%r10)
2486 * 48 89 e5 mov %rsp,%rbp
2493 * 49 8d 62 f8 lea -0x8(%r10),%rsp
2496 * There are some variations in the epilogues, like:
2504 * 49 8d 62 f8 lea -0x8(%r10),%rsp
2509 * 4c 8b 55 e8 mov -0x18(%rbp),%r10
2510 * 48 8b 5d e0 mov -0x20(%rbp),%rbx
2511 * 4c 8b 65 f0 mov -0x10(%rbp),%r12
2512 * 4c 8b 6d f8 mov -0x8(%rbp),%r13
2514 * 49 8d 62 f8 lea -0x8(%r10),%rsp
2517 * Sometimes r13 is used as the DRAP register, in which case it's saved and
2518 * restored beforehand:
2521 * 4c 8d 6c 24 10 lea 0x10(%rsp),%r13
2522 * 48 83 e4 f0 and $0xfffffffffffffff0,%rsp
2524 * 49 8d 65 f0 lea -0x10(%r13),%rsp
2528 static int update_cfi_state(struct instruction *insn,
2529 struct instruction *next_insn,
2530 struct cfi_state *cfi, struct stack_op *op)
2532 struct cfi_reg *cfa = &cfi->cfa;
2533 struct cfi_reg *regs = cfi->regs;
2535 /* stack operations don't make sense with an undefined CFA */
2536 if (cfa->base == CFI_UNDEFINED) {
2538 WARN_FUNC("undefined stack state", insn->sec, insn->offset);
2544 if (cfi->type == UNWIND_HINT_TYPE_REGS ||
2545 cfi->type == UNWIND_HINT_TYPE_REGS_PARTIAL)
2546 return update_cfi_state_regs(insn, cfi, op);
2548 switch (op->dest.type) {
2551 switch (op->src.type) {
2554 if (op->src.reg == CFI_SP && op->dest.reg == CFI_BP &&
2555 cfa->base == CFI_SP &&
2556 check_reg_frame_pos(®s[CFI_BP], -cfa->offset)) {
2558 /* mov %rsp, %rbp */
2559 cfa->base = op->dest.reg;
2560 cfi->bp_scratch = false;
2563 else if (op->src.reg == CFI_SP &&
2564 op->dest.reg == CFI_BP && cfi->drap) {
2566 /* drap: mov %rsp, %rbp */
2567 regs[CFI_BP].base = CFI_BP;
2568 regs[CFI_BP].offset = -cfi->stack_size;
2569 cfi->bp_scratch = false;
2572 else if (op->src.reg == CFI_SP && cfa->base == CFI_SP) {
2577 * This is needed for the rare case where GCC
2584 cfi->vals[op->dest.reg].base = CFI_CFA;
2585 cfi->vals[op->dest.reg].offset = -cfi->stack_size;
2588 else if (op->src.reg == CFI_BP && op->dest.reg == CFI_SP &&
2589 (cfa->base == CFI_BP || cfa->base == cfi->drap_reg)) {
2594 * Restore the original stack pointer (Clang).
2596 cfi->stack_size = -cfi->regs[CFI_BP].offset;
2599 else if (op->dest.reg == cfa->base) {
2601 /* mov %reg, %rsp */
2602 if (cfa->base == CFI_SP &&
2603 cfi->vals[op->src.reg].base == CFI_CFA) {
2606 * This is needed for the rare case
2607 * where GCC does something dumb like:
2609 * lea 0x8(%rsp), %rcx
2613 cfa->offset = -cfi->vals[op->src.reg].offset;
2614 cfi->stack_size = cfa->offset;
2616 } else if (cfa->base == CFI_SP &&
2617 cfi->vals[op->src.reg].base == CFI_SP_INDIRECT &&
2618 cfi->vals[op->src.reg].offset == cfa->offset) {
2623 * 1: mov %rsp, (%[tos])
2624 * 2: mov %[tos], %rsp
2630 * 1 - places a pointer to the previous
2631 * stack at the Top-of-Stack of the
2634 * 2 - switches to the new stack.
2636 * 3 - pops the Top-of-Stack to restore
2637 * the original stack.
2639 * Note: we set base to SP_INDIRECT
2640 * here and preserve offset. Therefore
2641 * when the unwinder reaches ToS it
2642 * will dereference SP and then add the
2643 * offset to find the next frame, IOW:
2646 cfa->base = CFI_SP_INDIRECT;
2649 cfa->base = CFI_UNDEFINED;
2654 else if (op->dest.reg == CFI_SP &&
2655 cfi->vals[op->src.reg].base == CFI_SP_INDIRECT &&
2656 cfi->vals[op->src.reg].offset == cfa->offset) {
2659 * The same stack swizzle case 2) as above. But
2660 * because we can't change cfa->base, case 3)
2661 * will become a regular POP. Pretend we're a
2662 * PUSH so things don't go unbalanced.
2664 cfi->stack_size += 8;
2671 if (op->dest.reg == CFI_SP && op->src.reg == CFI_SP) {
2674 cfi->stack_size -= op->src.offset;
2675 if (cfa->base == CFI_SP)
2676 cfa->offset -= op->src.offset;
2680 if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) {
2682 /* lea disp(%rbp), %rsp */
2683 cfi->stack_size = -(op->src.offset + regs[CFI_BP].offset);
2687 if (!cfi->drap && op->src.reg == CFI_SP &&
2688 op->dest.reg == CFI_BP && cfa->base == CFI_SP &&
2689 check_reg_frame_pos(®s[CFI_BP], -cfa->offset + op->src.offset)) {
2691 /* lea disp(%rsp), %rbp */
2693 cfa->offset -= op->src.offset;
2694 cfi->bp_scratch = false;
2698 if (op->src.reg == CFI_SP && cfa->base == CFI_SP) {
2700 /* drap: lea disp(%rsp), %drap */
2701 cfi->drap_reg = op->dest.reg;
2704 * lea disp(%rsp), %reg
2706 * This is needed for the rare case where GCC
2707 * does something dumb like:
2709 * lea 0x8(%rsp), %rcx
2713 cfi->vals[op->dest.reg].base = CFI_CFA;
2714 cfi->vals[op->dest.reg].offset = \
2715 -cfi->stack_size + op->src.offset;
2720 if (cfi->drap && op->dest.reg == CFI_SP &&
2721 op->src.reg == cfi->drap_reg) {
2723 /* drap: lea disp(%drap), %rsp */
2725 cfa->offset = cfi->stack_size = -op->src.offset;
2726 cfi->drap_reg = CFI_UNDEFINED;
2731 if (op->dest.reg == cfi->cfa.base && !(next_insn && next_insn->hint)) {
2732 WARN_FUNC("unsupported stack register modification",
2733 insn->sec, insn->offset);
2740 if (op->dest.reg != CFI_SP ||
2741 (cfi->drap_reg != CFI_UNDEFINED && cfa->base != CFI_SP) ||
2742 (cfi->drap_reg == CFI_UNDEFINED && cfa->base != CFI_BP)) {
2743 WARN_FUNC("unsupported stack pointer realignment",
2744 insn->sec, insn->offset);
2748 if (cfi->drap_reg != CFI_UNDEFINED) {
2749 /* drap: and imm, %rsp */
2750 cfa->base = cfi->drap_reg;
2751 cfa->offset = cfi->stack_size = 0;
2756 * Older versions of GCC (4.8ish) realign the stack
2757 * without DRAP, with a frame pointer.
2764 if (op->dest.reg == CFI_SP && cfa->base == CFI_SP_INDIRECT) {
2766 /* pop %rsp; # restore from a stack swizzle */
2771 if (!cfi->drap && op->dest.reg == cfa->base) {
2777 if (cfi->drap && cfa->base == CFI_BP_INDIRECT &&
2778 op->dest.reg == cfi->drap_reg &&
2779 cfi->drap_offset == -cfi->stack_size) {
2781 /* drap: pop %drap */
2782 cfa->base = cfi->drap_reg;
2784 cfi->drap_offset = -1;
2786 } else if (cfi->stack_size == -regs[op->dest.reg].offset) {
2789 restore_reg(cfi, op->dest.reg);
2792 cfi->stack_size -= 8;
2793 if (cfa->base == CFI_SP)
2798 case OP_SRC_REG_INDIRECT:
2799 if (!cfi->drap && op->dest.reg == cfa->base &&
2800 op->dest.reg == CFI_BP) {
2802 /* mov disp(%rsp), %rbp */
2804 cfa->offset = cfi->stack_size;
2807 if (cfi->drap && op->src.reg == CFI_BP &&
2808 op->src.offset == cfi->drap_offset) {
2810 /* drap: mov disp(%rbp), %drap */
2811 cfa->base = cfi->drap_reg;
2813 cfi->drap_offset = -1;
2816 if (cfi->drap && op->src.reg == CFI_BP &&
2817 op->src.offset == regs[op->dest.reg].offset) {
2819 /* drap: mov disp(%rbp), %reg */
2820 restore_reg(cfi, op->dest.reg);
2822 } else if (op->src.reg == cfa->base &&
2823 op->src.offset == regs[op->dest.reg].offset + cfa->offset) {
2825 /* mov disp(%rbp), %reg */
2826 /* mov disp(%rsp), %reg */
2827 restore_reg(cfi, op->dest.reg);
2829 } else if (op->src.reg == CFI_SP &&
2830 op->src.offset == regs[op->dest.reg].offset + cfi->stack_size) {
2832 /* mov disp(%rsp), %reg */
2833 restore_reg(cfi, op->dest.reg);
2839 WARN_FUNC("unknown stack-related instruction",
2840 insn->sec, insn->offset);
2848 cfi->stack_size += 8;
2849 if (cfa->base == CFI_SP)
2852 if (op->src.type != OP_SRC_REG)
2856 if (op->src.reg == cfa->base && op->src.reg == cfi->drap_reg) {
2858 /* drap: push %drap */
2859 cfa->base = CFI_BP_INDIRECT;
2860 cfa->offset = -cfi->stack_size;
2862 /* save drap so we know when to restore it */
2863 cfi->drap_offset = -cfi->stack_size;
2865 } else if (op->src.reg == CFI_BP && cfa->base == cfi->drap_reg) {
2867 /* drap: push %rbp */
2868 cfi->stack_size = 0;
2872 /* drap: push %reg */
2873 save_reg(cfi, op->src.reg, CFI_BP, -cfi->stack_size);
2879 save_reg(cfi, op->src.reg, CFI_CFA, -cfi->stack_size);
2882 /* detect when asm code uses rbp as a scratch register */
2883 if (opts.stackval && insn->func && op->src.reg == CFI_BP &&
2884 cfa->base != CFI_BP)
2885 cfi->bp_scratch = true;
2888 case OP_DEST_REG_INDIRECT:
2891 if (op->src.reg == cfa->base && op->src.reg == cfi->drap_reg) {
2893 /* drap: mov %drap, disp(%rbp) */
2894 cfa->base = CFI_BP_INDIRECT;
2895 cfa->offset = op->dest.offset;
2897 /* save drap offset so we know when to restore it */
2898 cfi->drap_offset = op->dest.offset;
2901 /* drap: mov reg, disp(%rbp) */
2902 save_reg(cfi, op->src.reg, CFI_BP, op->dest.offset);
2905 } else if (op->dest.reg == cfa->base) {
2907 /* mov reg, disp(%rbp) */
2908 /* mov reg, disp(%rsp) */
2909 save_reg(cfi, op->src.reg, CFI_CFA,
2910 op->dest.offset - cfi->cfa.offset);
2912 } else if (op->dest.reg == CFI_SP) {
2914 /* mov reg, disp(%rsp) */
2915 save_reg(cfi, op->src.reg, CFI_CFA,
2916 op->dest.offset - cfi->stack_size);
2918 } else if (op->src.reg == CFI_SP && op->dest.offset == 0) {
2920 /* mov %rsp, (%reg); # setup a stack swizzle. */
2921 cfi->vals[op->dest.reg].base = CFI_SP_INDIRECT;
2922 cfi->vals[op->dest.reg].offset = cfa->offset;
2928 if (op->src.type != OP_SRC_POP && op->src.type != OP_SRC_POPF) {
2929 WARN_FUNC("unknown stack-related memory operation",
2930 insn->sec, insn->offset);
2935 cfi->stack_size -= 8;
2936 if (cfa->base == CFI_SP)
2942 WARN_FUNC("unknown stack-related instruction",
2943 insn->sec, insn->offset);
2951 * The stack layouts of alternatives instructions can sometimes diverge when
2952 * they have stack modifications. That's fine as long as the potential stack
2953 * layouts don't conflict at any given potential instruction boundary.
2955 * Flatten the CFIs of the different alternative code streams (both original
2956 * and replacement) into a single shared CFI array which can be used to detect
2957 * conflicts and nicely feed a linear array of ORC entries to the unwinder.
2959 static int propagate_alt_cfi(struct objtool_file *file, struct instruction *insn)
2961 struct cfi_state **alt_cfi;
2964 if (!insn->alt_group)
2968 WARN("CFI missing");
2972 alt_cfi = insn->alt_group->cfi;
2973 group_off = insn->offset - insn->alt_group->first_insn->offset;
2975 if (!alt_cfi[group_off]) {
2976 alt_cfi[group_off] = insn->cfi;
2978 if (cficmp(alt_cfi[group_off], insn->cfi)) {
2979 WARN_FUNC("stack layout conflict in alternatives",
2980 insn->sec, insn->offset);
2988 static int handle_insn_ops(struct instruction *insn,
2989 struct instruction *next_insn,
2990 struct insn_state *state)
2992 struct stack_op *op;
2994 list_for_each_entry(op, &insn->stack_ops, list) {
2996 if (update_cfi_state(insn, next_insn, &state->cfi, op))
2999 if (!insn->alt_group)
3002 if (op->dest.type == OP_DEST_PUSHF) {
3003 if (!state->uaccess_stack) {
3004 state->uaccess_stack = 1;
3005 } else if (state->uaccess_stack >> 31) {
3006 WARN_FUNC("PUSHF stack exhausted",
3007 insn->sec, insn->offset);
3010 state->uaccess_stack <<= 1;
3011 state->uaccess_stack |= state->uaccess;
3014 if (op->src.type == OP_SRC_POPF) {
3015 if (state->uaccess_stack) {
3016 state->uaccess = state->uaccess_stack & 1;
3017 state->uaccess_stack >>= 1;
3018 if (state->uaccess_stack == 1)
3019 state->uaccess_stack = 0;
3027 static bool insn_cfi_match(struct instruction *insn, struct cfi_state *cfi2)
3029 struct cfi_state *cfi1 = insn->cfi;
3033 WARN("CFI missing");
3037 if (memcmp(&cfi1->cfa, &cfi2->cfa, sizeof(cfi1->cfa))) {
3039 WARN_FUNC("stack state mismatch: cfa1=%d%+d cfa2=%d%+d",
3040 insn->sec, insn->offset,
3041 cfi1->cfa.base, cfi1->cfa.offset,
3042 cfi2->cfa.base, cfi2->cfa.offset);
3044 } else if (memcmp(&cfi1->regs, &cfi2->regs, sizeof(cfi1->regs))) {
3045 for (i = 0; i < CFI_NUM_REGS; i++) {
3046 if (!memcmp(&cfi1->regs[i], &cfi2->regs[i],
3047 sizeof(struct cfi_reg)))
3050 WARN_FUNC("stack state mismatch: reg1[%d]=%d%+d reg2[%d]=%d%+d",
3051 insn->sec, insn->offset,
3052 i, cfi1->regs[i].base, cfi1->regs[i].offset,
3053 i, cfi2->regs[i].base, cfi2->regs[i].offset);
3057 } else if (cfi1->type != cfi2->type) {
3059 WARN_FUNC("stack state mismatch: type1=%d type2=%d",
3060 insn->sec, insn->offset, cfi1->type, cfi2->type);
3062 } else if (cfi1->drap != cfi2->drap ||
3063 (cfi1->drap && cfi1->drap_reg != cfi2->drap_reg) ||
3064 (cfi1->drap && cfi1->drap_offset != cfi2->drap_offset)) {
3066 WARN_FUNC("stack state mismatch: drap1=%d(%d,%d) drap2=%d(%d,%d)",
3067 insn->sec, insn->offset,
3068 cfi1->drap, cfi1->drap_reg, cfi1->drap_offset,
3069 cfi2->drap, cfi2->drap_reg, cfi2->drap_offset);
3077 static inline bool func_uaccess_safe(struct symbol *func)
3080 return func->uaccess_safe;
3085 static inline const char *call_dest_name(struct instruction *insn)
3087 static char pvname[19];
3091 if (insn->call_dest)
3092 return insn->call_dest->name;
3094 rel = insn_reloc(NULL, insn);
3095 if (rel && !strcmp(rel->sym->name, "pv_ops")) {
3096 idx = (rel->addend / sizeof(void *));
3097 snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);
3104 static bool pv_call_dest(struct objtool_file *file, struct instruction *insn)
3106 struct symbol *target;
3110 rel = insn_reloc(file, insn);
3111 if (!rel || strcmp(rel->sym->name, "pv_ops"))
3114 idx = (arch_dest_reloc_offset(rel->addend) / sizeof(void *));
3116 if (file->pv_ops[idx].clean)
3119 file->pv_ops[idx].clean = true;
3121 list_for_each_entry(target, &file->pv_ops[idx].targets, pv_target) {
3122 if (!target->sec->noinstr) {
3123 WARN("pv_ops[%d]: %s", idx, target->name);
3124 file->pv_ops[idx].clean = false;
3128 return file->pv_ops[idx].clean;
3131 static inline bool noinstr_call_dest(struct objtool_file *file,
3132 struct instruction *insn,
3133 struct symbol *func)
3136 * We can't deal with indirect function calls at present;
3137 * assume they're instrumented.
3141 return pv_call_dest(file, insn);
3147 * If the symbol is from a noinstr section; we good.
3149 if (func->sec->noinstr)
3153 * The __ubsan_handle_*() calls are like WARN(), they only happen when
3154 * something 'BAD' happened. At the risk of taking the machine down,
3155 * let them proceed to get the message out.
3157 if (!strncmp(func->name, "__ubsan_handle_", 15))
3163 static int validate_call(struct objtool_file *file,
3164 struct instruction *insn,
3165 struct insn_state *state)
3167 if (state->noinstr && state->instr <= 0 &&
3168 !noinstr_call_dest(file, insn, insn->call_dest)) {
3169 WARN_FUNC("call to %s() leaves .noinstr.text section",
3170 insn->sec, insn->offset, call_dest_name(insn));
3174 if (state->uaccess && !func_uaccess_safe(insn->call_dest)) {
3175 WARN_FUNC("call to %s() with UACCESS enabled",
3176 insn->sec, insn->offset, call_dest_name(insn));
3181 WARN_FUNC("call to %s() with DF set",
3182 insn->sec, insn->offset, call_dest_name(insn));
3189 static int validate_sibling_call(struct objtool_file *file,
3190 struct instruction *insn,
3191 struct insn_state *state)
3193 if (has_modified_stack_frame(insn, state)) {
3194 WARN_FUNC("sibling call from callable instruction with modified stack frame",
3195 insn->sec, insn->offset);
3199 return validate_call(file, insn, state);
3202 static int validate_return(struct symbol *func, struct instruction *insn, struct insn_state *state)
3204 if (state->noinstr && state->instr > 0) {
3205 WARN_FUNC("return with instrumentation enabled",
3206 insn->sec, insn->offset);
3210 if (state->uaccess && !func_uaccess_safe(func)) {
3211 WARN_FUNC("return with UACCESS enabled",
3212 insn->sec, insn->offset);
3216 if (!state->uaccess && func_uaccess_safe(func)) {
3217 WARN_FUNC("return with UACCESS disabled from a UACCESS-safe function",
3218 insn->sec, insn->offset);
3223 WARN_FUNC("return with DF set",
3224 insn->sec, insn->offset);
3228 if (func && has_modified_stack_frame(insn, state)) {
3229 WARN_FUNC("return with modified stack frame",
3230 insn->sec, insn->offset);
3234 if (state->cfi.bp_scratch) {
3235 WARN_FUNC("BP used as a scratch register",
3236 insn->sec, insn->offset);
3243 static struct instruction *next_insn_to_validate(struct objtool_file *file,
3244 struct instruction *insn)
3246 struct alt_group *alt_group = insn->alt_group;
3249 * Simulate the fact that alternatives are patched in-place. When the
3250 * end of a replacement alt_group is reached, redirect objtool flow to
3251 * the end of the original alt_group.
3253 if (alt_group && insn == alt_group->last_insn && alt_group->orig_group)
3254 return next_insn_same_sec(file, alt_group->orig_group->last_insn);
3256 return next_insn_same_sec(file, insn);
3260 * Follow the branch starting at the given instruction, and recursively follow
3261 * any other branches (jumps). Meanwhile, track the frame pointer state at
3262 * each instruction and validate all the rules described in
3263 * tools/objtool/Documentation/stack-validation.txt.
3265 static int validate_branch(struct objtool_file *file, struct symbol *func,
3266 struct instruction *insn, struct insn_state state)
3268 struct alternative *alt;
3269 struct instruction *next_insn, *prev_insn = NULL;
3270 struct section *sec;
3277 next_insn = next_insn_to_validate(file, insn);
3279 if (func && insn->func && func != insn->func->pfunc) {
3280 WARN("%s() falls through to next function %s()",
3281 func->name, insn->func->name);
3285 if (func && insn->ignore) {
3286 WARN_FUNC("BUG: why am I validating an ignored function?",
3291 visited = 1 << state.uaccess;
3292 if (insn->visited) {
3293 if (!insn->hint && !insn_cfi_match(insn, &state.cfi))
3296 if (insn->visited & visited)
3303 state.instr += insn->instr;
3306 state.cfi = *insn->cfi;
3308 /* XXX track if we actually changed state.cfi */
3310 if (prev_insn && !cficmp(prev_insn->cfi, &state.cfi)) {
3311 insn->cfi = prev_insn->cfi;
3314 insn->cfi = cfi_hash_find_or_add(&state.cfi);
3318 insn->visited |= visited;
3320 if (propagate_alt_cfi(file, insn))
3323 if (!insn->ignore_alts && !list_empty(&insn->alts)) {
3324 bool skip_orig = false;
3326 list_for_each_entry(alt, &insn->alts, list) {
3330 ret = validate_branch(file, func, alt->insn, state);
3333 BT_FUNC("(alt)", insn);
3342 if (handle_insn_ops(insn, next_insn, &state))
3345 switch (insn->type) {
3348 return validate_return(func, insn, &state);
3351 case INSN_CALL_DYNAMIC:
3352 ret = validate_call(file, insn, &state);
3356 if (opts.stackval && func && !is_fentry_call(insn) &&
3357 !has_valid_stack_frame(&state)) {
3358 WARN_FUNC("call without frame pointer save/setup",
3368 case INSN_JUMP_CONDITIONAL:
3369 case INSN_JUMP_UNCONDITIONAL:
3370 if (is_sibling_call(insn)) {
3371 ret = validate_sibling_call(file, insn, &state);
3375 } else if (insn->jump_dest) {
3376 ret = validate_branch(file, func,
3377 insn->jump_dest, state);
3380 BT_FUNC("(branch)", insn);
3385 if (insn->type == INSN_JUMP_UNCONDITIONAL)
3390 case INSN_JUMP_DYNAMIC:
3391 case INSN_JUMP_DYNAMIC_CONDITIONAL:
3392 if (is_sibling_call(insn)) {
3393 ret = validate_sibling_call(file, insn, &state);
3398 if (insn->type == INSN_JUMP_DYNAMIC)
3403 case INSN_CONTEXT_SWITCH:
3404 if (func && (!next_insn || !next_insn->hint)) {
3405 WARN_FUNC("unsupported instruction in callable function",
3412 if (state.uaccess) {
3413 WARN_FUNC("recursive UACCESS enable", sec, insn->offset);
3417 state.uaccess = true;
3421 if (!state.uaccess && func) {
3422 WARN_FUNC("redundant UACCESS disable", sec, insn->offset);
3426 if (func_uaccess_safe(func) && !state.uaccess_stack) {
3427 WARN_FUNC("UACCESS-safe disables UACCESS", sec, insn->offset);
3431 state.uaccess = false;
3436 WARN_FUNC("recursive STD", sec, insn->offset);
3444 if (!state.df && func) {
3445 WARN_FUNC("redundant CLD", sec, insn->offset);
3460 if (state.cfi.cfa.base == CFI_UNDEFINED)
3462 WARN("%s: unexpected end of section", sec->name);
3473 static int validate_unwind_hints(struct objtool_file *file, struct section *sec)
3475 struct instruction *insn;
3476 struct insn_state state;
3477 int ret, warnings = 0;
3482 init_insn_state(file, &state, sec);
3485 insn = find_insn(file, sec, 0);
3489 insn = list_first_entry(&file->insn_list, typeof(*insn), list);
3492 while (&insn->list != &file->insn_list && (!sec || insn->sec == sec)) {
3493 if (insn->hint && !insn->visited && !insn->ignore) {
3494 ret = validate_branch(file, insn->func, insn, state);
3495 if (ret && opts.backtrace)
3496 BT_FUNC("<=== (hint)", insn);
3500 insn = list_next_entry(insn, list);
3506 static int validate_retpoline(struct objtool_file *file)
3508 struct instruction *insn;
3511 for_each_insn(file, insn) {
3512 if (insn->type != INSN_JUMP_DYNAMIC &&
3513 insn->type != INSN_CALL_DYNAMIC)
3516 if (insn->retpoline_safe)
3520 * .init.text code is ran before userspace and thus doesn't
3521 * strictly need retpolines, except for modules which are
3522 * loaded late, they very much do need retpoline in their
3525 if (!strcmp(insn->sec->name, ".init.text") && !opts.module)
3528 WARN_FUNC("indirect %s found in RETPOLINE build",
3529 insn->sec, insn->offset,
3530 insn->type == INSN_JUMP_DYNAMIC ? "jump" : "call");
3538 static bool is_kasan_insn(struct instruction *insn)
3540 return (insn->type == INSN_CALL &&
3541 !strcmp(insn->call_dest->name, "__asan_handle_no_return"));
3544 static bool is_ubsan_insn(struct instruction *insn)
3546 return (insn->type == INSN_CALL &&
3547 !strcmp(insn->call_dest->name,
3548 "__ubsan_handle_builtin_unreachable"));
3551 static bool ignore_unreachable_insn(struct objtool_file *file, struct instruction *insn)
3554 struct instruction *prev_insn;
3556 if (insn->ignore || insn->type == INSN_NOP || insn->type == INSN_TRAP)
3560 * Ignore alternative replacement instructions. This can happen
3561 * when a whitelisted function uses one of the ALTERNATIVE macros.
3563 if (!strcmp(insn->sec->name, ".altinstr_replacement") ||
3564 !strcmp(insn->sec->name, ".altinstr_aux"))
3568 * Whole archive runs might encounter dead code from weak symbols.
3569 * This is where the linker will have dropped the weak symbol in
3570 * favour of a regular symbol, but leaves the code in place.
3572 * In this case we'll find a piece of code (whole function) that is not
3573 * covered by a !section symbol. Ignore them.
3575 if (opts.link && !insn->func) {
3576 int size = find_symbol_hole_containing(insn->sec, insn->offset);
3577 unsigned long end = insn->offset + size;
3579 if (!size) /* not a hole */
3582 if (size < 0) /* hole until the end */
3585 sec_for_each_insn_continue(file, insn) {
3587 * If we reach a visited instruction at or before the
3588 * end of the hole, ignore the unreachable.
3593 if (insn->offset >= end)
3597 * If this hole jumps to a .cold function, mark it ignore too.
3599 if (insn->jump_dest && insn->jump_dest->func &&
3600 strstr(insn->jump_dest->func->name, ".cold")) {
3601 struct instruction *dest = insn->jump_dest;
3602 func_for_each_insn(file, dest->func, dest)
3603 dest->ignore = true;
3613 if (insn->func->static_call_tramp)
3617 * CONFIG_UBSAN_TRAP inserts a UD2 when it sees
3618 * __builtin_unreachable(). The BUG() macro has an unreachable() after
3619 * the UD2, which causes GCC's undefined trap logic to emit another UD2
3620 * (or occasionally a JMP to UD2).
3622 * It may also insert a UD2 after calling a __noreturn function.
3624 prev_insn = list_prev_entry(insn, list);
3625 if ((prev_insn->dead_end || dead_end_function(file, prev_insn->call_dest)) &&
3626 (insn->type == INSN_BUG ||
3627 (insn->type == INSN_JUMP_UNCONDITIONAL &&
3628 insn->jump_dest && insn->jump_dest->type == INSN_BUG)))
3632 * Check if this (or a subsequent) instruction is related to
3633 * CONFIG_UBSAN or CONFIG_KASAN.
3635 * End the search at 5 instructions to avoid going into the weeds.
3637 for (i = 0; i < 5; i++) {
3639 if (is_kasan_insn(insn) || is_ubsan_insn(insn))
3642 if (insn->type == INSN_JUMP_UNCONDITIONAL) {
3643 if (insn->jump_dest &&
3644 insn->jump_dest->func == insn->func) {
3645 insn = insn->jump_dest;
3652 if (insn->offset + insn->len >= insn->func->offset + insn->func->len)
3655 insn = list_next_entry(insn, list);
3661 static int validate_symbol(struct objtool_file *file, struct section *sec,
3662 struct symbol *sym, struct insn_state *state)
3664 struct instruction *insn;
3668 WARN("%s() is missing an ELF size annotation", sym->name);
3672 if (sym->pfunc != sym || sym->alias != sym)
3675 insn = find_insn(file, sec, sym->offset);
3676 if (!insn || insn->ignore || insn->visited)
3679 state->uaccess = sym->uaccess_safe;
3681 ret = validate_branch(file, insn->func, insn, *state);
3682 if (ret && opts.backtrace)
3683 BT_FUNC("<=== (sym)", insn);
3687 static int validate_section(struct objtool_file *file, struct section *sec)
3689 struct insn_state state;
3690 struct symbol *func;
3693 list_for_each_entry(func, &sec->symbol_list, list) {
3694 if (func->type != STT_FUNC)
3697 init_insn_state(file, &state, sec);
3698 set_func_state(&state.cfi);
3700 warnings += validate_symbol(file, sec, func, &state);
3706 static int validate_noinstr_sections(struct objtool_file *file)
3708 struct section *sec;
3711 sec = find_section_by_name(file->elf, ".noinstr.text");
3713 warnings += validate_section(file, sec);
3714 warnings += validate_unwind_hints(file, sec);
3717 sec = find_section_by_name(file->elf, ".entry.text");
3719 warnings += validate_section(file, sec);
3720 warnings += validate_unwind_hints(file, sec);
3726 static int validate_functions(struct objtool_file *file)
3728 struct section *sec;
3731 for_each_sec(file, sec) {
3732 if (!(sec->sh.sh_flags & SHF_EXECINSTR))
3735 warnings += validate_section(file, sec);
3741 static void mark_endbr_used(struct instruction *insn)
3743 if (!list_empty(&insn->call_node))
3744 list_del_init(&insn->call_node);
3747 static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn)
3749 struct instruction *dest;
3750 struct reloc *reloc;
3755 * Looking for function pointer load relocations. Ignore
3756 * direct/indirect branches:
3758 switch (insn->type) {
3760 case INSN_CALL_DYNAMIC:
3761 case INSN_JUMP_CONDITIONAL:
3762 case INSN_JUMP_UNCONDITIONAL:
3763 case INSN_JUMP_DYNAMIC:
3764 case INSN_JUMP_DYNAMIC_CONDITIONAL:
3772 for (reloc = insn_reloc(file, insn);
3774 reloc = find_reloc_by_dest_range(file->elf, insn->sec,
3776 (insn->offset + insn->len) - (reloc->offset + 1))) {
3779 * static_call_update() references the trampoline, which
3780 * doesn't have (or need) ENDBR. Skip warning in that case.
3782 if (reloc->sym->static_call_tramp)
3785 off = reloc->sym->offset;
3786 if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)
3787 off += arch_dest_reloc_offset(reloc->addend);
3789 off += reloc->addend;
3791 dest = find_insn(file, reloc->sym->sec, off);
3795 if (dest->type == INSN_ENDBR) {
3796 mark_endbr_used(dest);
3800 if (dest->func && dest->func == insn->func) {
3802 * Anything from->to self is either _THIS_IP_ or
3805 * There is no sane way to annotate _THIS_IP_ since the
3806 * compiler treats the relocation as a constant and is
3807 * happy to fold in offsets, skewing any annotation we
3808 * do, leading to vast amounts of false-positives.
3810 * There's also compiler generated _THIS_IP_ through
3811 * KCOV and such which we have no hope of annotating.
3813 * As such, blanket accept self-references without
3822 WARN_FUNC("relocation to !ENDBR: %s",
3823 insn->sec, insn->offset,
3824 offstr(dest->sec, dest->offset));
3832 static int validate_ibt_data_reloc(struct objtool_file *file,
3833 struct reloc *reloc)
3835 struct instruction *dest;
3837 dest = find_insn(file, reloc->sym->sec,
3838 reloc->sym->offset + reloc->addend);
3842 if (dest->type == INSN_ENDBR) {
3843 mark_endbr_used(dest);
3850 WARN_FUNC("data relocation to !ENDBR: %s",
3851 reloc->sec->base, reloc->offset,
3852 offstr(dest->sec, dest->offset));
3858 * Validate IBT rules and remove used ENDBR instructions from the seal list.
3859 * Unused ENDBR instructions will be annotated for sealing (i.e., replaced with
3860 * NOPs) later, in create_ibt_endbr_seal_sections().
3862 static int validate_ibt(struct objtool_file *file)
3864 struct section *sec;
3865 struct reloc *reloc;
3866 struct instruction *insn;
3869 for_each_insn(file, insn)
3870 warnings += validate_ibt_insn(file, insn);
3872 for_each_sec(file, sec) {
3874 /* Already done by validate_ibt_insn() */
3875 if (sec->sh.sh_flags & SHF_EXECINSTR)
3882 * These sections can reference text addresses, but not with
3883 * the intent to indirect branch to them.
3885 if (!strncmp(sec->name, ".discard", 8) ||
3886 !strncmp(sec->name, ".debug", 6) ||
3887 !strcmp(sec->name, ".altinstructions") ||
3888 !strcmp(sec->name, ".ibt_endbr_seal") ||
3889 !strcmp(sec->name, ".orc_unwind_ip") ||
3890 !strcmp(sec->name, ".parainstructions") ||
3891 !strcmp(sec->name, ".retpoline_sites") ||
3892 !strcmp(sec->name, ".smp_locks") ||
3893 !strcmp(sec->name, ".static_call_sites") ||
3894 !strcmp(sec->name, "_error_injection_whitelist") ||
3895 !strcmp(sec->name, "_kprobe_blacklist") ||
3896 !strcmp(sec->name, "__bug_table") ||
3897 !strcmp(sec->name, "__ex_table") ||
3898 !strcmp(sec->name, "__jump_table") ||
3899 !strcmp(sec->name, "__mcount_loc") ||
3900 !strcmp(sec->name, "__tracepoints"))
3903 list_for_each_entry(reloc, &sec->reloc->reloc_list, list)
3904 warnings += validate_ibt_data_reloc(file, reloc);
3910 static int validate_sls(struct objtool_file *file)
3912 struct instruction *insn, *next_insn;
3915 for_each_insn(file, insn) {
3916 next_insn = next_insn_same_sec(file, insn);
3918 if (insn->retpoline_safe)
3921 switch (insn->type) {
3923 if (!next_insn || next_insn->type != INSN_TRAP) {
3924 WARN_FUNC("missing int3 after ret",
3925 insn->sec, insn->offset);
3930 case INSN_JUMP_DYNAMIC:
3931 if (!next_insn || next_insn->type != INSN_TRAP) {
3932 WARN_FUNC("missing int3 after indirect jump",
3933 insn->sec, insn->offset);
3945 static int validate_reachable_instructions(struct objtool_file *file)
3947 struct instruction *insn;
3949 if (file->ignore_unreachables)
3952 for_each_insn(file, insn) {
3953 if (insn->visited || ignore_unreachable_insn(file, insn))
3956 WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
3963 int check(struct objtool_file *file)
3965 int ret, warnings = 0;
3967 arch_initial_func_cfi_state(&initial_func_cfi);
3968 init_cfi_state(&init_cfi);
3969 init_cfi_state(&func_cfi);
3970 set_func_state(&func_cfi);
3972 if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3)))
3975 cfi_hash_add(&init_cfi);
3976 cfi_hash_add(&func_cfi);
3978 ret = decode_sections(file);
3984 if (list_empty(&file->insn_list))
3987 if (opts.retpoline) {
3988 ret = validate_retpoline(file);
3994 if (opts.stackval || opts.orc || opts.uaccess) {
3995 ret = validate_functions(file);
4000 ret = validate_unwind_hints(file, NULL);
4006 ret = validate_reachable_instructions(file);
4012 } else if (opts.noinstr) {
4013 ret = validate_noinstr_sections(file);
4020 ret = validate_ibt(file);
4027 ret = validate_sls(file);
4033 if (opts.static_call) {
4034 ret = create_static_call_sections(file);
4040 if (opts.retpoline) {
4041 ret = create_retpoline_sites_sections(file);
4046 ret = create_return_sites_sections(file);
4053 ret = create_mcount_loc_sections(file);
4060 ret = create_ibt_endbr_seal_sections(file);
4066 if (opts.orc && !list_empty(&file->insn_list)) {
4067 ret = orc_create(file);
4075 printf("nr_insns_visited: %ld\n", nr_insns_visited);
4076 printf("nr_cfi: %ld\n", nr_cfi);
4077 printf("nr_cfi_reused: %ld\n", nr_cfi_reused);
4078 printf("nr_cfi_cache: %ld\n", nr_cfi_cache);
4083 * For now, don't fail the kernel build on fatal warnings. These
4084 * errors are still fairly common due to the growing matrix of
4085 * supported toolchains and their recent pace of change.