Skip to content

Commit 0decf1f

Browse files
Matt Helsleyjpoimboe
authored andcommitted
objtool: Enable compilation of objtool for all architectures
Objtool currently only compiles for x86 architectures. This is fine as it presently does not support tooling for other architectures. However, we would like to be able to convert other kernel tools to run as objtool sub commands because they too process ELF object files. This will allow us to convert tools such as recordmcount to use objtool's ELF code. Since much of recordmcount's ELF code is copy-paste code to/from a variety of other kernel tools (look at modpost for example) this means that if we can convert recordmcount we can convert more. We define weak definitions for subcommand entry functions and other weak definitions for shared functions critical to building existing subcommands. These return 127 when the command is missing which signify tools that do not exist on all architectures. In this case the "check" and "orc" tools do not exist on all architectures so we only add them for x86. Future changes adding support for "check", to arm64 for example, can then modify the SUBCMD_CHECK variable when building for arm64. Objtool is not currently wired in to KConfig to be built for other architectures because it's not needed for those architectures and there are no commands it supports other than those for x86. As more command support is enabled on various architectures the necessary KConfig changes can be made (e.g. adding "STACK_VALIDATION") to trigger building objtool. [ jpoimboe: remove aliases, add __weak macro, add error messages ] Cc: Julien Thierry <[email protected]> Signed-off-by: Matt Helsley <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]>
1 parent d37c90d commit 0decf1f

File tree

12 files changed

+73
-34
lines changed

12 files changed

+73
-34
lines changed

tools/objtool/Build

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
objtool-y += arch/$(SRCARCH)/
2+
3+
objtool-y += weak.o
4+
5+
objtool-$(SUBCMD_CHECK) += check.o
6+
objtool-$(SUBCMD_CHECK) += special.o
7+
objtool-$(SUBCMD_ORC) += check.o
8+
objtool-$(SUBCMD_ORC) += orc_gen.o
9+
objtool-$(SUBCMD_ORC) += orc_dump.o
10+
211
objtool-y += builtin-check.o
312
objtool-y += builtin-orc.o
4-
objtool-y += check.o
5-
objtool-y += orc_gen.o
6-
objtool-y += orc_dump.o
713
objtool-y += elf.o
8-
objtool-y += special.o
914
objtool-y += objtool.o
1015

1116
objtool-y += libstring.o

tools/objtool/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(CC) $(CFLAGS) -x c -E -
4646
CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
4747

4848
AWK = awk
49+
50+
SUBCMD_CHECK := n
51+
SUBCMD_ORC := n
52+
53+
ifeq ($(SRCARCH),x86)
54+
SUBCMD_CHECK := y
55+
SUBCMD_ORC := y
56+
endif
57+
58+
export SUBCMD_CHECK SUBCMD_ORC
4959
export srctree OUTPUT CFLAGS SRCARCH AWK
5060
include $(srctree)/tools/build/Makefile.include
5161

tools/objtool/arch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
#include <stdbool.h>
1010
#include <linux/list.h>
11-
#include "elf.h"
11+
#include "objtool.h"
1212
#include "cfi.h"
1313

14+
#include <asm/orc_types.h>
15+
1416
enum insn_type {
1517
INSN_JUMP_CONDITIONAL,
1618
INSN_JUMP_UNCONDITIONAL,

tools/objtool/builtin-check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <subcmd/parse-options.h>
1717
#include <string.h>
1818
#include "builtin.h"
19-
#include "check.h"
19+
#include "objtool.h"
2020

2121
bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, validate_dup, vmlinux;
2222

tools/objtool/builtin-orc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
#include <string.h>
1616
#include "builtin.h"
17-
#include "check.h"
18-
17+
#include "objtool.h"
1918

2019
static const char *orc_usage[] = {
2120
"objtool orc generate [<options>] file.o",

tools/objtool/check.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#include <stdlib.h>
88

99
#include "builtin.h"
10+
#include "cfi.h"
11+
#include "arch.h"
1012
#include "check.h"
11-
#include "elf.h"
1213
#include "special.h"
13-
#include "arch.h"
1414
#include "warn.h"
1515

1616
#include <linux/hashtable.h>

tools/objtool/check.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#define _CHECK_H
88

99
#include <stdbool.h>
10-
#include "objtool.h"
1110
#include "cfi.h"
1211
#include "arch.h"
13-
#include "orc.h"
1412

1513
struct insn_state {
1614
struct cfi_state cfi;
@@ -47,8 +45,6 @@ struct instruction {
4745
struct orc_entry orc;
4846
};
4947

50-
int check(const char *objname, bool orc);
51-
5248
struct instruction *find_insn(struct objtool_file *file,
5349
struct section *sec, unsigned long offset);
5450

tools/objtool/objtool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ struct objtool_file {
1919
bool ignore_unreachables, c_file, hints, rodata;
2020
};
2121

22+
int check(const char *objname, bool orc);
23+
int orc_dump(const char *objname);
24+
int create_orc(struct objtool_file *file);
25+
int create_orc_sections(struct objtool_file *file);
26+
2227
#endif /* _OBJTOOL_H */

tools/objtool/orc.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

tools/objtool/orc_dump.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55

66
#include <unistd.h>
7-
#include "orc.h"
7+
#include <asm/orc_types.h>
8+
#include "objtool.h"
89
#include "warn.h"
910

1011
static const char *reg_name(unsigned int reg)

0 commit comments

Comments
 (0)