1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com> 4 */ 5 6 #include <stdio.h> 7 #include <stdbool.h> 8 #include <string.h> 9 #include <stdlib.h> 10 #include <unistd.h> 11 #include <subcmd/exec-cmd.h> 12 #include <subcmd/pager.h> 13 #include <linux/kernel.h> 14 15 #include <objtool/builtin.h> 16 #include <objtool/objtool.h> 17 #include <objtool/warn.h> 18 19 bool help; 20 21 static struct objtool_file file; 22 23 struct objtool_file *objtool_open_read(const char *filename) 24 { 25 if (file.elf) { 26 ERROR("won't handle more than one file at a time"); 27 return NULL; 28 } 29 30 file.elf = elf_open_read(filename, O_RDWR); 31 if (!file.elf) 32 return NULL; 33 34 hash_init(file.insn_hash); 35 INIT_LIST_HEAD(&file.retpoline_call_list); 36 INIT_LIST_HEAD(&file.return_thunk_list); 37 INIT_LIST_HEAD(&file.static_call_list); 38 INIT_LIST_HEAD(&file.mcount_loc_list); 39 INIT_LIST_HEAD(&file.endbr_list); 40 INIT_LIST_HEAD(&file.call_list); 41 file.ignore_unreachables = opts.no_unreachable; 42 file.hints = false; 43 44 return &file; 45 } 46 47 int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func) 48 { 49 if (!opts.noinstr) 50 return 0; 51 52 if (!f->pv_ops) { 53 ERROR("paravirt confusion"); 54 return -1; 55 } 56 57 /* 58 * These functions will be patched into native code, 59 * see paravirt_patch(). 60 */ 61 if (!strcmp(func->name, "_paravirt_nop") || 62 !strcmp(func->name, "_paravirt_ident_64")) 63 return 0; 64 65 /* already added this function */ 66 if (!list_empty(&func->pv_target)) 67 return 0; 68 69 list_add(&func->pv_target, &f->pv_ops[idx].targets); 70 f->pv_ops[idx].clean = false; 71 return 0; 72 } 73 74 int main(int argc, const char **argv) 75 { 76 static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED"; 77 78 /* libsubcmd init */ 79 exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED); 80 pager_init(UNUSED); 81 82 return objtool_run(argc, argv); 83 } 84