Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v5.4
  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
 26struct cmd_struct {
 27	const char *name;
 28	int (*fn)(int, const char **);
 29	const char *help;
 30};
 31
 32static const char objtool_usage_string[] =
 33	"objtool COMMAND [ARGS]";
 34
 35static 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
 40bool help;
 41
 42static 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	exit(129);
 62}
 63
 64static void handle_options(int *argc, const char ***argv)
 65{
 66	while (*argc > 0) {
 67		const char *cmd = (*argv)[0];
 68
 69		if (cmd[0] != '-')
 70			break;
 71
 72		if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) {
 73			help = true;
 74			break;
 75		} else {
 76			fprintf(stderr, "Unknown option: %s\n", cmd);
 77			cmd_usage();
 78		}
 79
 80		(*argv)++;
 81		(*argc)--;
 82	}
 83}
 84
 85static void handle_internal_command(int argc, const char **argv)
 86{
 87	const char *cmd = argv[0];
 88	unsigned int i, ret;
 89
 90	for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
 91		struct cmd_struct *p = objtool_cmds+i;
 92
 93		if (strcmp(p->name, cmd))
 94			continue;
 95
 96		ret = p->fn(argc, argv);
 97
 98		exit(ret);
 99	}
100
101	cmd_usage();
102}
103
104int main(int argc, const char **argv)
105{
106	static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED";
107
108	/* libsubcmd init */
109	exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED);
110	pager_init(UNUSED);
111
112	argv++;
113	argc--;
114	handle_options(&argc, &argv);
115
116	if (!argc || help)
117		cmd_usage();
118
119	handle_internal_command(argc, argv);
120
121	return 0;
122}
v4.17
 
  1/*
  2 * 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/>.
 16 */
 17
 18/*
 19 * objtool:
 20 *
 21 * The 'check' subcmd analyzes every .o file and ensures the validity of its
 22 * stack trace metadata.  It enforces a set of rules on asm code and C inline
 23 * assembly code so that stack traces can be reliable.
 24 *
 25 * For more information, see tools/objtool/Documentation/stack-validation.txt.
 26 */
 27
 28#include <stdio.h>
 29#include <stdbool.h>
 30#include <string.h>
 31#include <stdlib.h>
 32#include <subcmd/exec-cmd.h>
 33#include <subcmd/pager.h>
 34#include <linux/kernel.h>
 35
 36#include "builtin.h"
 37
 38struct cmd_struct {
 39	const char *name;
 40	int (*fn)(int, const char **);
 41	const char *help;
 42};
 43
 44static const char objtool_usage_string[] =
 45	"objtool COMMAND [ARGS]";
 46
 47static struct cmd_struct objtool_cmds[] = {
 48	{"check",	cmd_check,	"Perform stack metadata validation on an object file" },
 49	{"orc",		cmd_orc,	"Generate in-place ORC unwind tables for an object file" },
 50};
 51
 52bool help;
 53
 54static void cmd_usage(void)
 55{
 56	unsigned int i, longest = 0;
 57
 58	printf("\n usage: %s\n\n", objtool_usage_string);
 59
 60	for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
 61		if (longest < strlen(objtool_cmds[i].name))
 62			longest = strlen(objtool_cmds[i].name);
 63	}
 64
 65	puts(" Commands:");
 66	for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
 67		printf("   %-*s   ", longest, objtool_cmds[i].name);
 68		puts(objtool_cmds[i].help);
 69	}
 70
 71	printf("\n");
 72
 73	exit(129);
 74}
 75
 76static void handle_options(int *argc, const char ***argv)
 77{
 78	while (*argc > 0) {
 79		const char *cmd = (*argv)[0];
 80
 81		if (cmd[0] != '-')
 82			break;
 83
 84		if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h")) {
 85			help = true;
 86			break;
 87		} else {
 88			fprintf(stderr, "Unknown option: %s\n", cmd);
 89			cmd_usage();
 90		}
 91
 92		(*argv)++;
 93		(*argc)--;
 94	}
 95}
 96
 97static void handle_internal_command(int argc, const char **argv)
 98{
 99	const char *cmd = argv[0];
100	unsigned int i, ret;
101
102	for (i = 0; i < ARRAY_SIZE(objtool_cmds); i++) {
103		struct cmd_struct *p = objtool_cmds+i;
104
105		if (strcmp(p->name, cmd))
106			continue;
107
108		ret = p->fn(argc, argv);
109
110		exit(ret);
111	}
112
113	cmd_usage();
114}
115
116int main(int argc, const char **argv)
117{
118	static const char *UNUSED = "OBJTOOL_NOT_IMPLEMENTED";
119
120	/* libsubcmd init */
121	exec_cmd_init("objtool", UNUSED, UNUSED, UNUSED);
122	pager_init(UNUSED);
123
124	argv++;
125	argc--;
126	handle_options(&argc, &argv);
127
128	if (!argc || help)
129		cmd_usage();
130
131	handle_internal_command(argc, argv);
132
133	return 0;
134}