hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/tools/objtool/objtool.c
....@@ -1,18 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version 2
7
- * of the License, or (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
164 */
175
186 /*
....@@ -34,6 +22,8 @@
3422 #include <linux/kernel.h>
3523
3624 #include "builtin.h"
25
+#include "objtool.h"
26
+#include "warn.h"
3727
3828 struct cmd_struct {
3929 const char *name;
....@@ -50,6 +40,37 @@
5040 };
5141
5242 bool help;
43
+
44
+const char *objname;
45
+static struct objtool_file file;
46
+
47
+struct objtool_file *objtool_open_read(const char *_objname)
48
+{
49
+ if (objname) {
50
+ if (strcmp(objname, _objname)) {
51
+ WARN("won't handle more than one file at a time");
52
+ return NULL;
53
+ }
54
+ return &file;
55
+ }
56
+ objname = _objname;
57
+
58
+ file.elf = elf_open_read(objname, O_RDWR);
59
+ if (!file.elf)
60
+ return NULL;
61
+
62
+ INIT_LIST_HEAD(&file.insn_list);
63
+ hash_init(file.insn_hash);
64
+ INIT_LIST_HEAD(&file.retpoline_call_list);
65
+ INIT_LIST_HEAD(&file.return_thunk_list);
66
+ INIT_LIST_HEAD(&file.static_call_list);
67
+ INIT_LIST_HEAD(&file.mcount_loc_list);
68
+ file.c_file = !vmlinux && find_section_by_name(file.elf, ".comment");
69
+ file.ignore_unreachables = no_unreachable;
70
+ file.hints = false;
71
+
72
+ return &file;
73
+}
5374
5475 static void cmd_usage(void)
5576 {
....@@ -70,7 +91,9 @@
7091
7192 printf("\n");
7293
73
- exit(129);
94
+ if (!help)
95
+ exit(129);
96
+ exit(0);
7497 }
7598
7699 static void handle_options(int *argc, const char ***argv)