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