Debian Codegraph @

arch/loongarch/Makefile

raw symbols SCIP
1 # SPDX-License-Identifier: GPL-2.0
2 #
3 # Author: Huacai Chen <[email protected]>
4 # Copyright (C) 2020-2022 Loongson Technology Corporation Limited
5
6 boot := arch/loongarch/boot
7
8 ifeq ($(shell uname -m),loongarch32)
9 KBUILD_DEFCONFIG := loongson32_defconfig
10 else
11 KBUILD_DEFCONFIG := loongson64_defconfig
12 endif
13
14 KBUILD_DTBS := dtbs
15
16 image-name-y := vmlinux
17 image-name-$(CONFIG_EFI_ZBOOT) := vmlinuz
18
19 ifndef CONFIG_EFI_STUB
20 KBUILD_IMAGE := $(boot)/vmlinux.elf
21 else
22 KBUILD_IMAGE := $(boot)/$(image-name-y).efi
23 endif
24
25 #
26 # Select the object file format to substitute into the linker script.
27 #
28 32bit-tool-archpref = loongarch32
29 64bit-tool-archpref = loongarch64
30 32bit-bfd = elf32-loongarch
31 64bit-bfd = elf64-loongarch
32 32bit-emul = elf32loongarch
33 64bit-emul = elf64loongarch
34
35 CC_FLAGS_FPU := -mfpu=64
36 CC_FLAGS_NO_FPU := -msoft-float
37
38 ifdef CONFIG_UNWINDER_ORC
39 orc_hash_h := arch/$(SRCARCH)/include/generated/asm/orc_hash.h
40 orc_hash_sh := $(srctree)/scripts/orc_hash.sh
41 targets += $(orc_hash_h)
42 quiet_cmd_orc_hash = GEN $@
43 cmd_orc_hash = mkdir -p $(dir $@); \
44 $(CONFIG_SHELL) $(orc_hash_sh) < $< > $@
45 $(orc_hash_h): $(srctree)/arch/loongarch/include/asm/orc_types.h $(orc_hash_sh) FORCE
46 $(call if_changed,orc_hash)
47 archprepare: $(orc_hash_h)
48 endif
49
50 ifdef CONFIG_DYNAMIC_FTRACE
51 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
52 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
53 endif
54
55 ifdef CONFIG_32BIT
56 tool-archpref = $(32bit-tool-archpref)
57 UTS_MACHINE := loongarch32
58 cflags-y += $(call cc-option,-m32)
59 else
60 tool-archpref = $(64bit-tool-archpref)
61 UTS_MACHINE := loongarch64
62 cflags-y += $(call cc-option,-m64)
63 endif
64
65 ifneq ($(SUBARCH),$(ARCH))
66 ifeq ($(CROSS_COMPILE),)
67 CROSS_COMPILE := $(call cc-cross-prefix, $(tool-archpref)-linux- $(tool-archpref)-linux-gnu- $(tool-archpref)-unknown-linux-gnu-)
68 endif
69 endif
70
71 ifdef CONFIG_32BIT
72 ifdef CONFIG_32BIT_STANDARD
73 ld-emul = $(32bit-emul)
74 cflags-y += -march=la32v1.0 -mabi=ilp32s -mcmodel=normal
75 else # CONFIG_32BIT_REDUCED
76 ld-emul = $(32bit-emul)
77 cflags-y += -march=la32rv1.0 -mabi=ilp32s -mcmodel=normal
78 endif
79 endif
80
81 ifdef CONFIG_64BIT
82 ld-emul = $(64bit-emul)
83 cflags-y += -march=loongarch64 -mabi=lp64s -mcmodel=normal
84 endif
85
86 cflags-y += -pipe $(CC_FLAGS_NO_FPU)
87 LDFLAGS_vmlinux += -static -n -nostdlib
88
89 # When the assembler supports explicit relocation hint, we must use it.
90 # GCC may have -mexplicit-relocs off by default if it was built with an old
91 # assembler, so we force it via an option.
92 #
93 # When the assembler does not supports explicit relocation hint, we can't use
94 # it. Disable it if the compiler supports it.
95 #
96 # The combination of a "new" assembler and "old" GCC is not supported, given
97 # the rarity of this combo and the extra complexity needed to make it work.
98 # Either upgrade the compiler or downgrade the assembler; the build will error
99 # out if it is the case (by probing for the model attribute; all supported
100 # compilers in this case would have support).
101 #
102 # Also, -mdirect-extern-access is useful in case of building with explicit
103 # relocs, for avoiding unnecessary GOT accesses. It is harmless to not have
104 # support though.
105 ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
106 cflags-y += $(call cc-option,-mexplicit-relocs)
107 KBUILD_CFLAGS_KERNEL += $(call cc-option,-mdirect-extern-access)
108 KBUILD_CFLAGS_KERNEL += $(call cc-option,-fdirect-access-external-data)
109 KBUILD_AFLAGS_MODULE += $(call cc-option,-fno-direct-access-external-data)
110 KBUILD_CFLAGS_MODULE += $(call cc-option,-fno-direct-access-external-data)
111 else
112 cflags-y += $(call cc-option,-mno-explicit-relocs)
113 KBUILD_AFLAGS_KERNEL += -Wa,-mla-global-with-pcrel
114 KBUILD_CFLAGS_KERNEL += -Wa,-mla-global-with-pcrel
115 KBUILD_AFLAGS_MODULE += -Wa,-mla-global-with-abs
116 KBUILD_CFLAGS_MODULE += -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
117 endif
118
119 KBUILD_AFLAGS += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
120 KBUILD_CFLAGS += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
121 KBUILD_AFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
122 KBUILD_CFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
123
124 ifdef CONFIG_OBJTOOL
125 ifdef CONFIG_CC_HAS_ANNOTATE_TABLEJUMP
126 KBUILD_CFLAGS += -mannotate-tablejump
127 else
128 KBUILD_CFLAGS += -fno-jump-tables # keep compatibility with older compilers
129 endif
130 ifdef CONFIG_RUSTC_HAS_ANNOTATE_TABLEJUMP
131 KBUILD_RUSTFLAGS += -Cllvm-args=--loongarch-annotate-tablejump
132 else
133 KBUILD_RUSTFLAGS += $(if $(call rustc-min-version,109300),-Cjump-tables=n,-Zno-jump-tables) # keep compatibility with older compilers
134 endif
135 ifdef CONFIG_LTO_CLANG
136 # The annotate-tablejump option can not be passed to LLVM backend when LTO is enabled.
137 # Ensure it is aware of linker with LTO, '--loongarch-annotate-tablejump' also needs to
138 # be passed via '-mllvm' to ld.lld.
139 KBUILD_LDFLAGS += $(call ld-option,-mllvm --loongarch-annotate-tablejump)
140 endif
141 endif
142
143 KBUILD_RUSTFLAGS += --target=loongarch64-unknown-none-softfloat -Ccode-model=small
144 KBUILD_RUSTFLAGS_KERNEL += -Zdirect-access-external-data=yes
145 KBUILD_RUSTFLAGS_MODULE += -Zdirect-access-external-data=no
146
147 ifeq ($(CONFIG_RELOCATABLE),y)
148 KBUILD_CFLAGS_KERNEL += -fPIE
149 KBUILD_RUSTFLAGS_KERNEL += -Crelocation-model=pie
150 LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
151 endif
152
153 cflags-y += $(call cc-option, -mno-check-zero-division -fno-isolate-erroneous-paths-dereference)
154
155 ifndef CONFIG_KASAN
156 cflags-y += -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset
157 endif
158
159 ifdef CONFIG_32BIT
160 load-y = 0xa0200000
161 else
162 load-y = 0x9000000000200000
163 endif
164
165 bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y)
166
167 drivers-$(CONFIG_PCI) += arch/loongarch/pci/
168
169 KBUILD_AFLAGS += $(cflags-y)
170 KBUILD_CFLAGS += $(cflags-y)
171 KBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y)
172
173 # This is required to get dwarf unwinding tables into .debug_frame
174 # instead of .eh_frame so we don't discard them.
175 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
176
177 ifdef CONFIG_ARCH_STRICT_ALIGN
178 # Don't emit unaligned accesses.
179 # Not all LoongArch cores support unaligned access, and as kernel we can't
180 # rely on others to provide emulation for these accesses.
181 KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
182 else
183 # Optimise for performance on hardware supports unaligned access.
184 KBUILD_CFLAGS += $(call cc-option,-mno-strict-align)
185 endif
186
187 KBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)
188
189 KBUILD_LDFLAGS += -m $(ld-emul)
190
191 ifdef need-compiler
192 CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
193 grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
194 sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
195 endif
196
197 libs-y += arch/loongarch/lib/
198 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
199
200 drivers-y += arch/loongarch/crypto/
201
202 # suspend and hibernation support
203 drivers-$(CONFIG_PM) += arch/loongarch/power/
204
205 ifeq ($(KBUILD_EXTMOD),)
206 prepare: vdso_prepare
207 vdso_prepare: prepare0
208 $(Q)$(MAKE) $(build)=arch/loongarch/vdso include/generated/vdso-offsets.h
209 endif
210
211 vdso-install-y += arch/loongarch/vdso/vdso.so.dbg
212
213 all: $(notdir $(KBUILD_IMAGE)) $(KBUILD_DTBS)
214
215 vmlinuz.efi: vmlinux.efi
216
217 vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux
218 $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@
219
220 install:
221 $(call cmd,install)
222
223 define archhelp
224 echo ' vmlinux.elf - Uncompressed ELF kernel image (arch/loongarch/boot/vmlinux.elf)'
225 echo ' vmlinux.efi - Uncompressed EFI kernel image (arch/loongarch/boot/vmlinux.efi)'
226 echo ' vmlinuz.efi - GZIP/ZSTD-compressed EFI kernel image (arch/loongarch/boot/vmlinuz.efi)'
227 echo ' Default when CONFIG_EFI_ZBOOT=y'
228 echo ' install - Install kernel using (your) ~/bin/$(INSTALLKERNEL) or'
229 echo ' (distribution) /sbin/$(INSTALLKERNEL) or install.sh to $$(INSTALL_PATH)'
230 echo
231 endef