1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
11 #include <subcmd/exec-cmd.h>
12 #include <subcmd/pager.h>
13 #include <linux/kernel.h>
15 #include <objtool/builtin.h>
16 #include <objtool/objtool.h>
17 #include <objtool/warn.h>
22 static struct objtool_file file
;
24 static bool objtool_create_backup(const char *_objname
)
26 int len
= strlen(_objname
);
27 char *buf
, *base
, *name
= malloc(len
+6);
31 perror("failed backup name malloc");
35 strcpy(name
, _objname
);
36 strcpy(name
+ len
, ".orig");
38 d
= open(name
, O_CREAT
|O_WRONLY
|O_TRUNC
, 0644);
40 perror("failed to create backup file");
44 s
= open(_objname
, O_RDONLY
);
46 perror("failed to open orig file");
52 perror("failed backup data malloc");
56 while ((l
= read(s
, buf
, 4096)) > 0) {
59 t
= write(d
, base
, l
);
61 perror("failed backup write");
70 perror("failed backup read");
82 struct objtool_file
*objtool_open_read(const char *_objname
)
85 if (strcmp(objname
, _objname
)) {
86 WARN("won't handle more than one file at a time");
93 file
.elf
= elf_open_read(objname
, O_RDWR
);
97 if (opts
.backup
&& !objtool_create_backup(objname
)) {
98 WARN("can't create backup file");
102 hash_init(file
.insn_hash
);
103 INIT_LIST_HEAD(&file
.retpoline_call_list
);
104 INIT_LIST_HEAD(&file
.return_thunk_list
);
105 INIT_LIST_HEAD(&file
.static_call_list
);
106 INIT_LIST_HEAD(&file
.mcount_loc_list
);
107 INIT_LIST_HEAD(&file
.endbr_list
);
108 INIT_LIST_HEAD(&file
.call_list
);
109 file
.ignore_unreachables
= opts
.no_unreachable
;
115 void objtool_pv_add(struct objtool_file
*f
, int idx
, struct symbol
*func
)
121 WARN("paravirt confusion");
126 * These functions will be patched into native code,
127 * see paravirt_patch().
129 if (!strcmp(func
->name
, "_paravirt_nop") ||
130 !strcmp(func
->name
, "_paravirt_ident_64"))
133 /* already added this function */
134 if (!list_empty(&func
->pv_target
))
137 list_add(&func
->pv_target
, &f
->pv_ops
[idx
].targets
);
138 f
->pv_ops
[idx
].clean
= false;
141 int main(int argc
, const char **argv
)
143 static const char *UNUSED
= "OBJTOOL_NOT_IMPLEMENTED";
146 exec_cmd_init("objtool", UNUSED
, UNUSED
, UNUSED
);
149 return objtool_run(argc
, argv
);