~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/objtool/objtool.c

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 <subcmd/exec-cmd.h>
 21 #include <subcmd/pager.h>
 22 #include <linux/kernel.h>
 23 
 24 #include "builtin.h"
 25 
 26 struct cmd_struct {
 27         const char *name;
 28         int (*fn)(int, const char **);
 29         const char *help;
 30 };
 31 
 32 static const char objtool_usage_string[] =
 33         "objtool COMMAND [ARGS]";
 34 
 35 static struct cmd_struct objtool_cmds[] = {
 36         {"check",       cmd_check,      "Perform stack metadata validation on an object file" },
 37         {"orc",         cmd_orc,        "Generate in-place ORC unwind tables for an object file" },
 38 };
 39 
 40 bool help;
 41 
 42 static void cmd_usage(void)
 43 {
 44         unsigned int i, longest = 0;
 45 
 46         printf("\n usage: %s\n\n", objtool_usage_string);
 47 
 48         for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
 49                 if (longest < strlen(objtool_cmds[i].name))
 50                         longest = strlen(objtool_cmds[i].name);
 51         }
 52 
 53         puts(" Commands:");
 54         for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
 55                 printf("   %-*s   ", longest, objtool_cmds[i].name);
 56                 puts(objtool_cmds[i].help);
 57         }
 58 
 59         printf("\n");
 60 
 61         if (!help)
 62                 exit(129);
 63         exit(0);
 64 }
 65 
 66 static void handle_options(int *argc, const char ***argv)
 67 {
 68         while (*argc > 0) {
 69                 const char *cmd = (*argv)[0];
 70 
 71                 if (cmd[0] != '-')
 72                         break;
 73 
 74                 if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) {
 75                         help = true;
 76                         break;
 77                 } else {
 78                         fprintf(stderr, "Unknown option: %s\n", cmd);
 79                         cmd_usage();
 80                 }
 81 
 82                 (*argv)++;
 83                 (*argc)--;
 84         }
 85 }
 86 
 87 static void handle_internal_command(int argc, const char **argv)
 88 {
 89         const char *cmd = argv[0];
 90         unsigned int i, ret;
 91 
 92         for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
 93                 struct cmd_struct *p = objtool_cmds+i;
 94 
 95                 if (strcmp(p->name, cmd))
 96                         continue;
 97 
 98                 ret = p->fn(argc, argv);
 99 
100                 exit(ret);
101         }
102 
103         cmd_usage();
104 }
105 
106 int main(int argc, const char **argv)
107 {
108         static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED";
109 
110         /* libsubcmd init */
111         exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED);
112         pager_init(UNUSED);
113 
114         argv++;
115         argc--;
116         handle_options(&argc, &argv);
117 
118         if (!argc || help)
119                 cmd_usage();
120 
121         handle_internal_command(argc, argv);
122 
123         return 0;
124 }
125 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp