objtool.c (2daf7faba7ded8703e4b4ebc8b161f22272fc91a) | objtool.c (b51277eb9775ce916f9efd2c51533e481180c1e8) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com> 4 */ 5 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com> 4 */ 5 |
6/* 7 * objtool: 8 * 9 * The 'check' subcmd analyzes every .o file and ensures the validity of its 10 * stack trace metadata. It enforces a set of rules on asm code and C inline 11 * assembly code so that stack traces can be reliable. 12 * 13 * For more information, see tools/objtool/Documentation/stack-validation.txt. 14 */ 15 | |
16#include <stdio.h> 17#include <stdbool.h> 18#include <string.h> 19#include <stdlib.h> 20#include <unistd.h> 21#include <subcmd/exec-cmd.h> 22#include <subcmd/pager.h> 23#include <linux/kernel.h> 24 25#include <objtool/builtin.h> 26#include <objtool/objtool.h> 27#include <objtool/warn.h> 28 | 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 |
29struct cmd_struct { 30 const char *name; 31 int (*fn)(int, const char **); 32 const char *help; 33}; 34 35static const char objtool_usage_string[] = 36 "objtool COMMAND [ARGS]"; 37 38static struct cmd_struct objtool_cmds[] = { 39 {"check", cmd_check, "Perform stack metadata validation on an object file" }, 40 {"orc", cmd_orc, "Generate in-place ORC unwind tables for an object file" }, 41}; 42 | |
43bool help; 44 45const char *objname; 46static struct objtool_file file; 47 48static bool objtool_create_backup(const char *_objname) 49{ 50 int len = strlen(_objname); --- 105 unchanged lines hidden (view full) --- 156 /* already added this function */ 157 if (!list_empty(&func->pv_target)) 158 return; 159 160 list_add(&func->pv_target, &f->pv_ops[idx].targets); 161 f->pv_ops[idx].clean = false; 162} 163 | 19bool help; 20 21const char *objname; 22static struct objtool_file file; 23 24static bool objtool_create_backup(const char *_objname) 25{ 26 int len = strlen(_objname); --- 105 unchanged lines hidden (view full) --- 132 /* already added this function */ 133 if (!list_empty(&func->pv_target)) 134 return; 135 136 list_add(&func->pv_target, &f->pv_ops[idx].targets); 137 f->pv_ops[idx].clean = false; 138} 139 |
164static void cmd_usage(void) 165{ 166 unsigned int i, longest = 0; 167 168 printf("\n usage: %s\n\n", objtool_usage_string); 169 170 for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) { 171 if (longest < strlen(objtool_cmds[i].name)) 172 longest = strlen(objtool_cmds[i].name); 173 } 174 175 puts(" Commands:"); 176 for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) { 177 printf(" %-*s ", longest, objtool_cmds[i].name); 178 puts(objtool_cmds[i].help); 179 } 180 181 printf("\n"); 182 183 if (!help) 184 exit(129); 185 exit(0); 186} 187 188static void handle_options(int *argc, const char ***argv) 189{ 190 while (*argc > 0) { 191 const char *cmd = (*argv)[0]; 192 193 if (cmd[0] != '-') 194 break; 195 196 if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) { 197 help = true; 198 break; 199 } else { 200 fprintf(stderr, "Unknown option: %s\n", cmd); 201 cmd_usage(); 202 } 203 204 (*argv)++; 205 (*argc)--; 206 } 207} 208 209static void handle_internal_command(int argc, const char **argv) 210{ 211 const char *cmd = argv[0]; 212 unsigned int i, ret; 213 214 for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) { 215 struct cmd_struct *p = objtool_cmds+i; 216 217 if (strcmp(p->name, cmd)) 218 continue; 219 220 ret = p->fn(argc, argv); 221 222 exit(ret); 223 } 224 225 cmd_usage(); 226} 227 | |
228int main(int argc, const char **argv) 229{ 230 static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED"; 231 232 /* libsubcmd init */ 233 exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED); 234 pager_init(UNUSED); 235 | 140int main(int argc, const char **argv) 141{ 142 static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED"; 143 144 /* libsubcmd init */ 145 exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED); 146 pager_init(UNUSED); 147 |
236 argv++; 237 argc--; 238 handle_options(&argc, &argv); | 148 objtool_run(argc, argv); |
239 | 149 |
240 if (!argc || help) 241 cmd_usage(); 242 243 handle_internal_command(argc, argv); 244 | |
245 return 0; 246} | 150 return 0; 151} |