blob: c807984a03c1a00b04e77c948cc08ab26053cbed [file] [log] [blame]
Thomas Gleixner1ccea772019-05-19 15:51:43 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06002/*
Josh Poimboeufdcc914f2017-06-28 10:11:05 -05003 * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
Josh Poimboeuf442f04c2016-02-28 22:22:41 -06004 */
5
6/*
7 * objtool check:
8 *
9 * This command analyzes every .o file and ensures the validity of its stack
10 * 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
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060016#include <subcmd/parse-options.h>
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060017#include "builtin.h"
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050018#include "check.h"
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060019
Peter Zijlstraea242132019-02-25 12:50:09 +010020bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess;
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060021
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050022static const char * const check_usage[] = {
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060023 "objtool check [<options>] file.o",
24 NULL,
25};
26
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050027const struct option check_options[] = {
Josh Poimboeuf867ac9d2017-07-24 18:34:14 -050028 OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
29 OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
Peter Zijlstrab5bc2232018-01-16 10:24:06 +010030 OPT_BOOLEAN('r', "retpoline", &retpoline, "Validate retpoline assumptions"),
Peter Zijlstraca41b972018-01-31 10:18:28 +010031 OPT_BOOLEAN('m', "module", &module, "Indicates the object will be part of a kernel module"),
Peter Zijlstra7697eee2019-03-01 11:15:49 +010032 OPT_BOOLEAN('b', "backtrace", &backtrace, "unwind on error"),
Peter Zijlstraea242132019-02-25 12:50:09 +010033 OPT_BOOLEAN('a', "uaccess", &uaccess, "enable uaccess checking"),
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050034 OPT_END(),
35};
36
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060037int cmd_check(int argc, const char **argv)
38{
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050039 const char *objname;
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060040
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050041 argc = parse_options(argc, argv, check_options, check_usage, 0);
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060042
43 if (argc != 1)
Josh Poimboeufdcc914f2017-06-28 10:11:05 -050044 usage_with_options(check_usage, check_options);
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060045
46 objname = argv[0];
47
Peter Zijlstra43a45252018-01-16 17:16:32 +010048 return check(objname, false);
Josh Poimboeuf442f04c2016-02-28 22:22:41 -060049}