Debian Codegraph @

tools/objtool/Makefile

raw
1 # SPDX-License-Identifier: GPL-2.0
2 include ../scripts/Makefile.include
3 include ../scripts/Makefile.arch
4
5 ifeq ($(SRCARCH),x86)
6 BUILD_ORC := y
7 ARCH_HAS_KLP := y
8 endif
9
10 ifeq ($(SRCARCH),loongarch)
11 BUILD_ORC := y
12 endif
13
14 ifeq ($(ARCH_HAS_KLP),y)
15 HAVE_XXHASH = $(shell printf "$(pound)include <xxhash.h>\nXXH3_state_t *state;int main() {}" | \
16 $(HOSTCC) $(HOSTCFLAGS) -xc - -o /dev/null -lxxhash 2> /dev/null && echo y || echo n)
17 ifeq ($(HAVE_XXHASH),y)
18 BUILD_KLP := y
19 LIBXXHASH_CFLAGS := $(shell $(HOSTPKG_CONFIG) libxxhash --cflags 2>/dev/null) \
20 -DBUILD_KLP
21 LIBXXHASH_LIBS := $(shell $(HOSTPKG_CONFIG) libxxhash --libs 2>/dev/null || echo -lxxhash)
22 endif
23 endif
24
25 export BUILD_ORC BUILD_KLP
26
27 ifeq ($(srctree),)
28 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
29 srctree := $(patsubst %/,%,$(dir $(srctree)))
30 endif
31
32 RM ?= rm -f
33
34 LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
35 ifneq ($(OUTPUT),)
36 LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
37 else
38 LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
39 endif
40 LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
41
42 OBJTOOL := $(OUTPUT)objtool
43 OBJTOOL_IN := $(OBJTOOL)-in.o
44
45 LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
46 LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
47
48 all: $(OBJTOOL)
49
50 WARNINGS := -Werror -Wall -Wextra -Wmissing-prototypes \
51 -Wmissing-declarations -Wwrite-strings \
52 -Wno-implicit-fallthrough -Wno-sign-compare \
53 -Wno-unused-parameter
54
55 INCLUDES := -I$(srctree)/tools/include \
56 -I$(srctree)/tools/include/uapi \
57 -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
58 -I$(srctree)/tools/arch/$(SRCARCH)/include \
59 -I$(srctree)/tools/objtool/include \
60 -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
61 -I$(LIBSUBCMD_OUTPUT)/include
62
63 OBJTOOL_CFLAGS := -std=gnu11 -fomit-frame-pointer -O2 -g $(WARNINGS) \
64 $(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS)
65
66 OBJTOOL_LDFLAGS := $(LIBSUBCMD) $(LIBELF_LIBS) $(LIBXXHASH_LIBS) $(HOSTLDFLAGS)
67
68 # Allow old libelf to be used:
69 elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr)
70 OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
71
72 # Always want host compilation.
73 HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
74
75 #
76 # To support disassembly, objtool needs libopcodes which is provided
77 # with libbfd (binutils-dev or binutils-devel package).
78 #
79 # We check using HOSTCC directly rather than the shared feature framework
80 # because objtool is a host tool that links against host libraries.
81 #
82 # When using shared libraries, -lopcodes is sufficient as dependencies are
83 # resolved automatically. With static libraries, we must explicitly link
84 # against libopcodes' dependencies: libbfd, libiberty, and sometimes libz.
85 # Try each combination and use the first one that succeeds.
86 #
87 LIBOPCODES_LIBS := $(shell \
88 for libs in "-lopcodes" \
89 "-lopcodes -lbfd" \
90 "-lopcodes -lbfd -liberty" \
91 "-lopcodes -lbfd -liberty -lz"; do \
92 echo 'extern void disassemble_init_for_target(void *);' \
93 'int main(void) { disassemble_init_for_target(0); return 0; }' | \
94 $(HOSTCC) -xc - -o /dev/null $$libs 2>/dev/null && \
95 echo "$$libs" && break; \
96 done)
97
98 # Styled disassembler support requires binutils >= 2.39
99 HAVE_DISASM_STYLED := $(shell echo '$(pound)include <dis-asm.h>' | \
100 $(HOSTCC) -E -xc - 2>/dev/null | grep -q disassembler_style && echo y)
101
102 BUILD_DISAS := n
103
104 ifneq ($(LIBOPCODES_LIBS),)
105 BUILD_DISAS := y
106 OBJTOOL_CFLAGS += -DDISAS -DPACKAGE='"objtool"'
107 OBJTOOL_LDFLAGS += $(LIBOPCODES_LIBS)
108 ifeq ($(HAVE_DISASM_STYLED),y)
109 OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED
110 endif
111 endif
112
113 export BUILD_DISAS
114
115 AWK = awk
116 MKDIR = mkdir
117
118 export srctree OUTPUT CFLAGS SRCARCH AWK
119 include $(srctree)/tools/build/Makefile.include
120
121 $(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
122 $(Q)$(CONFIG_SHELL) ./sync-check.sh
123 $(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
124 LDFLAGS="$(OBJTOOL_LDFLAGS)"
125
126
127 $(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
128 $(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
129
130
131 $(LIBSUBCMD_OUTPUT):
132 $(Q)$(MKDIR) -p $@
133
134 $(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
135 $(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
136 DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
137 $(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
138 $@ install_headers
139
140 $(LIBSUBCMD)-clean:
141 $(call QUIET_CLEAN, libsubcmd)
142 $(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
143
144 clean: $(LIBSUBCMD)-clean
145 $(Q)find $(OUTPUT) \( -name '*.o' -o -name '\.*.cmd' -o -name '\.*.d' \) -type f -print | xargs $(RM)
146 $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep
147 $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
148 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool
149 $(Q)$(RM) -r -- $(OUTPUT)feature
150
151 mrproper: clean
152 $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
153
154 FORCE:
155
156 .PHONY: clean mrproper FORCE