Makefile.lib 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Finds the multi-part object the current object will be linked into.
  3. # If the object belongs to two or more multi-part objects, list them all.
  4. modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
  5. $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
  6. __modname = $(or $(modname-multi),$(basetarget))
  7. modname = $(subst $(space),:,$(__modname))
  8. modfile = $(addprefix $(obj)/,$(__modname))
  9. # target with $(obj)/ and its suffix stripped
  10. target-stem = $(basename $(patsubst $(obj)/%,%,$@))
  11. # These flags are needed for modversions and compiling, so we define them here
  12. # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
  13. # end up in (or would, if it gets compiled in)
  14. name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
  15. name-fix = $(call stringify,$(call name-fix-token,$1))
  16. basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
  17. modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
  18. -D__KBUILD_MODNAME=$(call name-fix-token,$(modname))
  19. modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))
  20. _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
  21. $(filter-out $(ccflags-remove-y), \
  22. $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
  23. $(CFLAGS_$(target-stem).o))
  24. _rust_flags = $(filter-out $(RUSTFLAGS_REMOVE_$(target-stem).o), \
  25. $(filter-out $(rustflags-remove-y), \
  26. $(KBUILD_RUSTFLAGS) $(rustflags-y)) \
  27. $(RUSTFLAGS_$(target-stem).o))
  28. _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
  29. $(filter-out $(asflags-remove-y), \
  30. $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
  31. $(AFLAGS_$(target-stem).o))
  32. _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
  33. #
  34. # Enable gcov profiling flags for a file, directory or for all files depending
  35. # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
  36. # (in this order)
  37. #
  38. ifeq ($(CONFIG_GCOV_KERNEL),y)
  39. _c_flags += $(if $(patsubst n%,, \
  40. $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(if $(is-kernel-object),$(CONFIG_GCOV_PROFILE_ALL))), \
  41. $(CFLAGS_GCOV))
  42. endif
  43. #
  44. # Enable address sanitizer flags for kernel except some files or directories
  45. # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
  46. #
  47. ifeq ($(CONFIG_KASAN),y)
  48. ifneq ($(CONFIG_KASAN_HW_TAGS),y)
  49. _c_flags += $(if $(patsubst n%,, \
  50. $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \
  51. $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
  52. _rust_flags += $(if $(patsubst n%,, \
  53. $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \
  54. $(RUSTFLAGS_KASAN))
  55. endif
  56. endif
  57. ifeq ($(CONFIG_KMSAN),y)
  58. _c_flags += $(if $(patsubst n%,, \
  59. $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)$(is-kernel-object)), \
  60. $(CFLAGS_KMSAN))
  61. _c_flags += $(if $(patsubst n%,, \
  62. $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)$(is-kernel-object)), \
  63. , -mllvm -msan-disable-checks=1)
  64. endif
  65. ifeq ($(CONFIG_UBSAN),y)
  66. _c_flags += $(if $(patsubst n%,, \
  67. $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(is-kernel-object)), \
  68. $(CFLAGS_UBSAN))
  69. _c_flags += $(if $(patsubst n%,, \
  70. $(UBSAN_INTEGER_WRAP_$(target-stem).o)$(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_INTEGER_WRAP)$(UBSAN_SANITIZE)$(is-kernel-object)), \
  71. $(CFLAGS_UBSAN_INTEGER_WRAP))
  72. endif
  73. ifeq ($(CONFIG_KCOV),y)
  74. _c_flags += $(if $(patsubst n%,, \
  75. $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \
  76. $(CFLAGS_KCOV))
  77. _rust_flags += $(if $(patsubst n%,, \
  78. $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \
  79. $(RUSTFLAGS_KCOV))
  80. endif
  81. #
  82. # Enable KCSAN flags except some files or directories we don't want to check
  83. # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
  84. #
  85. ifeq ($(CONFIG_KCSAN),y)
  86. _c_flags += $(if $(patsubst n%,, \
  87. $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)$(is-kernel-object)), \
  88. $(CFLAGS_KCSAN))
  89. # Some uninstrumented files provide implied barriers required to avoid false
  90. # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
  91. _c_flags += $(if $(patsubst n%,, \
  92. $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
  93. -D__KCSAN_INSTRUMENT_BARRIERS__)
  94. endif
  95. #
  96. # Enable context analysis flags only where explicitly opted in.
  97. # (depends on variables CONTEXT_ANALYSIS_obj.o, CONTEXT_ANALYSIS)
  98. #
  99. ifeq ($(CONFIG_WARN_CONTEXT_ANALYSIS),y)
  100. _c_flags += $(if $(patsubst n%,, \
  101. $(CONTEXT_ANALYSIS_$(target-stem).o)$(CONTEXT_ANALYSIS)$(if $(is-kernel-object),$(CONFIG_WARN_CONTEXT_ANALYSIS_ALL))), \
  102. $(CFLAGS_CONTEXT_ANALYSIS))
  103. endif
  104. #
  105. # Enable AutoFDO build flags except some files or directories we don't want to
  106. # enable (depends on variables AUTOFDO_PROFILE_obj.o and AUTOFDO_PROFILE).
  107. #
  108. ifeq ($(CONFIG_AUTOFDO_CLANG),y)
  109. _c_flags += $(if $(patsubst n%,, \
  110. $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object)), \
  111. $(CFLAGS_AUTOFDO_CLANG))
  112. endif
  113. #
  114. # Enable Propeller build flags except some files or directories we don't want to
  115. # enable (depends on variables AUTOFDO_PROPELLER_obj.o and PROPELLER_PROFILE).
  116. #
  117. ifdef CONFIG_PROPELLER_CLANG
  118. _c_flags += $(if $(patsubst n%,, \
  119. $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(PROPELLER_PROFILE))$(is-kernel-object), \
  120. $(CFLAGS_PROPELLER_CLANG))
  121. endif
  122. # $(src) for including checkin headers from generated source files
  123. # $(obj) for including generated headers from checkin source files
  124. ifdef building_out_of_srctree
  125. _c_flags += $(addprefix -I, $(src) $(obj))
  126. _a_flags += $(addprefix -I, $(src) $(obj))
  127. _cpp_flags += $(addprefix -I, $(src) $(obj))
  128. endif
  129. # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or modules
  130. is-kernel-object = $(or $(part-of-builtin),$(part-of-module))
  131. part-of-builtin = $(if $(filter $(basename $@).o, $(real-obj-y) $(lib-y)),y)
  132. part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
  133. quiet_modtag = $(if $(part-of-module),[M], )
  134. modkern_cflags = \
  135. $(if $(part-of-module), \
  136. $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
  137. $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
  138. modkern_rustflags = \
  139. $(if $(part-of-module), \
  140. $(KBUILD_RUSTFLAGS_MODULE) $(RUSTFLAGS_MODULE), \
  141. $(KBUILD_RUSTFLAGS_KERNEL) $(RUSTFLAGS_KERNEL))
  142. modkern_aflags = $(if $(part-of-module), \
  143. $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \
  144. $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) $(modfile_flags))
  145. c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  146. -include $(srctree)/include/linux/compiler_types.h \
  147. $(_c_flags) $(modkern_cflags) \
  148. $(basename_flags) $(modname_flags)
  149. rust_flags = $(_rust_flags) $(modkern_rustflags) @$(objtree)/include/generated/rustc_cfg
  150. a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  151. $(_a_flags) $(modkern_aflags) $(modname_flags)
  152. cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  153. $(_cpp_flags)
  154. ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
  155. ifdef CONFIG_OBJTOOL
  156. objtool := $(objtree)/tools/objtool/objtool
  157. objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) += --hacks=jump_label
  158. objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) += --hacks=noinstr
  159. objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) += --hacks=skylake
  160. objtool-args-$(CONFIG_X86_KERNEL_IBT) += --ibt
  161. objtool-args-$(CONFIG_FINEIBT) += --cfi
  162. objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL) += --mcount
  163. ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
  164. objtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT) += --mnop
  165. endif
  166. objtool-args-$(CONFIG_UNWINDER_ORC) += --orc
  167. objtool-args-$(CONFIG_MITIGATION_RETPOLINE) += --retpoline
  168. objtool-args-$(CONFIG_MITIGATION_RETHUNK) += --rethunk
  169. objtool-args-$(CONFIG_MITIGATION_SLS) += --sls
  170. objtool-args-$(CONFIG_STACK_VALIDATION) += --stackval
  171. objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call
  172. objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess
  173. objtool-args-$(or $(CONFIG_GCOV_KERNEL),$(CONFIG_KCOV)) += --no-unreachable
  174. objtool-args-$(CONFIG_PREFIX_SYMBOLS) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
  175. objtool-args-$(CONFIG_OBJTOOL_WERROR) += --werror
  176. objtool-args = $(objtool-args-y) \
  177. $(if $(delay-objtool), --link) \
  178. $(if $(part-of-module), --module)
  179. delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT),$(CONFIG_KLP_BUILD))
  180. cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
  181. cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
  182. objtool-enabled := y
  183. endif # CONFIG_OBJTOOL
  184. # Useful for describing the dependency of composite objects
  185. # Usage:
  186. # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
  187. define multi_depend
  188. $(foreach m, $1, \
  189. $(eval $m: \
  190. $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
  191. endef
  192. # Remove ".." and "." from a path, without using "realpath"
  193. # Usage:
  194. # $(call normalize_path,path/to/../file)
  195. define normalize_path
  196. $(strip $(eval elements :=) \
  197. $(foreach elem,$(subst /, ,$1), \
  198. $(if $(filter-out .,$(elem)), \
  199. $(if $(filter ..,$(elem)), \
  200. $(eval elements := $(wordlist 2,$(words $(elements)),x $(elements))), \
  201. $(eval elements := $(elements) $(elem))))) \
  202. $(subst $(space),/,$(elements)))
  203. endef
  204. # Build commands
  205. # ===========================================================================
  206. # These are shared by some Makefile.* files.
  207. ifdef CONFIG_LTO_CLANG
  208. # Run $(LD) here to convert LLVM IR to ELF in the following cases:
  209. # - when this object needs objtool processing, as objtool cannot process LLVM IR
  210. # - when this is a single-object module, as modpost cannot process LLVM IR
  211. cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
  212. endif
  213. quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
  214. cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
  215. $(cmd_ld_single) \
  216. $(cmd_objtool)
  217. define rule_cc_o_c
  218. $(call cmd_and_fixdep,cc_o_c)
  219. $(call cmd,checksrc)
  220. $(call cmd,checkdoc)
  221. $(call cmd,gen_objtooldep)
  222. $(call cmd,gen_symversions_c)
  223. $(call cmd,record_mcount)
  224. $(call cmd,warn_shared_object)
  225. endef
  226. quiet_cmd_as_o_S = AS $(quiet_modtag) $@
  227. cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
  228. define rule_as_o_S
  229. $(call cmd_and_fixdep,as_o_S)
  230. $(call cmd,gen_objtooldep)
  231. $(call cmd,gen_symversions_S)
  232. $(call cmd,warn_shared_object)
  233. endef
  234. # Copy a file
  235. # ===========================================================================
  236. # 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
  237. # the copy would be read-only as well, leading to an error when executing the
  238. # rule next time. Use 'cat' instead in order to generate a writable file.
  239. quiet_cmd_copy = COPY $@
  240. cmd_copy = cat $< > $@
  241. $(obj)/%: $(src)/%_shipped
  242. $(call cmd,copy)
  243. # Touch a file
  244. # ===========================================================================
  245. quiet_cmd_touch = TOUCH $(call normalize_path,$@)
  246. cmd_touch = touch $@
  247. # Commands useful for building a boot image
  248. # ===========================================================================
  249. #
  250. # Use as following:
  251. #
  252. # target: source(s) FORCE
  253. # $(if_changed,ld/objcopy/gzip)
  254. #
  255. # and add target to 'targets' so that we know we have to
  256. # read in the saved command line
  257. # Linking
  258. # ---------------------------------------------------------------------------
  259. quiet_cmd_ld = LD $@
  260. cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
  261. # Archive
  262. # ---------------------------------------------------------------------------
  263. quiet_cmd_ar = AR $@
  264. cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
  265. # Objcopy
  266. # ---------------------------------------------------------------------------
  267. quiet_cmd_objcopy = OBJCOPY $@
  268. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  269. # Gzip
  270. # ---------------------------------------------------------------------------
  271. quiet_cmd_gzip = GZIP $@
  272. cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
  273. # Bzip2
  274. # ---------------------------------------------------------------------------
  275. # Bzip2 and LZMA do not include size in file... so we have to fake that;
  276. # append the size as a 32-bit littleendian number as gzip does.
  277. size_append = printf $(shell \
  278. dec_size=0; \
  279. for F in $(real-prereqs); do \
  280. fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
  281. dec_size=$$(expr $$dec_size + $$fsize); \
  282. done; \
  283. printf "%08x\n" $$dec_size | \
  284. sed 's/\(..\)/\1 /g' | { \
  285. read ch0 ch1 ch2 ch3; \
  286. for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \
  287. printf '%s%03o' '\\' $$((0x$$ch)); \
  288. done; \
  289. } \
  290. )
  291. quiet_cmd_file_size = GEN $@
  292. cmd_file_size = $(size_append) > $@
  293. quiet_cmd_bzip2 = BZIP2 $@
  294. cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
  295. quiet_cmd_bzip2_with_size = BZIP2 $@
  296. cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
  297. # Lzma
  298. # ---------------------------------------------------------------------------
  299. quiet_cmd_lzma = LZMA $@
  300. cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
  301. quiet_cmd_lzma_with_size = LZMA $@
  302. cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
  303. quiet_cmd_lzo = LZO $@
  304. cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
  305. quiet_cmd_lzo_with_size = LZO $@
  306. cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
  307. quiet_cmd_lz4 = LZ4 $@
  308. cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -9 - - > $@
  309. quiet_cmd_lz4_with_size = LZ4 $@
  310. cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -9 - -; \
  311. $(size_append); } > $@
  312. # U-Boot mkimage
  313. # ---------------------------------------------------------------------------
  314. MKIMAGE := $(srctree)/scripts/mkuboot.sh
  315. # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
  316. # the number of overrides in arch makefiles
  317. UIMAGE_ARCH ?= $(SRCARCH)
  318. UIMAGE_COMPRESSION ?= $(or $(2),none)
  319. UIMAGE_OPTS-y ?=
  320. UIMAGE_TYPE ?= kernel
  321. UIMAGE_LOADADDR ?= arch_must_set_this
  322. UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
  323. UIMAGE_NAME ?= Linux-$(KERNELRELEASE)
  324. quiet_cmd_uimage = UIMAGE $@
  325. cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
  326. -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
  327. -T $(UIMAGE_TYPE) \
  328. -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
  329. -n '$(UIMAGE_NAME)' -d $< $@
  330. # Flat Image Tree (FIT)
  331. # This allows for packaging of a kernel and all devicetrees files, using
  332. # compression.
  333. # ---------------------------------------------------------------------------
  334. MAKE_FIT := $(srctree)/scripts/make_fit.py
  335. # Use this to override the compression algorithm
  336. FIT_COMPRESSION ?= gzip
  337. quiet_cmd_fit = FIT $@
  338. cmd_fit = $(MAKE_FIT) -o $@ --arch $(UIMAGE_ARCH) --os linux \
  339. --name '$(UIMAGE_NAME)' $(FIT_EXTRA_ARGS) \
  340. $(if $(findstring 1,$(KBUILD_VERBOSE)),-v) \
  341. $(if $(FIT_DECOMPOSE_DTBS),--decompose-dtbs) \
  342. --compress $(FIT_COMPRESSION) -k $< @$(word 2,$^)
  343. # XZ
  344. # ---------------------------------------------------------------------------
  345. # Use xzkern or xzkern_with_size to compress the kernel image and xzmisc to
  346. # compress other things.
  347. #
  348. # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
  349. # of the kernel decompressor. A BCJ filter is used if it is available for
  350. # the target architecture.
  351. #
  352. # xzkern_with_size also appends uncompressed size of the data using
  353. # size_append. The .xz format has the size information available at the end
  354. # of the file too, but it's in more complex format and it's good to avoid
  355. # changing the part of the boot code that reads the uncompressed size.
  356. # Note that the bytes added by size_append will make the xz tool think that
  357. # the file is corrupt. This is expected.
  358. #
  359. # xzmisc doesn't use size_append, so it can be used to create normal .xz
  360. # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
  361. # big dictionary would increase the memory usage too much in the multi-call
  362. # decompression mode. A BCJ filter isn't used either.
  363. quiet_cmd_xzkern = XZKERN $@
  364. cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
  365. quiet_cmd_xzkern_with_size = XZKERN $@
  366. cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
  367. $(size_append); } > $@
  368. quiet_cmd_xzmisc = XZMISC $@
  369. cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
  370. # ZSTD
  371. # ---------------------------------------------------------------------------
  372. # Appends the uncompressed size of the data using size_append. The .zst
  373. # format has the size information available at the beginning of the file too,
  374. # but it's in a more complex format and it's good to avoid changing the part
  375. # of the boot code that reads the uncompressed size.
  376. #
  377. # Note that the bytes added by size_append will make the zstd tool think that
  378. # the file is corrupt. This is expected.
  379. #
  380. # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
  381. # 128 MB. zstd22 is used for kernel compression because it is decompressed in a
  382. # single pass, so zstd doesn't need to allocate a window buffer. When streaming
  383. # decompression is used, like initramfs decompression, zstd22 should likely not
  384. # be used because it would require zstd to allocate a 128 MB buffer.
  385. quiet_cmd_zstd = ZSTD $@
  386. cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
  387. quiet_cmd_zstd22 = ZSTD22 $@
  388. cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
  389. quiet_cmd_zstd22_with_size = ZSTD22 $@
  390. cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
  391. # ASM offsets
  392. # ---------------------------------------------------------------------------
  393. # Default sed regexp - multiline due to syntax constraints
  394. #
  395. # Use [:space:] because LLVM's integrated assembler inserts <tab> around
  396. # the .ascii directive whereas GCC keeps the <space> as-is.
  397. define sed-offsets
  398. 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
  399. /^->/{s:->#\(.*\):/* \1 */:; \
  400. s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
  401. s:->::; p;}'
  402. endef
  403. # Use filechk to avoid rebuilds when a header changes, but the resulting file
  404. # does not
  405. define filechk_offsets
  406. echo "#ifndef $2"; \
  407. echo "#define $2"; \
  408. echo "/*"; \
  409. echo " * DO NOT MODIFY."; \
  410. echo " *"; \
  411. echo " * This file was generated by Kbuild"; \
  412. echo " */"; \
  413. echo ""; \
  414. sed -ne $(sed-offsets) < $<; \
  415. echo ""; \
  416. echo "#endif"
  417. endef