objtool: avoid ../ headers includes and name clashes
PATCH 1/1 objtool: avoid ../ headers includes and name clashes
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.
---
tools/objtool/.gitignore | 2 +-
tools/objtool/Makefile | 1 +
tools/objtool/arch/x86/decode.c | 8 ++++----
.../objtool/arch/x86/include/{ => arch}/cfi_regs.h | 0
.../arch/x86/include/{arch_elf.h => arch/elf.h} | 0
.../x86/include/{arch_special.h => arch/special.h} | 0
tools/objtool/arch/x86/special.c | 4 ++--
tools/objtool/builtin-check.c | 4 ++--
tools/objtool/builtin-orc.c | 4 ++--
tools/objtool/check.c | 14 +++++++-------
tools/objtool/elf.c | 6 +++---
tools/objtool/{ => include/objtool}/arch.h | 4 ++--
tools/objtool/{ => include/objtool}/builtin.h | 0
tools/objtool/{ => include/objtool}/cfi.h | 2 +-
tools/objtool/{ => include/objtool}/check.h | 4 ++--
tools/objtool/{ => include/objtool}/elf.h | 0
tools/objtool/{ => include/objtool}/objtool.h | 2 +-
tools/objtool/{ => include/objtool}/special.h | 4 ++--
tools/objtool/{ => include/objtool}/warn.h | 2 +-
tools/objtool/objtool.c | 6 +++---
tools/objtool/orc_dump.c | 4 ++--
tools/objtool/orc_gen.c | 4 ++--
tools/objtool/special.c | 8 ++++----
tools/objtool/weak.c | 2 +-
24 files changed, 43 insertions(+), 42 deletions(-)
rename tools/objtool/arch/x86/include/{ => arch}/cfi_regs.h (100%)
rename tools/objtool/arch/x86/include/{arch_elf.h => arch/elf.h} (100%)
rename tools/objtool/arch/x86/include/{arch_special.h => arch/special.h} (100%)
rename tools/objtool/{ => include/objtool}/arch.h (96%)
rename tools/objtool/{ => include/objtool}/builtin.h (100%)
rename tools/objtool/{ => include/objtool}/cfi.h (96%)
rename tools/objtool/{ => include/objtool}/check.h (96%)
rename tools/objtool/{ => include/objtool}/elf.h (100%)
rename tools/objtool/{ => include/objtool}/objtool.h (96%)
rename tools/objtool/{ => include/objtool}/special.h (94%)
rename tools/objtool/{ => include/objtool}/warn.h (98%)tools/objtool/.gitignore +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only arch/x86/lib/inat-tables.c -objtool +/objtool fixdep
tools/objtool/Makefile +1 -0
@@ -36,6 +36,7 @@ all: $(OBJTOOL) INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ + -I$(srctree)/tools/objtool/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
tools/objtool/arch/x86/decode.c +4 -4
@@ -11,11 +11,11 @@#include "../../../arch/x86/lib/inat.c" #include "../../../arch/x86/lib/insn.c" -#include "../../check.h" -#include "../../elf.h" -#include "../../arch.h" -#include "../../warn.h" #include <asm/orc_types.h> +#include <objtool/check.h> +#include <objtool/elf.h> +#include <objtool/arch.h> +#include <objtool/warn.h> static unsigned char op_to_cfi_reg[][2 ] = { {CFI_AX ,CFI_R8 },
tools/objtool/arch/x86/include/arch/cfi_regs.h renamed from tools/objtool/arch/x86/include/cfi_regs.h +0 -0
tools/objtool/arch/x86/include/arch/elf.h renamed from tools/objtool/arch/x86/include/arch_elf.h +0 -0
tools/objtool/arch/x86/include/arch/special.h renamed from tools/objtool/arch/x86/include/arch_special.h +0 -0
tools/objtool/arch/x86/special.c +2 -2
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0-or-later #include <string.h> -#include "../../special.h" -#include "../../builtin.h" +#include <objtool/special.h> +#include <objtool/builtin.h> #define X86_FEATURE_POPCNT (4 * 32 + 23)#define X86_FEATURE_SMAP (9 * 32 + 20)
tools/objtool/builtin-check.c +2 -2
@@ -15,8 +15,8 @@#include <subcmd/parse-options.h> #include <string.h> -#include "builtin.h" -#include "objtool.h" +#include <objtool/builtin.h> +#include <objtool/objtool.h> bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, validate_dup, vmlinux;
tools/objtool/builtin-orc.c +2 -2
@@ -13,8 +13,8 @@*/ #include <string.h> -#include "builtin.h" -#include "objtool.h" +#include <objtool/builtin.h> +#include <objtool/objtool.h> static const char *orc_usage[] = {"objtool orc generate [<options>] file.o" ,
tools/objtool/check.c +7 -7
@@ -6,13 +6,13 @@#include <string.h> #include <stdlib.h> -#include "builtin.h" -#include "cfi.h" -#include "arch.h" -#include "check.h" -#include "special.h" -#include "warn.h" -#include "arch_elf.h" +#include <arch/elf.h> +#include <objtool/builtin.h> +#include <objtool/cfi.h> +#include <objtool/arch.h> +#include <objtool/check.h> +#include <objtool/special.h> +#include <objtool/warn.h> #include <linux/objtool.h> #include <linux/hashtable.h>
tools/objtool/elf.c +3 -3
@@ -15,10 +15,10 @@#include <string.h> #include <unistd.h> #include <errno.h> -#include "builtin.h" +#include <objtool/builtin.h> -#include "elf.h" -#include "warn.h" +#include <objtool/elf.h> +#include <objtool/warn.h> #define MAX_NAME_LEN 128
tools/objtool/include/objtool/arch.h renamed from tools/objtool/arch.h +2 -2
@@ -8,8 +8,8 @@#include <stdbool.h> #include <linux/list.h> -#include "objtool.h" -#include "cfi.h" +#include <objtool/objtool.h> +#include <objtool/cfi.h> #ifdef INSN_USE_ORC #include <asm/orc_types.h>
tools/objtool/include/objtool/builtin.h renamed from tools/objtool/builtin.h +0 -0
tools/objtool/include/objtool/cfi.h renamed from tools/objtool/cfi.h +1 -1
@@ -6,7 +6,7 @@#ifndef _OBJTOOL_CFI_H#define _OBJTOOL_CFI_H -#include "cfi_regs.h" +#include <arch/cfi_regs.h> #define CFI_UNDEFINED -1#define CFI_CFA -2
tools/objtool/include/objtool/check.h renamed from tools/objtool/check.h +2 -2
@@ -7,8 +7,8 @@#define _CHECK_H#include <stdbool.h> -#include "cfi.h" -#include "arch.h" +#include <objtool/cfi.h> +#include <objtool/arch.h> struct insn_state {struct cfi_state cfi;
tools/objtool/include/objtool/elf.h renamed from tools/objtool/elf.h +0 -0
tools/objtool/include/objtool/objtool.h renamed from tools/objtool/objtool.h +1 -1
@@ -10,7 +10,7 @@#include <linux/list.h> #include <linux/hashtable.h> -#include "elf.h" +#include <objtool/elf.h> #define __weak __attribute__((weak))
tools/objtool/include/objtool/special.h renamed from tools/objtool/special.h +2 -2
@@ -7,8 +7,8 @@#define _SPECIAL_H#include <stdbool.h> -#include "check.h" -#include "elf.h" +#include <objtool/check.h> +#include <objtool/elf.h> #define C_JUMP_TABLE_SECTION ".rodata..c_jump_table"
tools/objtool/include/objtool/warn.h renamed from tools/objtool/warn.h +1 -1
@@ -11,7 +11,7 @@#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include "elf.h" +#include <objtool/elf.h> extern const char *objname;
tools/objtool/objtool.c +3 -3
@@ -21,9 +21,9 @@#include <subcmd/pager.h> #include <linux/kernel.h> -#include "builtin.h" -#include "objtool.h" -#include "warn.h" +#include <objtool/builtin.h> +#include <objtool/objtool.h> +#include <objtool/warn.h> struct cmd_struct {const char *name;
tools/objtool/orc_dump.c +2 -2
@@ -6,8 +6,8 @@#include <unistd.h> #include <linux/objtool.h> #include <asm/orc_types.h> -#include "objtool.h" -#include "warn.h" +#include <objtool/objtool.h> +#include <objtool/warn.h> static const char *reg_name (unsigned int reg) {
tools/objtool/orc_gen.c +2 -2
@@ -9,8 +9,8 @@#include <linux/objtool.h> #include <asm/orc_types.h> -#include "check.h" -#include "warn.h" +#include <objtool/check.h> +#include <objtool/warn.h> int create_orc (struct objtool_file *file) {
tools/objtool/special.c +4 -4
@@ -11,10 +11,10 @@#include <stdlib.h> #include <string.h> -#include "builtin.h" -#include "special.h" -#include "warn.h" -#include "arch_special.h" +#include <arch/special.h> +#include <objtool/builtin.h> +#include <objtool/special.h> +#include <objtool/warn.h> struct special_entry {const char *sec;
tools/objtool/weak.c +1 -1
@@ -7,7 +7,7 @@#include <stdbool.h> #include <errno.h> -#include "objtool.h" +#include <objtool/objtool.h> #define UNSUPPORTED (name) \ ({ \
Signature · 6 lines
⣿⣿⣿⣿⢋⡀⣀⠹⣿⣿⣿⣿ ⣿⣿⣿⣿⠠⣶⡦⠀⣿⣿⣿⣿ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
Quoted 4 lines · Vasily Gorbik
Doesn't this make it instantly obvious where are these files come from?
#include <
objtool/warn.h>
#include <arch/elf.h>
Indeed, this is a lot better! If I'm not mistaken, this conflicts with your other series. Would you mind rebasing this on top of the others?
Signature · 1 line
Josh