Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

objtool: Rework header include paths

Currently objtool headers are being included either by their base name
or included via ../ from a parent directory. In case of a base name usage:

#include "warn.h"
#include "arch_elf.h"

it does not make it apparent from which directory the file comes from.
To make it slightly better, and actually to avoid name clashes some arch
specific files have "arch_" suffix. And files from an arch folder have
to revert to including via ../ e.g:
#include "../../elf.h"

With additional architectures support and the code base growth there is
a need for clearer headers naming scheme for multiple reasons:
1. to make it instantly obvious where these files come from (objtool
itself / objtool arch|generic folders / some other external files),
2. to avoid name clashes of objtool arch specific headers, potential
obtool arch generic headers and the system header files (there is
/usr/include/elf.h already),
3. to avoid ../ includes and improve code readability.
4. to give a warm fuzzy feeling to developers who are mostly kernel
developers and are accustomed to linux kernel headers arranging
scheme.

Doesn't this make it instantly obvious where are these files come from?

#include <objtool/warn.h>
#include <arch/elf.h>

And doesn't it look nicer to avoid ugly ../ includes? Which also
guarantees this is elf.h from the objtool and not /usr/include/elf.h.

#include <objtool/elf.h>

This patch defines and implements new objtool headers arranging
scheme. Which is:
- all generic headers go to include/objtool (similar to include/linux)
- all arch headers go to arch/$(SRCARCH)/include/arch (to get arch
prefix). This is similar to linux arch specific "asm/*" headers but we
are not abusing "asm" name and calling it what it is. This also helps
to prevent name clashes (arch is not used in system headers or kernel
exports).

To bring objtool to this state the following things are done:
1. current top level tools/objtool/ headers are moved into
include/objtool/ subdirectory,
2. arch specific headers, currently only arch/x86/include/ are moved into
arch/x86/include/arch/ and were stripped of "arch_" suffix,
3. new -I$(srctree)/tools/objtool/include include path to make
includes like <objtool/warn.h> possible,
4. rewriting file includes,
5. make git not to ignore include/objtool/ subdirectory.

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

authored by

Vasily Gorbik and committed by
Josh Poimboeuf
7786032e 8bfe2732

