xref: /linux-6.15/arch/powerpc/Makefile (revision 22db99d6)
1# This file is included by the global makefile so that you can add your own
2# architecture-specific flags and dependencies.
3#
4# This file is subject to the terms and conditions of the GNU General Public
5# License.  See the file "COPYING" in the main directory of this archive
6# for more details.
7#
8# Copyright (C) 1994 by Linus Torvalds
9# Changes for PPC by Gary Thomas
10# Rewritten by Cort Dougan and Paul Mackerras
11#
12
13HAS_BIARCH	:= $(call cc-option-yn, -m32)
14
15# Set default 32 bits cross compilers for vdso and boot wrapper
16CROSS32_COMPILE ?=
17
18# If we're on a ppc/ppc64/ppc64le machine use that defconfig, otherwise just use
19# ppc64_defconfig because we have nothing better to go on.
20uname := $(shell uname -m)
21KBUILD_DEFCONFIG := $(if $(filter ppc%,$(uname)),$(uname),ppc64)_defconfig
22
23new_nm := $(shell if $(NM) --help 2>&1 | grep -- '--synthetic' > /dev/null; then echo y; else echo n; fi)
24
25ifeq ($(new_nm),y)
26NM		:= $(NM) --synthetic
27endif
28
29# BITS is used as extension for files which are available in a 32 bit
30# and a 64 bit version to simplify shared Makefiles.
31# e.g.: obj-y += foo_$(BITS).o
32export BITS
33
34ifdef CONFIG_PPC64
35        BITS := 64
36else
37        BITS := 32
38endif
39
40machine-y = ppc
41machine-$(CONFIG_PPC64) += 64
42machine-$(CONFIG_CPU_LITTLE_ENDIAN) += le
43UTS_MACHINE := $(subst $(space),,$(machine-y))
44
45# XXX This needs to be before we override LD below
46ifdef CONFIG_PPC32
47KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
48else
49ifeq ($(call ld-ifversion, -ge, 22500, y),y)
50# Have the linker provide sfpr if possible.
51# There is a corresponding test in arch/powerpc/lib/Makefile
52KBUILD_LDFLAGS_MODULE += --save-restore-funcs
53else
54KBUILD_LDFLAGS_MODULE += arch/powerpc/lib/crtsavres.o
55endif
56endif
57
58ifdef CONFIG_CPU_LITTLE_ENDIAN
59KBUILD_CFLAGS	+= -mlittle-endian
60KBUILD_LDFLAGS	+= -EL
61LDEMULATION	:= lppc
62GNUTARGET	:= powerpcle
63MULTIPLEWORD	:= -mno-multiple
64KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
65else
66KBUILD_CFLAGS += $(call cc-option,-mbig-endian)
67KBUILD_LDFLAGS	+= -EB
68LDEMULATION	:= ppc
69GNUTARGET	:= powerpc
70MULTIPLEWORD	:= -mmultiple
71endif
72
73ifdef CONFIG_PPC64
74ifndef CONFIG_CC_IS_CLANG
75cflags-$(CONFIG_PPC64_ELF_ABI_V1)	+= $(call cc-option,-mabi=elfv1)
76cflags-$(CONFIG_PPC64_ELF_ABI_V1)	+= $(call cc-option,-mcall-aixdesc)
77aflags-$(CONFIG_PPC64_ELF_ABI_V1)	+= $(call cc-option,-mabi=elfv1)
78aflags-$(CONFIG_PPC64_ELF_ABI_V2)	+= -mabi=elfv2
79endif
80endif
81
82ifndef CONFIG_CC_IS_CLANG
83  cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mno-strict-align
84endif
85
86cflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(call cc-option,-mbig-endian)
87cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mlittle-endian
88aflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(call cc-option,-mbig-endian)
89aflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mlittle-endian
90
91ifeq ($(HAS_BIARCH),y)
92KBUILD_CFLAGS	+= -m$(BITS)
93KBUILD_AFLAGS	+= -m$(BITS)
94KBUILD_LDFLAGS	+= -m elf$(BITS)$(LDEMULATION)
95endif
96
97cflags-$(CONFIG_STACKPROTECTOR)	+= -mstack-protector-guard=tls
98ifdef CONFIG_PPC64
99cflags-$(CONFIG_STACKPROTECTOR)	+= -mstack-protector-guard-reg=r13
100else
101cflags-$(CONFIG_STACKPROTECTOR)	+= -mstack-protector-guard-reg=r2
102endif
103
104LDFLAGS_vmlinux-y := -Bstatic
105LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
106LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) += -z notext
107LDFLAGS_vmlinux	:= $(LDFLAGS_vmlinux-y)
108
109ifdef CONFIG_PPC64
110ifndef CONFIG_PPC_KERNEL_PCREL
111ifeq ($(call cc-option-yn,-mcmodel=medium),y)
112	# -mcmodel=medium breaks modules because it uses 32bit offsets from
113	# the TOC pointer to create pointers where possible. Pointers into the
114	# percpu data area are created by this method.
115	#
116	# The kernel module loader relocates the percpu data section from the
117	# original location (starting with 0xd...) to somewhere in the base
118	# kernel percpu data space (starting with 0xc...). We need a full
119	# 64bit relocation for this to work, hence -mcmodel=large.
120	KBUILD_CFLAGS_MODULE += -mcmodel=large
121else
122	export NO_MINIMAL_TOC := -mno-minimal-toc
123endif
124endif
125endif
126
127CFLAGS-$(CONFIG_PPC64)	:= $(call cc-option,-mtraceback=no)
128ifdef CONFIG_PPC64_ELF_ABI_V2
129CFLAGS-$(CONFIG_PPC64)	+= $(call cc-option,-mabi=elfv2,$(call cc-option,-mcall-aixdesc))
130else
131ifndef CONFIG_CC_IS_CLANG
132CFLAGS-$(CONFIG_PPC64)	+= $(call cc-option,-mabi=elfv1)
133CFLAGS-$(CONFIG_PPC64)	+= $(call cc-option,-mcall-aixdesc)
134endif
135endif
136CFLAGS-$(CONFIG_PPC64)	+= $(call cc-option,-mcmodel=medium,$(call cc-option,-mminimal-toc))
137CFLAGS-$(CONFIG_PPC64)	+= $(call cc-option,-mno-pointers-to-nested-functions)
138CFLAGS-$(CONFIG_PPC64)	+= $(call cc-option,-mlong-double-128)
139
140# Clang unconditionally reserves r2 on ppc32 and does not support the flag
141# https://bugs.llvm.org/show_bug.cgi?id=39555
142CFLAGS-$(CONFIG_PPC32)	:= $(call cc-option, -ffixed-r2)
143
144# Clang doesn't support -mmultiple / -mno-multiple
145# https://bugs.llvm.org/show_bug.cgi?id=39556
146CFLAGS-$(CONFIG_PPC32)	+= $(call cc-option, $(MULTIPLEWORD))
147
148CFLAGS-$(CONFIG_PPC32)	+= $(call cc-option,-mno-readonly-in-sdata)
149
150ifdef CONFIG_FUNCTION_TRACER
151CC_FLAGS_FTRACE := -pg
152ifdef CONFIG_MPROFILE_KERNEL
153CC_FLAGS_FTRACE += -mprofile-kernel
154endif
155endif
156
157CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += -mcpu=$(CONFIG_TARGET_CPU)
158AFLAGS-$(CONFIG_TARGET_CPU_BOOL) += -mcpu=$(CONFIG_TARGET_CPU)
159
160CFLAGS-$(CONFIG_POWERPC64_CPU) += $(call cc-option,-mtune=power10,	\
161				  $(call cc-option,-mtune=power9,	\
162				  $(call cc-option,-mtune=power8)))
163
164asinstr := $(call as-instr,lis 9$(comma)foo@high,-DHAVE_AS_ATHIGH=1)
165
166KBUILD_CPPFLAGS	+= -I $(srctree)/arch/$(ARCH) $(asinstr)
167KBUILD_AFLAGS	+= $(AFLAGS-y)
168KBUILD_CFLAGS	+= $(call cc-option,-msoft-float)
169KBUILD_CFLAGS	+= -pipe $(CFLAGS-y)
170CPP		= $(CC) -E $(KBUILD_CFLAGS)
171
172CHECKFLAGS	+= -m$(BITS) -D__powerpc__ -D__powerpc$(BITS)__
173ifdef CONFIG_CPU_BIG_ENDIAN
174CHECKFLAGS	+= -D__BIG_ENDIAN__
175else
176CHECKFLAGS	+= -D__LITTLE_ENDIAN__
177endif
178
179ifdef CONFIG_476FPE_ERR46
180	KBUILD_LDFLAGS_MODULE += --ppc476-workaround \
181		-T $(srctree)/arch/powerpc/platforms/44x/ppc476_modules.lds
182endif
183
184# No prefix or pcrel
185ifdef CONFIG_PPC_KERNEL_PREFIXED
186KBUILD_CFLAGS += $(call cc-option,-mprefixed)
187else
188KBUILD_CFLAGS += $(call cc-option,-mno-prefixed)
189endif
190ifdef CONFIG_PPC_KERNEL_PCREL
191KBUILD_CFLAGS += $(call cc-option,-mpcrel)
192else
193KBUILD_CFLAGS += $(call cc-option,-mno-pcrel)
194endif
195
196# No AltiVec or VSX or MMA instructions when building kernel
197KBUILD_CFLAGS += $(call cc-option,-mno-altivec)
198KBUILD_CFLAGS += $(call cc-option,-mno-vsx)
199KBUILD_CFLAGS += $(call cc-option,-mno-mma)
200
201# No SPE instruction when building kernel
202# (We use all available options to help semi-broken compilers)
203KBUILD_CFLAGS += $(call cc-option,-mno-spe)
204KBUILD_CFLAGS += $(call cc-option,-mspe=no)
205
206# Don't emit .eh_frame since we have no use for it
207KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
208
209# Never use string load/store instructions as they are
210# often slow when they are implemented at all
211KBUILD_CFLAGS		+= $(call cc-option,-mno-string)
212
213cpu-as-$(CONFIG_ALTIVEC)	+= $(call as-option,-Wa$(comma)-maltivec)
214
215# When using '-many -mpower4' gas will first try and find a matching power4
216# mnemonic and failing that it will allow any valid mnemonic that GAS knows
217# about. GCC will pass -many to GAS when assembling, clang does not.
218# LLVM IAS doesn't understand either flag: https://github.com/ClangBuiltLinux/linux/issues/675
219# but LLVM IAS only supports ISA >= 2.06 for Book3S 64 anyway...
220cpu-as-$(CONFIG_PPC_BOOK3S_64)	+= $(call as-option,-Wa$(comma)-mpower4) $(call as-option,-Wa$(comma)-many)
221
222KBUILD_AFLAGS += $(cpu-as-y)
223KBUILD_CFLAGS += $(cpu-as-y)
224
225KBUILD_AFLAGS += $(aflags-y)
226KBUILD_CFLAGS += $(cflags-y)
227
228# Default to zImage, override when needed
229all: zImage
230
231# With make 3.82 we cannot mix normal and wildcard targets
232BOOT_TARGETS1 := zImage zImage.initrd uImage
233BOOT_TARGETS2 := zImage% dtbImage% treeImage.% cuImage.% simpleImage.% uImage.%
234
235PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2)
236
237boot := arch/$(ARCH)/boot
238
239$(BOOT_TARGETS1): vmlinux
240	$(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
241$(BOOT_TARGETS2): vmlinux
242	$(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
243
244
245PHONY += bootwrapper_install
246bootwrapper_install:
247	$(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
248
249include $(srctree)/scripts/Makefile.defconf
250
251generated_configs += pseries_le_defconfig
252pseries_le_defconfig:
253	$(call merge_into_defconfig,pseries_defconfig,le)
254
255generated_configs += ppc64le_defconfig
256ppc64le_defconfig:
257	$(call merge_into_defconfig,ppc64_defconfig,le)
258
259generated_configs += ppc64le_guest_defconfig
260ppc64le_guest_defconfig:
261	$(call merge_into_defconfig,ppc64_defconfig,le guest)
262
263generated_configs += ppc64_guest_defconfig
264ppc64_guest_defconfig:
265	$(call merge_into_defconfig,ppc64_defconfig,be guest)
266
267generated_configs += powernv_be_defconfig
268powernv_be_defconfig:
269	$(call merge_into_defconfig,powernv_defconfig,be)
270
271generated_configs += mpc85xx_defconfig
272mpc85xx_defconfig:
273	$(call merge_into_defconfig,mpc85xx_base.config,\
274		85xx-32bit 85xx-hw fsl-emb-nonhw)
275
276generated_configs += mpc85xx_smp_defconfig
277mpc85xx_smp_defconfig:
278	$(call merge_into_defconfig,mpc85xx_base.config,\
279		85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw)
280
281generated_configs += corenet32_smp_defconfig
282corenet32_smp_defconfig:
283	$(call merge_into_defconfig,corenet_base.config,\
284		85xx-32bit 85xx-smp 85xx-hw fsl-emb-nonhw dpaa)
285
286generated_configs += corenet64_smp_defconfig
287corenet64_smp_defconfig:
288	$(call merge_into_defconfig,corenet_base.config,\
289		85xx-64bit 85xx-smp altivec 85xx-hw fsl-emb-nonhw dpaa)
290
291generated_configs += mpc86xx_defconfig
292mpc86xx_defconfig:
293	$(call merge_into_defconfig,mpc86xx_base.config,\
294		86xx-hw fsl-emb-nonhw)
295
296generated_configs += mpc86xx_smp_defconfig
297mpc86xx_smp_defconfig:
298	$(call merge_into_defconfig,mpc86xx_base.config,\
299		86xx-smp 86xx-hw fsl-emb-nonhw)
300
301generated_configs += ppc32_allmodconfig
302ppc32_allmodconfig:
303	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/book3s_32.config \
304		-f $(srctree)/Makefile allmodconfig
305
306generated_configs += ppc_defconfig
307ppc_defconfig:
308	$(call merge_into_defconfig,book3s_32.config,)
309
310generated_configs += ppc64le_allmodconfig
311ppc64le_allmodconfig:
312	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/le.config \
313		-f $(srctree)/Makefile allmodconfig
314
315generated_configs += ppc64le_allnoconfig
316ppc64le_allnoconfig:
317	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/ppc64le.config \
318		-f $(srctree)/Makefile allnoconfig
319
320generated_configs += ppc64_book3e_allmodconfig
321ppc64_book3e_allmodconfig:
322	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/85xx-64bit.config \
323		-f $(srctree)/Makefile allmodconfig
324
325generated_configs += ppc32_randconfig
326ppc32_randconfig:
327	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/32-bit.config \
328		-f $(srctree)/Makefile randconfig
329
330generated_configs += ppc64_randconfig
331ppc64_randconfig:
332	$(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/powerpc/configs/64-bit.config \
333		-f $(srctree)/Makefile randconfig
334
335PHONY += $(generated_configs)
336
337define archhelp
338  echo '* zImage          - Build default images selected by kernel config'
339  echo '  zImage.*        - Compressed kernel image (arch/$(ARCH)/boot/zImage.*)'
340  echo '  uImage          - U-Boot native image format'
341  echo '  cuImage.<dt>    - Backwards compatible U-Boot image for older'
342  echo '                    versions which do not support device trees'
343  echo '  dtbImage.<dt>   - zImage with an embedded device tree blob'
344  echo '  simpleImage.<dt> - Firmware independent image.'
345  echo '  treeImage.<dt>  - Support for older IBM 4xx firmware (not U-Boot)'
346  echo '  install         - Install kernel using'
347  echo '                    (your) ~/bin/$(INSTALLKERNEL) or'
348  echo '                    (distribution) /sbin/$(INSTALLKERNEL) or'
349  echo '                    install to $$(INSTALL_PATH) and run lilo'
350  echo '  *_defconfig     - Select default config from arch/$(ARCH)/configs'
351  echo ''
352  echo '  Targets with <dt> embed a device tree blob inside the image'
353  echo '  These targets support board with firmware that does not'
354  echo '  support passing a device tree directly.  Replace <dt> with the'
355  echo '  name of a dts file from the arch/$(ARCH)/boot/dts/ directory'
356  echo '  (minus the .dts extension).'
357  echo
358  $(foreach cfg,$(generated_configs),
359    printf "  %-27s - Build for %s\\n" $(cfg) $(subst _defconfig,,$(cfg));)
360endef
361
362PHONY += install
363install:
364	$(call cmd,install)
365
366ifeq ($(KBUILD_EXTMOD),)
367# We need to generate vdso-offsets.h before compiling certain files in kernel/.
368# In order to do that, we should use the archprepare target, but we can't since
369# asm-offsets.h is included in some files used to generate vdso-offsets.h, and
370# asm-offsets.h is built in prepare0, for which archprepare is a dependency.
371# Therefore we need to generate the header after prepare0 has been made, hence
372# this hack.
373prepare: vdso_prepare
374vdso_prepare: prepare0
375	$(if $(CONFIG_VDSO32),$(Q)$(MAKE) \
376		$(build)=arch/powerpc/kernel/vdso include/generated/vdso32-offsets.h)
377	$(if $(CONFIG_PPC64),$(Q)$(MAKE) \
378		$(build)=arch/powerpc/kernel/vdso include/generated/vdso64-offsets.h)
379endif
380
381archprepare: checkbin
382
383archheaders:
384	$(Q)$(MAKE) $(build)=arch/powerpc/kernel/syscalls all
385
386ifdef CONFIG_STACKPROTECTOR
387prepare: stack_protector_prepare
388
389PHONY += stack_protector_prepare
390stack_protector_prepare: prepare0
391ifdef CONFIG_PPC64
392	$(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
393else
394	$(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
395endif
396endif
397
398PHONY += checkbin
399# Check toolchain versions:
400# - gcc-4.6 is the minimum kernel-wide version so nothing required.
401checkbin:
402	@if test "x${CONFIG_LD_IS_LLD}" != "xy" -a \
403		"x$(call ld-ifversion, -le, 22400, y)" = "xy" ; then \
404		echo -n '*** binutils 2.24 miscompiles weak symbols ' ; \
405		echo 'in some circumstances.' ; \
406		echo    '*** binutils 2.23 do not define the TOC symbol ' ; \
407		echo -n '*** Please use a different binutils version.' ; \
408		false ; \
409	fi
410