+48 -47
+1 -1
tools/objtool/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 arch/x86/lib/inat-tables.c 3 - objtool 3 + /objtool 4 4 fixdep
+1
tools/objtool/Makefile
··· 27 27 INCLUDES := -I$(srctree)/tools/include \ 28 28 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ 29 29 -I$(srctree)/tools/arch/$(SRCARCH)/include \ 30 + -I$(srctree)/tools/objtool/include \ 30 31 -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include 31 32 WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs 32 33 CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
+2 -2
tools/objtool/arch.h tools/objtool/include/objtool/arch.h
··· 8 8 9 9 #include <stdbool.h> 10 10 #include <linux/list.h> 11 - #include "objtool.h" 12 - #include "cfi.h" 11 + #include <objtool/objtool.h> 12 + #include <objtool/cfi.h> 13 13 14 14 #ifdef INSN_USE_ORC 15 15 #include <asm/orc_types.h>
+4 -4
tools/objtool/arch/x86/decode.c
··· 11 11 #include "../../../arch/x86/lib/inat.c" 12 12 #include "../../../arch/x86/lib/insn.c" 13 13 14 - #include "../../check.h" 15 - #include "../../elf.h" 16 - #include "../../arch.h" 17 - #include "../../warn.h" 18 14 #include <asm/orc_types.h> 15 + #include <objtool/check.h> 16 + #include <objtool/elf.h> 17 + #include <objtool/arch.h> 18 + #include <objtool/warn.h> 19 19 20 20 static unsigned char op_to_cfi_reg[][2] = { 21 21 {CFI_AX, CFI_R8},
tools/objtool/arch/x86/include/arch_elf.h tools/objtool/arch/x86/include/arch/elf.h
tools/objtool/arch/x86/include/arch_endianness.h tools/objtool/arch/x86/include/arch/endianness.h
tools/objtool/arch/x86/include/arch_special.h tools/objtool/arch/x86/include/arch/special.h
tools/objtool/arch/x86/include/cfi_regs.h tools/objtool/arch/x86/include/arch/cfi_regs.h
+2 -2
tools/objtool/arch/x86/special.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 #include <string.h> 3 3 4 - #include "../../special.h" 5 - #include "../../builtin.h" 4 + #include <objtool/special.h> 5 + #include <objtool/builtin.h> 6 6 7 7 #define X86_FEATURE_POPCNT (4 * 32 + 23) 8 8 #define X86_FEATURE_SMAP (9 * 32 + 20)
+2 -2
tools/objtool/builtin-check.c
··· 15 15 16 16 #include <subcmd/parse-options.h> 17 17 #include <string.h> 18 - #include "builtin.h" 19 - #include "objtool.h" 18 + #include <objtool/builtin.h> 19 + #include <objtool/objtool.h> 20 20 21 21 bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, validate_dup, vmlinux; 22 22
+2 -2
tools/objtool/builtin-orc.c
··· 13 13 */ 14 14 15 15 #include <string.h> 16 - #include "builtin.h" 17 - #include "objtool.h" 16 + #include <objtool/builtin.h> 17 + #include <objtool/objtool.h> 18 18 19 19 static const char *orc_usage[] = { 20 20 "objtool orc generate [<options>] file.o",
tools/objtool/builtin.h tools/objtool/include/objtool/builtin.h
+1 -1
tools/objtool/cfi.h tools/objtool/include/objtool/cfi.h
··· 6 6 #ifndef _OBJTOOL_CFI_H 7 7 #define _OBJTOOL_CFI_H 8 8 9 - #include "cfi_regs.h" 9 + #include <arch/cfi_regs.h> 10 10 11 11 #define CFI_UNDEFINED -1 12 12 #define CFI_CFA -2
+8 -8
tools/objtool/check.c
··· 6 6 #include <string.h> 7 7 #include <stdlib.h> 8 8 9 - #include "builtin.h" 10 - #include "cfi.h" 11 - #include "arch.h" 12 - #include "check.h" 13 - #include "special.h" 14 - #include "warn.h" 15 - #include "arch_elf.h" 16 - #include "endianness.h" 9 + #include <arch/elf.h> 10 + #include <objtool/builtin.h> 11 + #include <objtool/cfi.h> 12 + #include <objtool/arch.h> 13 + #include <objtool/check.h> 14 + #include <objtool/special.h> 15 + #include <objtool/warn.h> 16 + #include <objtool/endianness.h> 17 17 18 18 #include <linux/objtool.h> 19 19 #include <linux/hashtable.h>
+2 -2
tools/objtool/check.h tools/objtool/include/objtool/check.h
··· 7 7 #define _CHECK_H 8 8 9 9 #include <stdbool.h> 10 - #include "cfi.h" 11 - #include "arch.h" 10 + #include <objtool/cfi.h> 11 + #include <objtool/arch.h> 12 12 13 13 struct insn_state { 14 14 struct cfi_state cfi;
+3 -3
tools/objtool/elf.c
··· 15 15 #include <string.h> 16 16 #include <unistd.h> 17 17 #include <errno.h> 18 - #include "builtin.h" 18 + #include <objtool/builtin.h> 19 19 20 - #include "elf.h" 21 - #include "warn.h" 20 + #include <objtool/elf.h> 21 + #include <objtool/warn.h> 22 22 23 23 #define MAX_NAME_LEN 128 24 24
tools/objtool/elf.h tools/objtool/include/objtool/elf.h
+1 -1
tools/objtool/endianness.h tools/objtool/include/objtool/endianness.h
··· 2 2 #ifndef _OBJTOOL_ENDIANNESS_H 3 3 #define _OBJTOOL_ENDIANNESS_H 4 4 5 + #include <arch/endianness.h> 5 6 #include <linux/kernel.h> 6 7 #include <endian.h> 7 - #include "arch_endianness.h" 8 8 9 9 #ifndef __TARGET_BYTE_ORDER 10 10 #error undefined arch __TARGET_BYTE_ORDER
+3 -3
tools/objtool/objtool.c
··· 21 21 #include <subcmd/pager.h> 22 22 #include <linux/kernel.h> 23 23 24 - #include "builtin.h" 25 - #include "objtool.h" 26 - #include "warn.h" 24 + #include <objtool/builtin.h> 25 + #include <objtool/objtool.h> 26 + #include <objtool/warn.h> 27 27 28 28 struct cmd_struct { 29 29 const char *name;
+1 -1
tools/objtool/objtool.h tools/objtool/include/objtool/objtool.h
··· 10 10 #include <linux/list.h> 11 11 #include <linux/hashtable.h> 12 12 13 - #include "elf.h" 13 + #include <objtool/elf.h> 14 14 15 15 #define __weak __attribute__((weak)) 16 16
+3 -3
tools/objtool/orc_dump.c
··· 6 6 #include <unistd.h> 7 7 #include <linux/objtool.h> 8 8 #include <asm/orc_types.h> 9 - #include "objtool.h" 10 - #include "warn.h" 11 - #include "endianness.h" 9 + #include <objtool/objtool.h> 10 + #include <objtool/warn.h> 11 + #include <objtool/endianness.h> 12 12 13 13 static const char *reg_name(unsigned int reg) 14 14 {
+3 -3
tools/objtool/orc_gen.c
··· 9 9 #include <linux/objtool.h> 10 10 #include <asm/orc_types.h> 11 11 12 - #include "check.h" 13 - #include "warn.h" 14 - #include "endianness.h" 12 + #include <objtool/check.h> 13 + #include <objtool/warn.h> 14 + #include <objtool/endianness.h> 15 15 16 16 int create_orc(struct objtool_file *file) 17 17 {
+5 -5
tools/objtool/special.c
··· 11 11 #include <stdlib.h> 12 12 #include <string.h> 13 13 14 - #include "builtin.h" 15 - #include "special.h" 16 - #include "warn.h" 17 - #include "arch_special.h" 18 - #include "endianness.h" 14 + #include <arch/special.h> 15 + #include <objtool/builtin.h> 16 + #include <objtool/special.h> 17 + #include <objtool/warn.h> 18 + #include <objtool/endianness.h> 19 19 20 20 struct special_entry { 21 21 const char *sec;
+2 -2
tools/objtool/special.h tools/objtool/include/objtool/special.h
··· 7 7 #define _SPECIAL_H 8 8 9 9 #include <stdbool.h> 10 - #include "check.h" 11 - #include "elf.h" 10 + #include <objtool/check.h> 11 + #include <objtool/elf.h> 12 12 13 13 #define C_JUMP_TABLE_SECTION ".rodata..c_jump_table" 14 14
+1 -1
tools/objtool/warn.h tools/objtool/include/objtool/warn.h
··· 11 11 #include <sys/types.h> 12 12 #include <sys/stat.h> 13 13 #include <fcntl.h> 14 - #include "elf.h" 14 + #include <objtool/elf.h> 15 15 16 16 extern const char *objname; 17 17
+1 -1
tools/objtool/weak.c
··· 7 7 8 8 #include <stdbool.h> 9 9 #include <errno.h> 10 - #include "objtool.h" 10 + #include <objtool/objtool.h> 11 11 12 12 #define UNSUPPORTED(name) \ 13 13 ({ \