Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'kbuild-v6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

- Support cross-compiling linux-headers Debian package and kernel-devel
RPM package

- Add support for the linux-debug Pacman package

- Improve module rebuilding speed by factoring out the common code to
scripts/module-common.c

- Separate device tree build rules into scripts/Makefile.dtbs

- Add a new script to generate modules.builtin.ranges, which is useful
for tracing tools to find symbols in built-in modules

- Refactor Kconfig and misc tools

- Update Kbuild and Kconfig documentation

* tag 'kbuild-v6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (51 commits)
kbuild: doc: replace "gcc" in external module description
kbuild: doc: describe the -C option precisely for external module builds
kbuild: doc: remove the description about shipped files
kbuild: doc: drop section numbering, use references in modules.rst
kbuild: doc: throw out the local table of contents in modules.rst
kbuild: doc: remove outdated description of the limitation on -I usage
kbuild: doc: remove description about grepping CONFIG options
kbuild: doc: update the description about Kbuild/Makefile split
kbuild: remove unnecessary export of RUST_LIB_SRC
kbuild: remove append operation on cmd_ld_ko_o
kconfig: cache expression values
kconfig: use hash table to reuse expressions
kconfig: refactor expr_eliminate_dups()
kconfig: add comments to expression transformations
kconfig: change some expr_*() functions to bool
scripts: move hash function from scripts/kconfig/ to scripts/include/
kallsyms: change overflow variable to bool type
kallsyms: squash output_address()
kbuild: add install target for modules.builtin.ranges
scripts: add verifier script for builtin module range data
...

+1867 -909
+1 -2
.gitignore
··· 47 47 *.so.dbg 48 48 *.su 49 49 *.symtypes 50 - *.symversions 51 50 *.tab.[ch] 52 51 *.tar 53 52 *.xz ··· 70 71 /Module.markers 71 72 /modules.builtin 72 73 /modules.builtin.modinfo 74 + /modules.builtin.ranges 73 75 /modules.nsdeps 74 76 75 77 # ··· 143 143 # id-utils files 144 144 ID 145 145 146 - *.orig 147 146 *~ 148 147 \#*# 149 148
+1
Documentation/dontdiff
··· 180 180 modules-only.symvers 181 181 modules.builtin 182 182 modules.builtin.modinfo 183 + modules.builtin.ranges 183 184 modules.nsdeps 184 185 modules.order 185 186 modversions.h*
+10
Documentation/kbuild/kbuild.rst
··· 22 22 This file contains modinfo from all modules that are built into the kernel. 23 23 Unlike modinfo of a separate module, all fields are prefixed with module name. 24 24 25 + modules.builtin.ranges 26 + ---------------------- 27 + This file contains address offset ranges (per ELF section) for all modules 28 + that are built into the kernel. Together with System.map, it can be used 29 + to associate module names with symbols. 25 30 26 31 Environment variables 27 32 ===================== ··· 133 128 KBUILD_OUTPUT 134 129 ------------- 135 130 Specify the output directory when building the kernel. 131 + 132 + This variable can also be used to point to the kernel output directory when 133 + building external modules against a pre-built kernel in a separate build 134 + directory. Please note that this does NOT specify the output directory for the 135 + external modules themselves. 136 136 137 137 The output directory can also be specified using "O=...". 138 138
+5 -1
Documentation/kbuild/kconfig-language.rst
··· 70 70 71 71 Every menu entry can have at most one prompt, which is used to display 72 72 to the user. Optionally dependencies only for this prompt can be added 73 - with "if". 73 + with "if". If a prompt is not present, the config option is a non-visible 74 + symbol, meaning its value cannot be directly changed by the user (such as 75 + altering the value in ``.config``) and the option will not appear in any 76 + config menus. Its value can only be set via "default" and "select" (see 77 + below). 74 78 75 79 - default value: "default" <expr> ["if" <expr>] 76 80
-1
Documentation/kbuild/makefiles.rst
··· 1665 1665 TODO 1666 1666 ==== 1667 1667 1668 - - Describe how kbuild supports shipped files with _shipped. 1669 1668 - Generating offset header files. 1670 1669 - Add more variables to chapters 7 or 9?
+64 -160
Documentation/kbuild/modules.rst
··· 4 4 5 5 This document describes how to build an out-of-tree kernel module. 6 6 7 - .. Table of Contents 8 - 9 - === 1 Introduction 10 - === 2 How to Build External Modules 11 - --- 2.1 Command Syntax 12 - --- 2.2 Options 13 - --- 2.3 Targets 14 - --- 2.4 Building Separate Files 15 - === 3. Creating a Kbuild File for an External Module 16 - --- 3.1 Shared Makefile 17 - --- 3.2 Separate Kbuild file and Makefile 18 - --- 3.3 Binary Blobs 19 - --- 3.4 Building Multiple Modules 20 - === 4. Include Files 21 - --- 4.1 Kernel Includes 22 - --- 4.2 Single Subdirectory 23 - --- 4.3 Several Subdirectories 24 - === 5. Module Installation 25 - --- 5.1 INSTALL_MOD_PATH 26 - --- 5.2 INSTALL_MOD_DIR 27 - === 6. Module Versioning 28 - --- 6.1 Symbols From the Kernel (vmlinux + modules) 29 - --- 6.2 Symbols and External Modules 30 - --- 6.3 Symbols From Another External Module 31 - === 7. Tips & Tricks 32 - --- 7.1 Testing for CONFIG_FOO_BAR 33 - 34 - 35 - 36 - 1. Introduction 37 - =============== 7 + Introduction 8 + ============ 38 9 39 10 "kbuild" is the build system used by the Linux kernel. Modules must use 40 11 kbuild to stay compatible with changes in the build infrastructure and 41 - to pick up the right flags to "gcc." Functionality for building modules 12 + to pick up the right flags to the compiler. Functionality for building modules 42 13 both in-tree and out-of-tree is provided. The method for building 43 14 either is similar, and all modules are initially developed and built 44 15 out-of-tree. ··· 19 48 external module should supply a makefile that hides most of the 20 49 complexity, so one only has to type "make" to build the module. This is 21 50 easily accomplished, and a complete example will be presented in 22 - section 3. 51 + section `Creating a Kbuild File for an External Module`_. 23 52 24 53 25 - 2. How to Build External Modules 26 - ================================ 54 + How to Build External Modules 55 + ============================= 27 56 28 57 To build external modules, you must have a prebuilt kernel available 29 58 that contains the configuration and header files used in the build. ··· 40 69 CONFIG_MODVERSIONS is set; therefore, a full kernel build needs to be 41 70 executed to make module versioning work. 42 71 43 - 2.1 Command Syntax 44 - ================== 72 + Command Syntax 73 + -------------- 45 74 46 75 The command to build an external module is:: 47 76 48 - $ make -C <path_to_kernel_src> M=$PWD 77 + $ make -C <path_to_kernel_dir> M=$PWD 49 78 50 79 The kbuild system knows that an external module is being built 51 80 due to the "M=<dir>" option given in the command. ··· 59 88 60 89 $ make -C /lib/modules/`uname -r`/build M=$PWD modules_install 61 90 62 - 2.2 Options 63 - =========== 91 + Options 92 + ------- 64 93 65 - ($KDIR refers to the path of the kernel source directory.) 94 + ($KDIR refers to the path of the kernel source directory, or the path 95 + of the kernel output directory if the kernel was built in a separate 96 + build directory.) 66 97 67 98 make -C $KDIR M=$PWD 68 99 69 100 -C $KDIR 70 - The directory where the kernel source is located. 101 + The directory that contains the kernel and relevant build 102 + artifacts used for building an external module. 71 103 "make" will actually change to the specified directory 72 104 when executing and will change back when finished. 73 105 ··· 80 106 directory where the external module (kbuild file) is 81 107 located. 82 108 83 - 2.3 Targets 84 - =========== 109 + Targets 110 + ------- 85 111 86 112 When building an external module, only a subset of the "make" 87 113 targets are available. ··· 103 129 modules_install 104 130 Install the external module(s). The default location is 105 131 /lib/modules/<kernel_release>/updates/, but a prefix may 106 - be added with INSTALL_MOD_PATH (discussed in section 5). 132 + be added with INSTALL_MOD_PATH (discussed in section 133 + `Module Installation`_). 107 134 108 135 clean 109 136 Remove all generated files in the module directory only. ··· 112 137 help 113 138 List the available targets for external modules. 114 139 115 - 2.4 Building Separate Files 116 - =========================== 140 + Building Separate Files 141 + ----------------------- 117 142 118 143 It is possible to build single files that are part of a module. 119 144 This works equally well for the kernel, a module, and even for ··· 127 152 make -C $KDIR M=$PWD ./ 128 153 129 154 130 - 3. Creating a Kbuild File for an External Module 131 - ================================================ 155 + Creating a Kbuild File for an External Module 156 + ============================================= 132 157 133 158 In the last section we saw the command to build a module for the 134 159 running kernel. The module is not actually built, however, because a ··· 155 180 8123_if.c 156 181 8123_if.h 157 182 8123_pci.c 158 - 8123_bin.o_shipped <= Binary blob 159 183 160 - 3.1 Shared Makefile 161 - ------------------- 184 + Shared Makefile 185 + --------------- 162 186 163 187 An external module always includes a wrapper makefile that 164 188 supports building the module using "make" with no arguments. ··· 172 198 ifneq ($(KERNELRELEASE),) 173 199 # kbuild part of makefile 174 200 obj-m := 8123.o 175 - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o 201 + 8123-y := 8123_if.o 8123_pci.o 176 202 177 203 else 178 204 # normal makefile ··· 180 206 181 207 default: 182 208 $(MAKE) -C $(KDIR) M=$$PWD 183 - 184 - # Module specific targets 185 - genbin: 186 - echo "X" > 8123_bin.o_shipped 187 209 188 210 endif 189 211 ··· 191 221 line; the second pass is by the kbuild system, which is 192 222 initiated by the parameterized "make" in the default target. 193 223 194 - 3.2 Separate Kbuild File and Makefile 195 - ------------------------------------- 224 + Separate Kbuild File and Makefile 225 + --------------------------------- 196 226 197 - In newer versions of the kernel, kbuild will first look for a 198 - file named "Kbuild," and only if that is not found, will it 199 - then look for a makefile. Utilizing a "Kbuild" file allows us 200 - to split up the makefile from example 1 into two files: 227 + Kbuild will first look for a file named "Kbuild", and if it is not 228 + found, it will then look for "Makefile". Utilizing a "Kbuild" file 229 + allows us to split up the "Makefile" from example 1 into two files: 201 230 202 231 Example 2:: 203 232 204 233 --> filename: Kbuild 205 234 obj-m := 8123.o 206 - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o 235 + 8123-y := 8123_if.o 8123_pci.o 207 236 208 237 --> filename: Makefile 209 238 KDIR ?= /lib/modules/`uname -r`/build 210 239 211 240 default: 212 241 $(MAKE) -C $(KDIR) M=$$PWD 213 - 214 - # Module specific targets 215 - genbin: 216 - echo "X" > 8123_bin.o_shipped 217 242 218 243 The split in example 2 is questionable due to the simplicity of 219 244 each file; however, some external modules use makefiles 220 245 consisting of several hundred lines, and here it really pays 221 246 off to separate the kbuild part from the rest. 222 247 223 - The next example shows a backward compatible version. 224 - 225 - Example 3:: 226 - 227 - --> filename: Kbuild 228 - obj-m := 8123.o 229 - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o 230 - 231 - --> filename: Makefile 232 - ifneq ($(KERNELRELEASE),) 233 - # kbuild part of makefile 234 - include Kbuild 235 - 236 - else 237 - # normal makefile 238 - KDIR ?= /lib/modules/`uname -r`/build 239 - 240 - default: 241 - $(MAKE) -C $(KDIR) M=$$PWD 242 - 243 - # Module specific targets 244 - genbin: 245 - echo "X" > 8123_bin.o_shipped 246 - 247 - endif 248 - 249 - Here the "Kbuild" file is included from the makefile. This 250 - allows an older version of kbuild, which only knows of 251 - makefiles, to be used when the "make" and kbuild parts are 252 - split into separate files. 253 - 254 - 3.3 Binary Blobs 255 - ---------------- 256 - 257 - Some external modules need to include an object file as a blob. 258 - kbuild has support for this, but requires the blob file to be 259 - named <filename>_shipped. When the kbuild rules kick in, a copy 260 - of <filename>_shipped is created with _shipped stripped off, 261 - giving us <filename>. This shortened filename can be used in 262 - the assignment to the module. 263 - 264 - Throughout this section, 8123_bin.o_shipped has been used to 265 - build the kernel module 8123.ko; it has been included as 266 - 8123_bin.o:: 267 - 268 - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o 269 - 270 - Although there is no distinction between the ordinary source 271 - files and the binary file, kbuild will pick up different rules 272 - when creating the object file for the module. 273 - 274 - 3.4 Building Multiple Modules 275 - ============================= 248 + Building Multiple Modules 249 + ------------------------- 276 250 277 251 kbuild supports building multiple modules with a single build 278 252 file. For example, if you wanted to build two modules, foo.ko ··· 229 315 It is that simple! 230 316 231 317 232 - 4. Include Files 233 - ================ 318 + Include Files 319 + ============= 234 320 235 321 Within the kernel, header files are kept in standard locations 236 322 according to the following rule: ··· 248 334 include/scsi; and architecture specific headers are located 249 335 under arch/$(SRCARCH)/include/. 250 336 251 - 4.1 Kernel Includes 252 - ------------------- 337 + Kernel Includes 338 + --------------- 253 339 254 340 To include a header file located under include/linux/, simply 255 341 use:: 256 342 257 343 #include <linux/module.h> 258 344 259 - kbuild will add options to "gcc" so the relevant directories 345 + kbuild will add options to the compiler so the relevant directories 260 346 are searched. 261 347 262 - 4.2 Single Subdirectory 263 - ----------------------- 348 + Single Subdirectory 349 + ------------------- 264 350 265 351 External modules tend to place header files in a separate 266 352 include/ directory where their source is located, although this ··· 274 360 --> filename: Kbuild 275 361 obj-m := 8123.o 276 362 277 - ccflags-y := -Iinclude 278 - 8123-y := 8123_if.o 8123_pci.o 8123_bin.o 363 + ccflags-y := -I $(src)/include 364 + 8123-y := 8123_if.o 8123_pci.o 279 365 280 - Note that in the assignment there is no space between -I and 281 - the path. This is a limitation of kbuild: there must be no 282 - space present. 283 - 284 - 4.3 Several Subdirectories 285 - -------------------------- 366 + Several Subdirectories 367 + ---------------------- 286 368 287 369 kbuild can handle files that are spread over several directories. 288 370 Consider the following example:: ··· 317 407 file is located. 318 408 319 409 320 - 5. Module Installation 321 - ====================== 410 + Module Installation 411 + =================== 322 412 323 413 Modules which are included in the kernel are installed in the 324 414 directory: ··· 329 419 330 420 /lib/modules/$(KERNELRELEASE)/updates/ 331 421 332 - 5.1 INSTALL_MOD_PATH 333 - -------------------- 422 + INSTALL_MOD_PATH 423 + ---------------- 334 424 335 425 Above are the default directories but as always some level of 336 426 customization is possible. A prefix can be added to the ··· 344 434 calling "make." This has effect when installing both in-tree 345 435 and out-of-tree modules. 346 436 347 - 5.2 INSTALL_MOD_DIR 348 - ------------------- 437 + INSTALL_MOD_DIR 438 + --------------- 349 439 350 440 External modules are by default installed to a directory under 351 441 /lib/modules/$(KERNELRELEASE)/updates/, but you may wish to ··· 358 448 => Install dir: /lib/modules/$(KERNELRELEASE)/gandalf/ 359 449 360 450 361 - 6. Module Versioning 362 - ==================== 451 + Module Versioning 452 + ================= 363 453 364 454 Module versioning is enabled by the CONFIG_MODVERSIONS tag, and is used 365 455 as a simple ABI consistency check. A CRC value of the full prototype ··· 371 461 Module.symvers contains a list of all exported symbols from a kernel 372 462 build. 373 463 374 - 6.1 Symbols From the Kernel (vmlinux + modules) 375 - ----------------------------------------------- 464 + Symbols From the Kernel (vmlinux + modules) 465 + ------------------------------------------- 376 466 377 467 During a kernel build, a file named Module.symvers will be 378 468 generated. Module.symvers contains all exported symbols from ··· 396 486 1) It lists all exported symbols from vmlinux and all modules. 397 487 2) It lists the CRC if CONFIG_MODVERSIONS is enabled. 398 488 399 - 6.2 Symbols and External Modules 400 - -------------------------------- 489 + Symbols and External Modules 490 + ---------------------------- 401 491 402 492 When building an external module, the build system needs access 403 493 to the symbols from the kernel to check if all external symbols ··· 406 496 tree. During the MODPOST step, a new Module.symvers file will be 407 497 written containing all exported symbols from that external module. 408 498 409 - 6.3 Symbols From Another External Module 410 - ---------------------------------------- 499 + Symbols From Another External Module 500 + ------------------------------------ 411 501 412 502 Sometimes, an external module uses exported symbols from 413 503 another external module. Kbuild needs to have full knowledge of ··· 447 537 initialization of its symbol tables. 448 538 449 539 450 - 7. Tips & Tricks 451 - ================ 540 + Tips & Tricks 541 + ============= 452 542 453 - 7.1 Testing for CONFIG_FOO_BAR 454 - ------------------------------ 543 + Testing for CONFIG_FOO_BAR 544 + -------------------------- 455 545 456 546 Modules often need to check for certain `CONFIG_` options to 457 547 decide if a specific feature is included in the module. In ··· 463 553 464 554 ext2-y := balloc.o bitmap.o dir.o 465 555 ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o 466 - 467 - External modules have traditionally used "grep" to check for 468 - specific `CONFIG_` settings directly in .config. This usage is 469 - broken. As introduced before, external modules should use 470 - kbuild for building and can therefore use the same methods as 471 - in-tree modules when testing for `CONFIG_` definitions.
+7
Documentation/process/changes.rst
··· 64 64 gtags (optional) 6.6.5 gtags --version 65 65 mkimage (optional) 2017.01 mkimage --version 66 66 Python (optional) 3.5.x python3 --version 67 + GNU AWK (optional) 5.1.0 gawk --version 67 68 ====================== =============== ======================================== 68 69 69 70 .. [#f1] Sphinx is needed only to build the Kernel documentation ··· 192 191 platforms. The tool is available via the ``u-boot-tools`` package or can be 193 192 built from the U-Boot source code. See the instructions at 194 193 https://docs.u-boot.org/en/latest/build/tools.html#building-tools-for-linux 194 + 195 + GNU AWK 196 + ------- 197 + 198 + GNU AWK is needed if you want kernel builds to generate address range data for 199 + builtin modules (CONFIG_BUILTIN_MODULE_RANGES). 195 200 196 201 System utilities 197 202 ****************
+2 -5
Makefile
··· 579 579 RUSTC_OR_CLIPPY = $(RUSTC) 580 580 endif 581 581 582 - ifdef RUST_LIB_SRC 583 - export RUST_LIB_SRC 584 - endif 585 - 586 582 # Allows the usage of unstable features in stable compilers. 587 583 export RUSTC_BOOTSTRAP := 1 588 584 ··· 1479 1483 # Directories & files removed with 'make clean' 1480 1484 CLEAN_FILES += vmlinux.symvers modules-only.symvers \ 1481 1485 modules.builtin modules.builtin.modinfo modules.nsdeps \ 1486 + modules.builtin.ranges vmlinux.o.map \ 1482 1487 compile_commands.json rust/test \ 1483 1488 rust-project.json .vmlinux.objs .vmlinux.export.c 1484 1489 ··· 1944 1947 -o -name '*.c.[012]*.*' \ 1945 1948 -o -name '*.ll' \ 1946 1949 -o -name '*.gcno' \ 1947 - -o -name '*.*.symversions' \) -type f -print \ 1950 + \) -type f -print \ 1948 1951 -o -name '.tmp_*' -print \ 1949 1952 | xargs rm -rf 1950 1953
+1 -1
arch/arc/Kconfig
··· 554 554 string "Built in DTB" 555 555 help 556 556 Set the name of the DTB to embed in the vmlinux binary 557 - Leaving it blank selects the minimal "skeleton" dtb 557 + Leaving it blank selects the "nsim_700" dtb. 558 558 559 559 endmenu # "ARC Architecture Configuration" 560 560
-4
arch/x86/configs/tiny.config
··· 1 1 CONFIG_NOHIGHMEM=y 2 - # CONFIG_HIGHMEM4G is not set 3 - # CONFIG_HIGHMEM64G is not set 4 - # CONFIG_UNWINDER_ORC is not set 5 2 CONFIG_UNWINDER_GUESS=y 6 - # CONFIG_UNWINDER_FRAME_POINTER is not set
+1 -1
drivers/of/fdt.c
··· 34 34 35 35 /* 36 36 * __dtb_empty_root_begin[] and __dtb_empty_root_end[] magically created by 37 - * cmd_dt_S_dtb in scripts/Makefile.lib 37 + * cmd_wrap_S_dtb in scripts/Makefile.dtbs 38 38 */ 39 39 extern uint8_t __dtb_empty_root_begin[]; 40 40 extern uint8_t __dtb_empty_root_end[];
+2 -2
drivers/of/unittest.c
··· 1861 1861 struct device_node *unittest_data_node = NULL, *np; 1862 1862 /* 1863 1863 * __dtbo_testcases_begin[] and __dtbo_testcases_end[] are magically 1864 - * created by cmd_dt_S_dtbo in scripts/Makefile.lib 1864 + * created by cmd_wrap_S_dtbo in scripts/Makefile.dtbs 1865 1865 */ 1866 1866 extern uint8_t __dtbo_testcases_begin[]; 1867 1867 extern uint8_t __dtbo_testcases_end[]; ··· 3525 3525 3526 3526 /* 3527 3527 * __dtbo_##overlay_name##_begin[] and __dtbo_##overlay_name##_end[] are 3528 - * created by cmd_dt_S_dtbo in scripts/Makefile.lib 3528 + * created by cmd_wrap_S_dtbo in scripts/Makefile.dtbs 3529 3529 */ 3530 3530 3531 3531 #define OVERLAY_INFO_EXTERN(overlay_name) \
-6
kernel/configs/tiny.config
··· 1 - # CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set 2 1 CONFIG_CC_OPTIMIZE_FOR_SIZE=y 3 - # CONFIG_KERNEL_GZIP is not set 4 - # CONFIG_KERNEL_BZIP2 is not set 5 - # CONFIG_KERNEL_LZMA is not set 6 2 CONFIG_KERNEL_XZ=y 7 - # CONFIG_KERNEL_LZO is not set 8 - # CONFIG_KERNEL_LZ4 is not set 9 3 CONFIG_SLUB=y 10 4 CONFIG_SLUB_TINY=y
+15
lib/Kconfig.debug
··· 573 573 pieces of code get eliminated with 574 574 CONFIG_LD_DEAD_CODE_DATA_ELIMINATION. 575 575 576 + config BUILTIN_MODULE_RANGES 577 + bool "Generate address range information for builtin modules" 578 + depends on !LTO 579 + depends on VMLINUX_MAP 580 + help 581 + When modules are built into the kernel, there will be no module name 582 + associated with its symbols in /proc/kallsyms. Tracers may want to 583 + identify symbols by module name and symbol name regardless of whether 584 + the module is configured as loadable or not. 585 + 586 + This option generates modules.builtin.ranges in the build tree with 587 + offset ranges (per ELF section) for the module(s) they belong to. 588 + It also records an anchor symbol to determine the load address of the 589 + section. 590 + 576 591 config DEBUG_FORCE_WEAK_PER_CPU 577 592 bool "Force weak per-cpu definitions" 578 593 depends on DEBUG_KERNEL
+23 -35
scripts/Makefile.build
··· 41 41 include $(kbuild-file) 42 42 include $(srctree)/scripts/Makefile.lib 43 43 44 - # Do not include hostprogs rules unless needed. 45 - # $(sort ...) is used here to remove duplicated words and excessive spaces. 46 - hostprogs := $(sort $(hostprogs)) 47 - ifneq ($(hostprogs),) 48 - include $(srctree)/scripts/Makefile.host 49 - endif 50 - 51 - # Do not include userprogs rules unless needed. 52 - # $(sort ...) is used here to remove duplicated words and excessive spaces. 53 - userprogs := $(sort $(userprogs)) 54 - ifneq ($(userprogs),) 55 - include $(srctree)/scripts/Makefile.userprogs 56 - endif 57 - 58 44 ifndef obj 59 45 $(warning kbuild: Makefile.build is included improperly) 60 46 endif ··· 57 71 # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...) 58 72 subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y))) 59 73 subdir-modorder := $(sort $(filter %/modules.order, $(obj-m))) 60 - subdir-dtbslist := $(sort $(filter %/dtbs-list, $(dtb-y))) 61 74 62 75 targets-for-builtin := $(extra-y) 63 76 ··· 348 363 349 364 targets += $(filter-out $(subdir-builtin), $(real-obj-y)) 350 365 targets += $(filter-out $(subdir-modorder), $(real-obj-m)) 351 - targets += $(real-dtb-y) $(lib-y) $(always-y) 366 + targets += $(lib-y) $(always-y) 352 367 353 368 # Linker scripts preprocessor (.lds.S -> .lds) 354 369 # --------------------------------------------------------------------------- ··· 374 389 # To build objects in subdirs, we need to descend into the directories 375 390 $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ; 376 391 $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ; 377 - $(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ; 378 392 379 393 # 380 394 # Rule to compile a set of .o files into one .a file (without symbol table) ··· 389 405 $(obj)/built-in.a: $(real-obj-y) FORCE 390 406 $(call if_changed,ar_builtin) 391 407 392 - # 393 - # Rule to create modules.order and dtbs-list 394 - # 395 - # This is a list of build artifacts (module or dtb) from the current Makefile 396 - # and its sub-directories. The timestamp should be updated when any of the 397 - # member files. 408 + # This is a list of build artifacts from the current Makefile and its 409 + # sub-directories. The timestamp should be updated when any of the member files. 398 410 399 411 cmd_gen_order = { $(foreach m, $(real-prereqs), \ 400 412 $(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \ 401 413 > $@ 402 414 403 415 $(obj)/modules.order: $(obj-m) FORCE 404 - $(call if_changed,gen_order) 405 - 406 - $(obj)/dtbs-list: $(dtb-y) FORCE 407 416 $(call if_changed,gen_order) 408 417 409 418 # ··· 427 450 $(patsubst %$(strip $(1)),%$(sfx), \ 428 451 $(filter %$(strip $(1)), $(targets)))) 429 452 # %.asn1.o <- %.asn1.[ch] <- %.asn1 430 - # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts 431 - # %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso 432 - # %.lex.o <- %.lex.c <- %.l 433 - # %.tab.o <- %.tab.[ch] <- %.y 434 - targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ 435 - $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \ 436 - $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo) \ 437 - $(call intermediate_targets, .lex.o, .lex.c) \ 438 - $(call intermediate_targets, .tab.o, .tab.c .tab.h) 453 + targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) 454 + 455 + # Include additional build rules when necessary 456 + # --------------------------------------------------------------------------- 457 + 458 + # $(sort ...) is used here to remove duplicated words and excessive spaces. 459 + hostprogs := $(sort $(hostprogs)) 460 + ifneq ($(hostprogs),) 461 + include $(srctree)/scripts/Makefile.host 462 + endif 463 + 464 + # $(sort ...) is used here to remove duplicated words and excessive spaces. 465 + userprogs := $(sort $(userprogs)) 466 + ifneq ($(userprogs),) 467 + include $(srctree)/scripts/Makefile.userprogs 468 + endif 469 + 470 + ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),) 471 + include $(srctree)/scripts/Makefile.dtbs 472 + endif 439 473 440 474 # Build 441 475 # ---------------------------------------------------------------------------
+142
scripts/Makefile.dtbs
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 4 + dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 5 + 6 + # Composite DTB (i.e. DTB constructed by overlay) 7 + multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs) 8 + # Primitive DTB compiled from *.dts 9 + real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs) 10 + # Base DTB that overlay is applied onto 11 + base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs)) 12 + 13 + dtb-y := $(addprefix $(obj)/, $(dtb-y)) 14 + multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y)) 15 + real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y)) 16 + 17 + always-y += $(dtb-y) 18 + targets += $(real-dtb-y) 19 + 20 + # dtbs-list 21 + # --------------------------------------------------------------------------- 22 + 23 + ifdef need-dtbslist 24 + subdir-dtbslist := $(addsuffix /dtbs-list, $(subdir-ym)) 25 + dtb-y += $(subdir-dtbslist) 26 + always-y += $(obj)/dtbs-list 27 + endif 28 + 29 + $(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ; 30 + 31 + $(obj)/dtbs-list: $(dtb-y) FORCE 32 + $(call if_changed,gen_order) 33 + 34 + # Assembly file to wrap dtb(o) 35 + # --------------------------------------------------------------------------- 36 + 37 + # Generate an assembly file to wrap the output of the device tree compiler 38 + quiet_cmd_wrap_S_dtb = WRAP $@ 39 + cmd_wrap_S_dtb = { \ 40 + symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \ 41 + echo '\#include <asm-generic/vmlinux.lds.h>'; \ 42 + echo '.section .dtb.init.rodata,"a"'; \ 43 + echo '.balign STRUCT_ALIGNMENT'; \ 44 + echo ".global $${symbase}_begin"; \ 45 + echo "$${symbase}_begin:"; \ 46 + echo '.incbin "$<" '; \ 47 + echo ".global $${symbase}_end"; \ 48 + echo "$${symbase}_end:"; \ 49 + echo '.balign STRUCT_ALIGNMENT'; \ 50 + } > $@ 51 + 52 + $(obj)/%.dtb.S: $(obj)/%.dtb FORCE 53 + $(call if_changed,wrap_S_dtb) 54 + 55 + $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE 56 + $(call if_changed,wrap_S_dtb) 57 + 58 + # Schema check 59 + # --------------------------------------------------------------------------- 60 + 61 + ifneq ($(CHECK_DTBS),) 62 + DT_CHECKER ?= dt-validate 63 + DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m) 64 + DT_BINDING_DIR := Documentation/devicetree/bindings 65 + DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json 66 + dtb-check-enabled = $(if $(filter %.dtb, $@),y) 67 + endif 68 + 69 + quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], ) 70 + cmd_dtb_check = $(if $(dtb-check-enabled),; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true) 71 + 72 + # Overlay 73 + # --------------------------------------------------------------------------- 74 + 75 + # NOTE: 76 + # Do not replace $(filter %.dtb %.dtbo, $^) with $(real-prereqs). When a single 77 + # DTB is turned into a multi-blob DTB, $^ will contain header file dependencies 78 + # recorded in the .*.cmd file. 79 + quiet_cmd_fdtoverlay = OVL $(quiet_dtb_check_tag) $@ 80 + cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(filter %.dtb %.dtbo, $^) $(cmd_dtb_check) 81 + 82 + $(multi-dtb-y): $(DT_TMP_SCHEMA) FORCE 83 + $(call if_changed,fdtoverlay) 84 + $(call multi_depend, $(multi-dtb-y), .dtb, -dtbs) 85 + 86 + # DTC 87 + # --------------------------------------------------------------------------- 88 + 89 + DTC ?= $(objtree)/scripts/dtc/dtc 90 + DTC_FLAGS += -Wno-unique_unit_address 91 + 92 + # Disable noisy checks by default 93 + ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) 94 + DTC_FLAGS += -Wno-unit_address_vs_reg \ 95 + -Wno-avoid_unnecessary_addr_size \ 96 + -Wno-alias_paths \ 97 + -Wno-graph_child_address \ 98 + -Wno-simple_bus_reg 99 + else 100 + DTC_FLAGS += -Wunique_unit_address_if_enabled 101 + endif 102 + 103 + ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),) 104 + DTC_FLAGS += -Wnode_name_chars_strict \ 105 + -Wproperty_name_chars_strict \ 106 + -Wunique_unit_address 107 + endif 108 + 109 + DTC_FLAGS += $(DTC_FLAGS_$(target-stem)) 110 + 111 + # Set -@ if the target is a base DTB that overlay is applied onto 112 + DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@) 113 + 114 + DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes 115 + 116 + dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -D__DTS__ 117 + 118 + dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 119 + 120 + quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@ 121 + cmd_dtc = \ 122 + $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 123 + $(DTC) -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \ 124 + $(DTC_FLAGS) -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 125 + cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \ 126 + $(cmd_dtb_check) 127 + 128 + $(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE 129 + $(call if_changed_dep,dtc) 130 + 131 + $(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE 132 + $(call if_changed_dep,dtc) 133 + 134 + # targets 135 + # --------------------------------------------------------------------------- 136 + 137 + targets += $(always-y) 138 + 139 + # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts 140 + # %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso 141 + targets += $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \ 142 + $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo)
+5
scripts/Makefile.host
··· 160 160 161 161 targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \ 162 162 $(host-cxxmulti) $(host-cxxobjs) $(host-rust) 163 + 164 + # %.lex.o <- %.lex.c <- %.l 165 + # %.tab.o <- %.tab.[ch] <- %.y 166 + targets += $(call intermediate_targets, .lex.o, .lex.c) \ 167 + $(call intermediate_targets, .tab.o, .tab.c .tab.h)
+2 -117
scripts/Makefile.lib
··· 45 45 obj-y := $(filter-out %/, $(obj-y)) 46 46 endif 47 47 48 - ifdef need-dtbslist 49 - dtb-y += $(addsuffix /dtbs-list, $(subdir-ym)) 50 - always-y += dtbs-list 51 - endif 52 - 53 48 # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals 54 49 suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s)))) 55 50 # List composite targets that are constructed by combining other targets ··· 75 80 userprogs += $(userprogs-always-y) $(userprogs-always-m) 76 81 always-y += $(userprogs-always-y) $(userprogs-always-m) 77 82 78 - # DTB 79 - # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 80 - dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 81 - 82 - # Composite DTB (i.e. DTB constructed by overlay) 83 - multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs) 84 - # Primitive DTB compiled from *.dts 85 - real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs) 86 - # Base DTB that overlay is applied onto 87 - base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs)) 88 - 89 - always-y += $(dtb-y) 90 - 91 83 # Add subdir path 92 84 93 85 ifneq ($(obj),.) ··· 86 104 real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) 87 105 real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) 88 106 multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) 89 - dtb-y := $(addprefix $(obj)/, $(dtb-y)) 90 - multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y)) 91 - real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y)) 92 107 subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 93 108 endif 94 109 ··· 217 238 218 239 modkern_aflags = $(if $(part-of-module), \ 219 240 $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ 220 - $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) 241 + $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) $(modfile_flags)) 221 242 222 243 c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 223 244 -include $(srctree)/include/linux/compiler_types.h \ ··· 227 248 rust_flags = $(_rust_flags) $(modkern_rustflags) @$(objtree)/include/generated/rustc_cfg 228 249 229 250 a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 230 - $(_a_flags) $(modkern_aflags) 251 + $(_a_flags) $(modkern_aflags) $(modname_flags) 231 252 232 253 cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 233 254 $(_cpp_flags) 234 255 235 256 ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) 236 - 237 - DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes 238 - 239 - dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \ 240 - $(addprefix -I,$(DTC_INCLUDE)) \ 241 - -undef -D__DTS__ 242 257 243 258 ifdef CONFIG_OBJTOOL 244 259 ··· 322 349 323 350 quiet_cmd_gzip = GZIP $@ 324 351 cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@ 325 - 326 - # DTC 327 - # --------------------------------------------------------------------------- 328 - DTC ?= $(objtree)/scripts/dtc/dtc 329 - DTC_FLAGS += \ 330 - -Wno-unique_unit_address 331 - 332 - # Disable noisy checks by default 333 - ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) 334 - DTC_FLAGS += -Wno-unit_address_vs_reg \ 335 - -Wno-avoid_unnecessary_addr_size \ 336 - -Wno-alias_paths \ 337 - -Wno-graph_child_address \ 338 - -Wno-simple_bus_reg 339 - else 340 - DTC_FLAGS += \ 341 - -Wunique_unit_address_if_enabled 342 - endif 343 - 344 - ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),) 345 - DTC_FLAGS += -Wnode_name_chars_strict \ 346 - -Wproperty_name_chars_strict \ 347 - -Wunique_unit_address 348 - endif 349 - 350 - DTC_FLAGS += $(DTC_FLAGS_$(target-stem)) 351 - 352 - # Set -@ if the target is a base DTB that overlay is applied onto 353 - DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@) 354 - 355 - # Generate an assembly file to wrap the output of the device tree compiler 356 - quiet_cmd_wrap_S_dtb = WRAP $@ 357 - cmd_wrap_S_dtb = { \ 358 - symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \ 359 - echo '\#include <asm-generic/vmlinux.lds.h>'; \ 360 - echo '.section .dtb.init.rodata,"a"'; \ 361 - echo '.balign STRUCT_ALIGNMENT'; \ 362 - echo ".global $${symbase}_begin"; \ 363 - echo "$${symbase}_begin:"; \ 364 - echo '.incbin "$<" '; \ 365 - echo ".global $${symbase}_end"; \ 366 - echo "$${symbase}_end:"; \ 367 - echo '.balign STRUCT_ALIGNMENT'; \ 368 - } > $@ 369 - 370 - $(obj)/%.dtb.S: $(obj)/%.dtb FORCE 371 - $(call if_changed,wrap_S_dtb) 372 - 373 - $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE 374 - $(call if_changed,wrap_S_dtb) 375 - 376 - quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], ) 377 - cmd_dtb_check = $(if $(dtb-check-enabled),; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true) 378 - 379 - quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@ 380 - cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 381 - $(DTC) -o $@ -b 0 \ 382 - $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \ 383 - -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 384 - cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \ 385 - $(cmd_dtb_check) 386 - 387 - # NOTE: 388 - # Do not replace $(filter %.dtb %.dtbo, $^) with $(real-prereqs). When a single 389 - # DTB is turned into a multi-blob DTB, $^ will contain header file dependencies 390 - # recorded in the .*.cmd file. 391 - quiet_cmd_fdtoverlay = OVL $(quiet_dtb_check_tag) $@ 392 - cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(filter %.dtb %.dtbo, $^) $(cmd_dtb_check) 393 - 394 - $(multi-dtb-y): FORCE 395 - $(call if_changed,fdtoverlay) 396 - $(call multi_depend, $(multi-dtb-y), .dtb, -dtbs) 397 - 398 - ifneq ($(CHECK_DTBS),) 399 - DT_CHECKER ?= dt-validate 400 - DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m) 401 - DT_BINDING_DIR := Documentation/devicetree/bindings 402 - DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json 403 - dtb-check-enabled = $(if $(filter %.dtb, $@),y) 404 - endif 405 - 406 - $(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE 407 - $(call if_changed_dep,dtc) 408 - 409 - $(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE 410 - $(call if_changed_dep,dtc) 411 - 412 - dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 413 352 414 353 # Bzip2 415 354 # ---------------------------------------------------------------------------
+6 -3
scripts/Makefile.modfinal
··· 30 30 %.mod.o: %.mod.c FORCE 31 31 $(call if_changed_dep,cc_o_c) 32 32 33 + $(extmod_prefix).module-common.o: $(srctree)/scripts/module-common.c FORCE 34 + $(call if_changed_dep,cc_o_c) 35 + 33 36 quiet_cmd_ld_ko_o = LD [M] $@ 34 - cmd_ld_ko_o += \ 37 + cmd_ld_ko_o = \ 35 38 $(LD) -r $(KBUILD_LDFLAGS) \ 36 39 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ 37 40 -T scripts/module.lds -o $@ $(filter %.o, $^) ··· 57 54 printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 58 55 59 56 # Re-generate module BTFs if either module's .ko or vmlinux changed 60 - %.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE 57 + %.ko: %.o %.mod.o $(extmod_prefix).module-common.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE 61 58 +$(call if_changed_except,ld_ko_o,vmlinux) 62 59 ifdef CONFIG_DEBUG_INFO_BTF_MODULES 63 60 +$(if $(newer-prereqs),$(call cmd,btf_ko)) 64 61 endif 65 62 66 - targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) 63 + targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) $(extmod_prefix).module-common.o 67 64 68 65 # Add FORCE to the prerequisites of a target to force it to be always rebuilt. 69 66 # ---------------------------------------------------------------------------
+5 -3
scripts/Makefile.modinst
··· 30 30 quiet_cmd_install_modorder = INSTALL $@ 31 31 cmd_install_modorder = sed 's:^\(.*\)\.o$$:kernel/\1.ko:' $< > $@ 32 32 33 - # Install modules.builtin(.modinfo) even when CONFIG_MODULES is disabled. 33 + # Install modules.builtin(.modinfo,.ranges) even when CONFIG_MODULES is disabled. 34 34 install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo) 35 35 36 - $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo): $(MODLIB)/%: % FORCE 36 + install-$(CONFIG_BUILTIN_MODULE_RANGES) += $(MODLIB)/modules.builtin.ranges 37 + 38 + $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin.ranges): $(MODLIB)/%: % FORCE 37 39 $(call cmd,install) 38 40 39 41 endif ··· 148 146 quiet_cmd_xz = XZ $@ 149 147 cmd_xz = $(XZ) --check=crc32 --lzma2=dict=1MiB -f $< 150 148 quiet_cmd_zstd = ZSTD $@ 151 - cmd_zstd = $(ZSTD) -T0 --rm -f -q $< 149 + cmd_zstd = $(ZSTD) --rm -f -q $< 152 150 153 151 $(dst)/%.ko.gz: $(dst)/%.ko FORCE 154 152 $(call cmd,gzip)
+1 -2
scripts/Makefile.package
··· 147 147 PHONY += pacman-pkg 148 148 pacman-pkg: 149 149 @ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD 150 - +objtree="$(realpath $(objtree))" \ 151 - BUILDDIR="$(realpath $(objtree))/pacman" \ 150 + +BUILDDIR="$(realpath $(objtree))/pacman" \ 152 151 CARCH="$(UTS_MACHINE)" \ 153 152 KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \ 154 153 KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
+18
scripts/Makefile.vmlinux
··· 33 33 vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE 34 34 +$(call if_changed_dep,link_vmlinux) 35 35 36 + # module.builtin.ranges 37 + # --------------------------------------------------------------------------- 38 + ifdef CONFIG_BUILTIN_MODULE_RANGES 39 + __default: modules.builtin.ranges 40 + 41 + quiet_cmd_modules_builtin_ranges = GEN $@ 42 + cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ 43 + 44 + targets += modules.builtin.ranges 45 + modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ 46 + modules.builtin vmlinux.map vmlinux.o.map FORCE 47 + $(call if_changed,modules_builtin_ranges) 48 + 49 + vmlinux.map: vmlinux 50 + @: 51 + 52 + endif 53 + 36 54 # Add FORCE to the prerequisites of a target to force it to be always rebuilt. 37 55 # --------------------------------------------------------------------------- 38 56
+3
scripts/Makefile.vmlinux_o
··· 45 45 # Link of vmlinux.o used for section mismatch analysis 46 46 # --------------------------------------------------------------------------- 47 47 48 + vmlinux-o-ld-args-$(CONFIG_BUILTIN_MODULE_RANGES) += -Map=$@.map 49 + 48 50 quiet_cmd_ld_vmlinux.o = LD $@ 49 51 cmd_ld_vmlinux.o = \ 50 52 $(LD) ${KBUILD_LDFLAGS} -r -o $@ \ 53 + $(vmlinux-o-ld-args-y) \ 51 54 $(addprefix -T , $(initcalls-lds)) \ 52 55 --whole-archive vmlinux.a --no-whole-archive \ 53 56 --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
+5 -10
scripts/basic/fixdep.c
··· 99 99 #include <stdio.h> 100 100 #include <ctype.h> 101 101 102 + #include <xalloc.h> 103 + 102 104 static void usage(void) 103 105 { 104 106 fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); ··· 133 131 static void add_to_hashtable(const char *name, int len, unsigned int hash, 134 132 struct item *hashtab[]) 135 133 { 136 - struct item *aux = malloc(sizeof(*aux) + len); 134 + struct item *aux; 137 135 138 - if (!aux) { 139 - perror("fixdep:malloc"); 140 - exit(1); 141 - } 136 + aux = xmalloc(sizeof(*aux) + len); 142 137 memcpy(aux->name, name, len); 143 138 aux->len = len; 144 139 aux->hash = hash; ··· 227 228 perror(filename); 228 229 exit(2); 229 230 } 230 - buf = malloc(st.st_size + 1); 231 - if (!buf) { 232 - perror("fixdep: malloc"); 233 - exit(2); 234 - } 231 + buf = xmalloc(st.st_size + 1); 235 232 if (read(fd, buf, st.st_size) != st.st_size) { 236 233 perror("fixdep: read"); 237 234 exit(2);
+508
scripts/generate_builtin_ranges.awk
··· 1 + #!/usr/bin/gawk -f 2 + # SPDX-License-Identifier: GPL-2.0 3 + # generate_builtin_ranges.awk: Generate address range data for builtin modules 4 + # Written by Kris Van Hees <kris.van.hees@oracle.com> 5 + # 6 + # Usage: generate_builtin_ranges.awk modules.builtin vmlinux.map \ 7 + # vmlinux.o.map > modules.builtin.ranges 8 + # 9 + 10 + # Return the module name(s) (if any) associated with the given object. 11 + # 12 + # If we have seen this object before, return information from the cache. 13 + # Otherwise, retrieve it from the corresponding .cmd file. 14 + # 15 + function get_module_info(fn, mod, obj, s) { 16 + if (fn in omod) 17 + return omod[fn]; 18 + 19 + if (match(fn, /\/[^/]+$/) == 0) 20 + return ""; 21 + 22 + obj = fn; 23 + mod = ""; 24 + fn = substr(fn, 1, RSTART) "." substr(fn, RSTART + 1) ".cmd"; 25 + if (getline s <fn == 1) { 26 + if (match(s, /DKBUILD_MODFILE=['"]+[^'"]+/) > 0) { 27 + mod = substr(s, RSTART + 16, RLENGTH - 16); 28 + gsub(/['"]/, "", mod); 29 + } else if (match(s, /RUST_MODFILE=[^ ]+/) > 0) 30 + mod = substr(s, RSTART + 13, RLENGTH - 13); 31 + } 32 + close(fn); 33 + 34 + # A single module (common case) also reflects objects that are not part 35 + # of a module. Some of those objects have names that are also a module 36 + # name (e.g. core). We check the associated module file name, and if 37 + # they do not match, the object is not part of a module. 38 + if (mod !~ / /) { 39 + if (!(mod in mods)) 40 + mod = ""; 41 + } 42 + 43 + gsub(/([^/ ]*\/)+/, "", mod); 44 + gsub(/-/, "_", mod); 45 + 46 + # At this point, mod is a single (valid) module name, or a list of 47 + # module names (that do not need validation). 48 + omod[obj] = mod; 49 + 50 + return mod; 51 + } 52 + 53 + # Update the ranges entry for the given module 'mod' in section 'osect'. 54 + # 55 + # We use a modified absolute start address (soff + base) as index because we 56 + # may need to insert an anchor record later that must be at the start of the 57 + # section data, and the first module may very well start at the same address. 58 + # So, we use (addr << 1) + 1 to allow a possible anchor record to be placed at 59 + # (addr << 1). This is safe because the index is only used to sort the entries 60 + # before writing them out. 61 + # 62 + function update_entry(osect, mod, soff, eoff, sect, idx) { 63 + sect = sect_in[osect]; 64 + idx = sprintf("%016x", (soff + sect_base[osect]) * 2 + 1); 65 + entries[idx] = sprintf("%s %08x-%08x %s", sect, soff, eoff, mod); 66 + count[sect]++; 67 + } 68 + 69 + # (1) Build a lookup map of built-in module names. 70 + # 71 + # The first file argument is used as input (modules.builtin). 72 + # 73 + # Lines will be like: 74 + # kernel/crypto/lzo-rle.ko 75 + # and we record the object name "crypto/lzo-rle". 76 + # 77 + ARGIND == 1 { 78 + sub(/kernel\//, ""); # strip off "kernel/" prefix 79 + sub(/\.ko$/, ""); # strip off .ko suffix 80 + 81 + mods[$1] = 1; 82 + next; 83 + } 84 + 85 + # (2) Collect address information for each section. 86 + # 87 + # The second file argument is used as input (vmlinux.map). 88 + # 89 + # We collect the base address of the section in order to convert all addresses 90 + # in the section into offset values. 91 + # 92 + # We collect the address of the anchor (or first symbol in the section if there 93 + # is no explicit anchor) to allow users of the range data to calculate address 94 + # ranges based on the actual load address of the section in the running kernel. 95 + # 96 + # We collect the start address of any sub-section (section included in the top 97 + # level section being processed). This is needed when the final linking was 98 + # done using vmlinux.a because then the list of objects contained in each 99 + # section is to be obtained from vmlinux.o.map. The offset of the sub-section 100 + # is recorded here, to be used as an addend when processing vmlinux.o.map 101 + # later. 102 + # 103 + 104 + # Both GNU ld and LLVM lld linker map format are supported by converting LLVM 105 + # lld linker map records into equivalent GNU ld linker map records. 106 + # 107 + # The first record of the vmlinux.map file provides enough information to know 108 + # which format we are dealing with. 109 + # 110 + ARGIND == 2 && FNR == 1 && NF == 7 && $1 == "VMA" && $7 == "Symbol" { 111 + map_is_lld = 1; 112 + if (dbg) 113 + printf "NOTE: %s uses LLVM lld linker map format\n", FILENAME >"/dev/stderr"; 114 + next; 115 + } 116 + 117 + # (LLD) Convert a section record fronm lld format to ld format. 118 + # 119 + # lld: ffffffff82c00000 2c00000 2493c0 8192 .data 120 + # -> 121 + # ld: .data 0xffffffff82c00000 0x2493c0 load address 0x0000000002c00000 122 + # 123 + ARGIND == 2 && map_is_lld && NF == 5 && /[0-9] [^ ]+$/ { 124 + $0 = $5 " 0x"$1 " 0x"$3 " load address 0x"$2; 125 + } 126 + 127 + # (LLD) Convert an anchor record from lld format to ld format. 128 + # 129 + # lld: ffffffff81000000 1000000 0 1 _text = . 130 + # -> 131 + # ld: 0xffffffff81000000 _text = . 132 + # 133 + ARGIND == 2 && map_is_lld && !anchor && NF == 7 && raw_addr == "0x"$1 && $6 == "=" && $7 == "." { 134 + $0 = " 0x"$1 " " $5 " = ."; 135 + } 136 + 137 + # (LLD) Convert an object record from lld format to ld format. 138 + # 139 + # lld: 11480 11480 1f07 16 vmlinux.a(arch/x86/events/amd/uncore.o):(.text) 140 + # -> 141 + # ld: .text 0x0000000000011480 0x1f07 arch/x86/events/amd/uncore.o 142 + # 143 + ARGIND == 2 && map_is_lld && NF == 5 && $5 ~ /:\(/ { 144 + gsub(/\)/, ""); 145 + sub(/ vmlinux\.a\(/, " "); 146 + sub(/:\(/, " "); 147 + $0 = " "$6 " 0x"$1 " 0x"$3 " " $5; 148 + } 149 + 150 + # (LLD) Convert a symbol record from lld format to ld format. 151 + # 152 + # We only care about these while processing a section for which no anchor has 153 + # been determined yet. 154 + # 155 + # lld: ffffffff82a859a4 2a859a4 0 1 btf_ksym_iter_id 156 + # -> 157 + # ld: 0xffffffff82a859a4 btf_ksym_iter_id 158 + # 159 + ARGIND == 2 && map_is_lld && sect && !anchor && NF == 5 && $5 ~ /^[_A-Za-z][_A-Za-z0-9]*$/ { 160 + $0 = " 0x"$1 " " $5; 161 + } 162 + 163 + # (LLD) We do not need any other ldd linker map records. 164 + # 165 + ARGIND == 2 && map_is_lld && /^[0-9a-f]{16} / { 166 + next; 167 + } 168 + 169 + # (LD) Section records with just the section name at the start of the line 170 + # need to have the next line pulled in to determine whether it is a 171 + # loadable section. If it is, the next line will contains a hex value 172 + # as first and second items. 173 + # 174 + ARGIND == 2 && !map_is_lld && NF == 1 && /^[^ ]/ { 175 + s = $0; 176 + getline; 177 + if ($1 !~ /^0x/ || $2 !~ /^0x/) 178 + next; 179 + 180 + $0 = s " " $0; 181 + } 182 + 183 + # (LD) Object records with just the section name denote records with a long 184 + # section name for which the remainder of the record can be found on the 185 + # next line. 186 + # 187 + # (This is also needed for vmlinux.o.map, when used.) 188 + # 189 + ARGIND >= 2 && !map_is_lld && NF == 1 && /^ [^ \*]/ { 190 + s = $0; 191 + getline; 192 + $0 = s " " $0; 193 + } 194 + 195 + # Beginning a new section - done with the previous one (if any). 196 + # 197 + ARGIND == 2 && /^[^ ]/ { 198 + sect = 0; 199 + } 200 + 201 + # Process a loadable section (we only care about .-sections). 202 + # 203 + # Record the section name and its base address. 204 + # We also record the raw (non-stripped) address of the section because it can 205 + # be used to identify an anchor record. 206 + # 207 + # Note: 208 + # Since some AWK implementations cannot handle large integers, we strip off the 209 + # first 4 hex digits from the address. This is safe because the kernel space 210 + # is not large enough for addresses to extend into those digits. The portion 211 + # to strip off is stored in addr_prefix as a regexp, so further clauses can 212 + # perform a simple substitution to do the address stripping. 213 + # 214 + ARGIND == 2 && /^\./ { 215 + # Explicitly ignore a few sections that are not relevant here. 216 + if ($1 ~ /^\.orc_/ || $1 ~ /_sites$/ || $1 ~ /\.percpu/) 217 + next; 218 + 219 + # Sections with a 0-address can be ignored as well. 220 + if ($2 ~ /^0x0+$/) 221 + next; 222 + 223 + raw_addr = $2; 224 + addr_prefix = "^" substr($2, 1, 6); 225 + base = $2; 226 + sub(addr_prefix, "0x", base); 227 + base = strtonum(base); 228 + sect = $1; 229 + anchor = 0; 230 + sect_base[sect] = base; 231 + sect_size[sect] = strtonum($3); 232 + 233 + if (dbg) 234 + printf "[%s] BASE %016x\n", sect, base >"/dev/stderr"; 235 + 236 + next; 237 + } 238 + 239 + # If we are not in a section we care about, we ignore the record. 240 + # 241 + ARGIND == 2 && !sect { 242 + next; 243 + } 244 + 245 + # Record the first anchor symbol for the current section. 246 + # 247 + # An anchor record for the section bears the same raw address as the section 248 + # record. 249 + # 250 + ARGIND == 2 && !anchor && NF == 4 && raw_addr == $1 && $3 == "=" && $4 == "." { 251 + anchor = sprintf("%s %08x-%08x = %s", sect, 0, 0, $2); 252 + sect_anchor[sect] = anchor; 253 + 254 + if (dbg) 255 + printf "[%s] ANCHOR %016x = %s (.)\n", sect, 0, $2 >"/dev/stderr"; 256 + 257 + next; 258 + } 259 + 260 + # If no anchor record was found for the current section, use the first symbol 261 + # in the section as anchor. 262 + # 263 + ARGIND == 2 && !anchor && NF == 2 && $1 ~ /^0x/ && $2 !~ /^0x/ { 264 + addr = $1; 265 + sub(addr_prefix, "0x", addr); 266 + addr = strtonum(addr) - base; 267 + anchor = sprintf("%s %08x-%08x = %s", sect, addr, addr, $2); 268 + sect_anchor[sect] = anchor; 269 + 270 + if (dbg) 271 + printf "[%s] ANCHOR %016x = %s\n", sect, addr, $2 >"/dev/stderr"; 272 + 273 + next; 274 + } 275 + 276 + # The first occurrence of a section name in an object record establishes the 277 + # addend (often 0) for that section. This information is needed to handle 278 + # sections that get combined in the final linking of vmlinux (e.g. .head.text 279 + # getting included at the start of .text). 280 + # 281 + # If the section does not have a base yet, use the base of the encapsulating 282 + # section. 283 + # 284 + ARGIND == 2 && sect && NF == 4 && /^ [^ \*]/ && !($1 in sect_addend) { 285 + if (!($1 in sect_base)) { 286 + sect_base[$1] = base; 287 + 288 + if (dbg) 289 + printf "[%s] BASE %016x\n", $1, base >"/dev/stderr"; 290 + } 291 + 292 + addr = $2; 293 + sub(addr_prefix, "0x", addr); 294 + addr = strtonum(addr); 295 + sect_addend[$1] = addr - sect_base[$1]; 296 + sect_in[$1] = sect; 297 + 298 + if (dbg) 299 + printf "[%s] ADDEND %016x - %016x = %016x\n", $1, addr, base, sect_addend[$1] >"/dev/stderr"; 300 + 301 + # If the object is vmlinux.o then we will need vmlinux.o.map to get the 302 + # actual offsets of objects. 303 + if ($4 == "vmlinux.o") 304 + need_o_map = 1; 305 + } 306 + 307 + # (3) Collect offset ranges (relative to the section base address) for built-in 308 + # modules. 309 + # 310 + # If the final link was done using the actual objects, vmlinux.map contains all 311 + # the information we need (see section (3a)). 312 + # If linking was done using vmlinux.a as intermediary, we will need to process 313 + # vmlinux.o.map (see section (3b)). 314 + 315 + # (3a) Determine offset range info using vmlinux.map. 316 + # 317 + # Since we are already processing vmlinux.map, the top level section that is 318 + # being processed is already known. If we do not have a base address for it, 319 + # we do not need to process records for it. 320 + # 321 + # Given the object name, we determine the module(s) (if any) that the current 322 + # object is associated with. 323 + # 324 + # If we were already processing objects for a (list of) module(s): 325 + # - If the current object belongs to the same module(s), update the range data 326 + # to include the current object. 327 + # - Otherwise, ensure that the end offset of the range is valid. 328 + # 329 + # If the current object does not belong to a built-in module, ignore it. 330 + # 331 + # If it does, we add a new built-in module offset range record. 332 + # 333 + ARGIND == 2 && !need_o_map && /^ [^ ]/ && NF == 4 && $3 != "0x0" { 334 + if (!(sect in sect_base)) 335 + next; 336 + 337 + # Turn the address into an offset from the section base. 338 + soff = $2; 339 + sub(addr_prefix, "0x", soff); 340 + soff = strtonum(soff) - sect_base[sect]; 341 + eoff = soff + strtonum($3); 342 + 343 + # Determine which (if any) built-in modules the object belongs to. 344 + mod = get_module_info($4); 345 + 346 + # If we are processing a built-in module: 347 + # - If the current object is within the same module, we update its 348 + # entry by extending the range and move on 349 + # - Otherwise: 350 + # + If we are still processing within the same main section, we 351 + # validate the end offset against the start offset of the 352 + # current object (e.g. .rodata.str1.[18] objects are often 353 + # listed with an incorrect size in the linker map) 354 + # + Otherwise, we validate the end offset against the section 355 + # size 356 + if (mod_name) { 357 + if (mod == mod_name) { 358 + mod_eoff = eoff; 359 + update_entry(mod_sect, mod_name, mod_soff, eoff); 360 + 361 + next; 362 + } else if (sect == sect_in[mod_sect]) { 363 + if (mod_eoff > soff) 364 + update_entry(mod_sect, mod_name, mod_soff, soff); 365 + } else { 366 + v = sect_size[sect_in[mod_sect]]; 367 + if (mod_eoff > v) 368 + update_entry(mod_sect, mod_name, mod_soff, v); 369 + } 370 + } 371 + 372 + mod_name = mod; 373 + 374 + # If we encountered an object that is not part of a built-in module, we 375 + # do not need to record any data. 376 + if (!mod) 377 + next; 378 + 379 + # At this point, we encountered the start of a new built-in module. 380 + mod_name = mod; 381 + mod_soff = soff; 382 + mod_eoff = eoff; 383 + mod_sect = $1; 384 + update_entry($1, mod, soff, mod_eoff); 385 + 386 + next; 387 + } 388 + 389 + # If we do not need to parse the vmlinux.o.map file, we are done. 390 + # 391 + ARGIND == 3 && !need_o_map { 392 + if (dbg) 393 + printf "Note: %s is not needed.\n", FILENAME >"/dev/stderr"; 394 + exit; 395 + } 396 + 397 + # (3) Collect offset ranges (relative to the section base address) for built-in 398 + # modules. 399 + # 400 + 401 + # (LLD) Convert an object record from lld format to ld format. 402 + # 403 + ARGIND == 3 && map_is_lld && NF == 5 && $5 ~ /:\(/ { 404 + gsub(/\)/, ""); 405 + sub(/:\(/, " "); 406 + 407 + sect = $6; 408 + if (!(sect in sect_addend)) 409 + next; 410 + 411 + sub(/ vmlinux\.a\(/, " "); 412 + $0 = " "sect " 0x"$1 " 0x"$3 " " $5; 413 + } 414 + 415 + # (3b) Determine offset range info using vmlinux.o.map. 416 + # 417 + # If we do not know an addend for the object's section, we are interested in 418 + # anything within that section. 419 + # 420 + # Determine the top-level section that the object's section was included in 421 + # during the final link. This is the section name offset range data will be 422 + # associated with for this object. 423 + # 424 + # The remainder of the processing of the current object record follows the 425 + # procedure outlined in (3a). 426 + # 427 + ARGIND == 3 && /^ [^ ]/ && NF == 4 && $3 != "0x0" { 428 + osect = $1; 429 + if (!(osect in sect_addend)) 430 + next; 431 + 432 + # We need to work with the main section. 433 + sect = sect_in[osect]; 434 + 435 + # Turn the address into an offset from the section base. 436 + soff = $2; 437 + sub(addr_prefix, "0x", soff); 438 + soff = strtonum(soff) + sect_addend[osect]; 439 + eoff = soff + strtonum($3); 440 + 441 + # Determine which (if any) built-in modules the object belongs to. 442 + mod = get_module_info($4); 443 + 444 + # If we are processing a built-in module: 445 + # - If the current object is within the same module, we update its 446 + # entry by extending the range and move on 447 + # - Otherwise: 448 + # + If we are still processing within the same main section, we 449 + # validate the end offset against the start offset of the 450 + # current object (e.g. .rodata.str1.[18] objects are often 451 + # listed with an incorrect size in the linker map) 452 + # + Otherwise, we validate the end offset against the section 453 + # size 454 + if (mod_name) { 455 + if (mod == mod_name) { 456 + mod_eoff = eoff; 457 + update_entry(mod_sect, mod_name, mod_soff, eoff); 458 + 459 + next; 460 + } else if (sect == sect_in[mod_sect]) { 461 + if (mod_eoff > soff) 462 + update_entry(mod_sect, mod_name, mod_soff, soff); 463 + } else { 464 + v = sect_size[sect_in[mod_sect]]; 465 + if (mod_eoff > v) 466 + update_entry(mod_sect, mod_name, mod_soff, v); 467 + } 468 + } 469 + 470 + mod_name = mod; 471 + 472 + # If we encountered an object that is not part of a built-in module, we 473 + # do not need to record any data. 474 + if (!mod) 475 + next; 476 + 477 + # At this point, we encountered the start of a new built-in module. 478 + mod_name = mod; 479 + mod_soff = soff; 480 + mod_eoff = eoff; 481 + mod_sect = osect; 482 + update_entry(osect, mod, soff, mod_eoff); 483 + 484 + next; 485 + } 486 + 487 + # (4) Generate the output. 488 + # 489 + # Anchor records are added for each section that contains offset range data 490 + # records. They are added at an adjusted section base address (base << 1) to 491 + # ensure they come first in the second records (see update_entry() above for 492 + # more information). 493 + # 494 + # All entries are sorted by (adjusted) address to ensure that the output can be 495 + # parsed in strict ascending address order. 496 + # 497 + END { 498 + for (sect in count) { 499 + if (sect in sect_anchor) { 500 + idx = sprintf("%016x", sect_base[sect] * 2); 501 + entries[idx] = sect_anchor[sect]; 502 + } 503 + } 504 + 505 + n = asorti(entries, indices); 506 + for (i = 1; i <= n; i++) 507 + print entries[indices[i]]; 508 + }
+28
scripts/include/hash.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + #ifndef HASH_H 3 + #define HASH_H 4 + 5 + static inline unsigned int hash_str(const char *s) 6 + { 7 + /* fnv32 hash */ 8 + unsigned int hash = 2166136261U; 9 + 10 + for (; *s; s++) 11 + hash = (hash ^ *s) * 0x01000193; 12 + return hash; 13 + } 14 + 15 + /* simplified version of functions from include/linux/hash.h */ 16 + #define GOLDEN_RATIO_32 0x61C88647 17 + 18 + static inline unsigned int hash_32(unsigned int val) 19 + { 20 + return 0x61C88647 * val; 21 + } 22 + 23 + static inline unsigned int hash_ptr(const void *ptr) 24 + { 25 + return hash_32((unsigned int)(unsigned long)ptr); 26 + } 27 + 28 + #endif /* HASH_H */
+50
scripts/include/hashtable.h
··· 15 15 16 16 #define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)]) 17 17 18 + static inline void __hash_init(struct hlist_head *ht, unsigned int sz) 19 + { 20 + unsigned int i; 21 + 22 + for (i = 0; i < sz; i++) 23 + INIT_HLIST_HEAD(&ht[i]); 24 + } 25 + 26 + /** 27 + * hash_init - initialize a hash table 28 + * @table: hashtable to be initialized 29 + * 30 + * This has to be a macro since HASH_SIZE() will not work on pointers since 31 + * it calculates the size during preprocessing. 32 + */ 33 + #define hash_init(table) __hash_init(table, HASH_SIZE(table)) 34 + 18 35 /** 19 36 * hash_add - add an object to a hashtable 20 37 * @table: hashtable to add to ··· 40 23 */ 41 24 #define hash_add(table, node, key) \ 42 25 hlist_add_head(node, hash_head(table, key)) 26 + 27 + /** 28 + * hash_del - remove an object from a hashtable 29 + * @node: &struct hlist_node of the object to remove 30 + */ 31 + static inline void hash_del(struct hlist_node *node) 32 + { 33 + hlist_del_init(node); 34 + } 43 35 44 36 /** 45 37 * hash_for_each - iterate over a hashtable ··· 61 35 hlist_for_each_entry(obj, &table[_bkt], member) 62 36 63 37 /** 38 + * hash_for_each_safe - iterate over a hashtable safe against removal of 39 + * hash entry 40 + * @table: hashtable to iterate 41 + * @obj: the type * to use as a loop cursor for each entry 42 + * @tmp: a &struct hlist_node used for temporary storage 43 + * @member: the name of the hlist_node within the struct 44 + */ 45 + #define hash_for_each_safe(table, obj, tmp, member) \ 46 + for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \ 47 + hlist_for_each_entry_safe(obj, tmp, &table[_bkt], member) 48 + 49 + /** 64 50 * hash_for_each_possible - iterate over all possible objects hashing to the 65 51 * same bucket 66 52 * @table: hashtable to iterate ··· 82 44 */ 83 45 #define hash_for_each_possible(table, obj, member, key) \ 84 46 hlist_for_each_entry(obj, hash_head(table, key), member) 47 + 48 + /** 49 + * hash_for_each_possible_safe - iterate over all possible objects hashing to the 50 + * same bucket safe against removals 51 + * @table: hashtable to iterate 52 + * @obj: the type * to use as a loop cursor for each entry 53 + * @tmp: a &struct hlist_node used for temporary storage 54 + * @member: the name of the hlist_node within the struct 55 + * @key: the key of the objects to iterate over 56 + */ 57 + #define hash_for_each_possible_safe(table, obj, tmp, member, key) \ 58 + hlist_for_each_entry_safe(obj, tmp, hash_head(table, key), member) 85 59 86 60 #endif /* HASHTABLE_H */
+69
scripts/include/list.h
··· 268 268 */ 269 269 270 270 #define HLIST_HEAD_INIT { .first = NULL } 271 + #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) 272 + static inline void INIT_HLIST_NODE(struct hlist_node *h) 273 + { 274 + h->next = NULL; 275 + h->pprev = NULL; 276 + } 277 + 278 + /** 279 + * hlist_unhashed - Has node been removed from list and reinitialized? 280 + * @h: Node to be checked 281 + * 282 + * Not that not all removal functions will leave a node in unhashed 283 + * state. For example, hlist_nulls_del_init_rcu() does leave the 284 + * node in unhashed state, but hlist_nulls_del() does not. 285 + */ 286 + static inline int hlist_unhashed(const struct hlist_node *h) 287 + { 288 + return !h->pprev; 289 + } 290 + 291 + static inline void __hlist_del(struct hlist_node *n) 292 + { 293 + struct hlist_node *next = n->next; 294 + struct hlist_node **pprev = n->pprev; 295 + 296 + *pprev = next; 297 + if (next) 298 + next->pprev = pprev; 299 + } 300 + 301 + /** 302 + * hlist_del - Delete the specified hlist_node from its list 303 + * @n: Node to delete. 304 + * 305 + * Note that this function leaves the node in hashed state. Use 306 + * hlist_del_init() or similar instead to unhash @n. 307 + */ 308 + static inline void hlist_del(struct hlist_node *n) 309 + { 310 + __hlist_del(n); 311 + n->next = LIST_POISON1; 312 + n->pprev = LIST_POISON2; 313 + } 314 + 315 + /** 316 + * hlist_del_init - Delete the specified hlist_node from its list and initialize 317 + * @n: Node to delete. 318 + * 319 + * Note that this function leaves the node in unhashed state. 320 + */ 321 + static inline void hlist_del_init(struct hlist_node *n) 322 + { 323 + if (!hlist_unhashed(n)) { 324 + __hlist_del(n); 325 + INIT_HLIST_NODE(n); 326 + } 327 + } 271 328 272 329 /** 273 330 * hlist_add_head - add a new entry at the beginning of the hlist ··· 362 305 for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ 363 306 pos; \ 364 307 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) 308 + 309 + /** 310 + * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry 311 + * @pos: the type * to use as a loop cursor. 312 + * @n: a &struct hlist_node to use as temporary storage 313 + * @head: the head for your list. 314 + * @member: the name of the hlist_node within the struct. 315 + */ 316 + #define hlist_for_each_entry_safe(pos, n, head, member) \ 317 + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ 318 + pos && ({ n = pos->member.next; 1; }); \ 319 + pos = hlist_entry_safe(n, typeof(*pos), member)) 365 320 366 321 #endif /* LIST_H */
+53
scripts/include/xalloc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + #ifndef XALLOC_H 4 + #define XALLOC_H 5 + 6 + #include <stdlib.h> 7 + #include <string.h> 8 + 9 + static inline void *xmalloc(size_t size) 10 + { 11 + void *p = malloc(size); 12 + 13 + if (!p) 14 + exit(1); 15 + return p; 16 + } 17 + 18 + static inline void *xcalloc(size_t nmemb, size_t size) 19 + { 20 + void *p = calloc(nmemb, size); 21 + 22 + if (!p) 23 + exit(1); 24 + return p; 25 + } 26 + 27 + static inline void *xrealloc(void *p, size_t size) 28 + { 29 + p = realloc(p, size); 30 + if (!p) 31 + exit(1); 32 + return p; 33 + } 34 + 35 + static inline char *xstrdup(const char *s) 36 + { 37 + char *p = strdup(s); 38 + 39 + if (!p) 40 + exit(1); 41 + return p; 42 + } 43 + 44 + static inline char *xstrndup(const char *s, size_t n) 45 + { 46 + char *p = strndup(s, n); 47 + 48 + if (!p) 49 + exit(1); 50 + return p; 51 + } 52 + 53 + #endif /* XALLOC_H */
+14 -32
scripts/kallsyms.c
··· 27 27 #include <ctype.h> 28 28 #include <limits.h> 29 29 30 + #include <xalloc.h> 31 + 30 32 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) 31 33 32 34 #define KSYM_NAME_LEN 512 ··· 170 168 * compressed together */ 171 169 len++; 172 170 173 - sym = malloc(sizeof(*sym) + len + 1); 174 - if (!sym) { 175 - fprintf(stderr, "kallsyms failure: " 176 - "unable to allocate required amount of memory\n"); 177 - exit(EXIT_FAILURE); 178 - } 171 + sym = xmalloc(sizeof(*sym) + len + 1); 179 172 sym->addr = addr; 180 173 sym->len = len; 181 174 sym->sym[0] = type; ··· 275 278 276 279 if (table_cnt >= table_size) { 277 280 table_size += 10000; 278 - table = realloc(table, sizeof(*table) * table_size); 279 - if (!table) { 280 - fprintf(stderr, "out of memory\n"); 281 - fclose(fp); 282 - exit (1); 283 - } 281 + table = xrealloc(table, sizeof(*table) * table_size); 284 282 } 285 283 286 284 table[table_cnt++] = sym; ··· 290 298 printf(".globl %s\n", label); 291 299 printf("\tALGN\n"); 292 300 printf("%s:\n", label); 293 - } 294 - 295 - /* Provide proper symbols relocatability by their '_text' relativeness. */ 296 - static void output_address(unsigned long long addr) 297 - { 298 - if (_text <= addr) 299 - printf("\tPTR\t_text + %#llx\n", addr - _text); 300 - else 301 - printf("\tPTR\t_text - %#llx\n", _text - addr); 302 301 } 303 302 304 303 /* uncompress a compressed symbol. When this function is called, the best table ··· 374 391 /* table of offset markers, that give the offset in the compressed stream 375 392 * every 256 symbols */ 376 393 markers_cnt = (table_cnt + 255) / 256; 377 - markers = malloc(sizeof(*markers) * markers_cnt); 378 - if (!markers) { 379 - fprintf(stderr, "kallsyms failure: " 380 - "unable to allocate required memory\n"); 381 - exit(EXIT_FAILURE); 382 - } 394 + markers = xmalloc(sizeof(*markers) * markers_cnt); 383 395 384 396 output_label("kallsyms_names"); 385 397 off = 0; ··· 455 477 */ 456 478 457 479 long long offset; 458 - int overflow; 480 + bool overflow; 459 481 460 482 if (!absolute_percpu) { 461 483 offset = table[i]->addr - relative_base; 462 - overflow = (offset < 0 || offset > UINT_MAX); 484 + overflow = offset < 0 || offset > UINT_MAX; 463 485 } else if (symbol_absolute(table[i])) { 464 486 offset = table[i]->addr; 465 - overflow = (offset < 0 || offset > INT_MAX); 487 + overflow = offset < 0 || offset > INT_MAX; 466 488 } else { 467 489 offset = relative_base - table[i]->addr - 1; 468 - overflow = (offset < INT_MIN || offset >= 0); 490 + overflow = offset < INT_MIN || offset >= 0; 469 491 } 470 492 if (overflow) { 471 493 fprintf(stderr, "kallsyms failure: " ··· 479 501 printf("\n"); 480 502 481 503 output_label("kallsyms_relative_base"); 482 - output_address(relative_base); 504 + /* Provide proper symbols relocatability by their '_text' relativeness. */ 505 + if (_text <= relative_base) 506 + printf("\tPTR\t_text + %#llx\n", relative_base - _text); 507 + else 508 + printf("\tPTR\t_text - %#llx\n", _text - relative_base); 483 509 printf("\n"); 484 510 485 511 sort_symbols_by_name();
+3
scripts/kconfig/confdata.c
··· 18 18 #include <time.h> 19 19 #include <unistd.h> 20 20 21 + #include <xalloc.h> 21 22 #include "internal.h" 22 23 #include "lkc.h" 23 24 ··· 395 394 sym->def[def].tri = no; 396 395 } 397 396 } 397 + 398 + expr_invalidate_all(); 398 399 399 400 while (getline_stripped(&line, &line_asize, in) != -1) { 400 401 struct menu *choice;
+207 -275
scripts/kconfig/expr.c
··· 9 9 #include <stdlib.h> 10 10 #include <string.h> 11 11 12 + #include <hash.h> 13 + #include <xalloc.h> 14 + #include "internal.h" 12 15 #include "lkc.h" 13 16 14 17 #define DEBUG_EXPR 0 15 18 19 + HASHTABLE_DEFINE(expr_hashtable, EXPR_HASHSIZE); 20 + 16 21 static struct expr *expr_eliminate_yn(struct expr *e); 22 + 23 + /** 24 + * expr_lookup - return the expression with the given type and sub-nodes 25 + * This looks up an expression with the specified type and sub-nodes. If such 26 + * an expression is found in the hash table, it is returned. Otherwise, a new 27 + * expression node is allocated and added to the hash table. 28 + * @type: expression type 29 + * @l: left node 30 + * @r: right node 31 + * return: expression 32 + */ 33 + static struct expr *expr_lookup(enum expr_type type, void *l, void *r) 34 + { 35 + struct expr *e; 36 + int hash; 37 + 38 + hash = hash_32((unsigned int)type ^ hash_ptr(l) ^ hash_ptr(r)); 39 + 40 + hash_for_each_possible(expr_hashtable, e, node, hash) { 41 + if (e->type == type && e->left._initdata == l && 42 + e->right._initdata == r) 43 + return e; 44 + } 45 + 46 + e = xmalloc(sizeof(*e)); 47 + e->type = type; 48 + e->left._initdata = l; 49 + e->right._initdata = r; 50 + 51 + hash_add(expr_hashtable, &e->node, hash); 52 + 53 + return e; 54 + } 17 55 18 56 struct expr *expr_alloc_symbol(struct symbol *sym) 19 57 { 20 - struct expr *e = xcalloc(1, sizeof(*e)); 21 - e->type = E_SYMBOL; 22 - e->left.sym = sym; 23 - return e; 58 + return expr_lookup(E_SYMBOL, sym, NULL); 24 59 } 25 60 26 61 struct expr *expr_alloc_one(enum expr_type type, struct expr *ce) 27 62 { 28 - struct expr *e = xcalloc(1, sizeof(*e)); 29 - e->type = type; 30 - e->left.expr = ce; 31 - return e; 63 + return expr_lookup(type, ce, NULL); 32 64 } 33 65 34 66 struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2) 35 67 { 36 - struct expr *e = xcalloc(1, sizeof(*e)); 37 - e->type = type; 38 - e->left.expr = e1; 39 - e->right.expr = e2; 40 - return e; 68 + return expr_lookup(type, e1, e2); 41 69 } 42 70 43 71 struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2) 44 72 { 45 - struct expr *e = xcalloc(1, sizeof(*e)); 46 - e->type = type; 47 - e->left.sym = s1; 48 - e->right.sym = s2; 49 - return e; 73 + return expr_lookup(type, s1, s2); 50 74 } 51 75 52 76 struct expr *expr_alloc_and(struct expr *e1, struct expr *e2) ··· 87 63 return e2 ? expr_alloc_two(E_OR, e1, e2) : e1; 88 64 } 89 65 90 - struct expr *expr_copy(const struct expr *org) 91 - { 92 - struct expr *e; 93 - 94 - if (!org) 95 - return NULL; 96 - 97 - e = xmalloc(sizeof(*org)); 98 - memcpy(e, org, sizeof(*org)); 99 - switch (org->type) { 100 - case E_SYMBOL: 101 - e->left = org->left; 102 - break; 103 - case E_NOT: 104 - e->left.expr = expr_copy(org->left.expr); 105 - break; 106 - case E_EQUAL: 107 - case E_GEQ: 108 - case E_GTH: 109 - case E_LEQ: 110 - case E_LTH: 111 - case E_UNEQUAL: 112 - e->left.sym = org->left.sym; 113 - e->right.sym = org->right.sym; 114 - break; 115 - case E_AND: 116 - case E_OR: 117 - e->left.expr = expr_copy(org->left.expr); 118 - e->right.expr = expr_copy(org->right.expr); 119 - break; 120 - default: 121 - fprintf(stderr, "can't copy type %d\n", e->type); 122 - free(e); 123 - e = NULL; 124 - break; 125 - } 126 - 127 - return e; 128 - } 129 - 130 - void expr_free(struct expr *e) 131 - { 132 - if (!e) 133 - return; 134 - 135 - switch (e->type) { 136 - case E_SYMBOL: 137 - break; 138 - case E_NOT: 139 - expr_free(e->left.expr); 140 - break; 141 - case E_EQUAL: 142 - case E_GEQ: 143 - case E_GTH: 144 - case E_LEQ: 145 - case E_LTH: 146 - case E_UNEQUAL: 147 - break; 148 - case E_OR: 149 - case E_AND: 150 - expr_free(e->left.expr); 151 - expr_free(e->right.expr); 152 - break; 153 - default: 154 - fprintf(stderr, "how to free type %d?\n", e->type); 155 - break; 156 - } 157 - free(e); 158 - } 159 - 160 66 static int trans_count; 161 67 162 68 /* ··· 99 145 */ 100 146 static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct expr **ep2) 101 147 { 148 + struct expr *l, *r; 149 + 102 150 /* Recurse down to leaves */ 103 151 104 152 if ((*ep1)->type == type) { 105 - __expr_eliminate_eq(type, &(*ep1)->left.expr, ep2); 106 - __expr_eliminate_eq(type, &(*ep1)->right.expr, ep2); 153 + l = (*ep1)->left.expr; 154 + r = (*ep1)->right.expr; 155 + __expr_eliminate_eq(type, &l, ep2); 156 + __expr_eliminate_eq(type, &r, ep2); 157 + *ep1 = expr_alloc_two(type, l, r); 107 158 return; 108 159 } 109 160 if ((*ep2)->type == type) { 110 - __expr_eliminate_eq(type, ep1, &(*ep2)->left.expr); 111 - __expr_eliminate_eq(type, ep1, &(*ep2)->right.expr); 161 + l = (*ep2)->left.expr; 162 + r = (*ep2)->right.expr; 163 + __expr_eliminate_eq(type, ep1, &l); 164 + __expr_eliminate_eq(type, ep1, &r); 165 + *ep2 = expr_alloc_two(type, l, r); 112 166 return; 113 167 } 114 168 ··· 132 170 /* *ep1 and *ep2 are equal leaves. Prepare them for elimination. */ 133 171 134 172 trans_count++; 135 - expr_free(*ep1); expr_free(*ep2); 136 173 switch (type) { 137 174 case E_OR: 138 175 *ep1 = expr_alloc_symbol(&symbol_no); ··· 203 242 * equals some operand in the other (operands do not need to appear in the same 204 243 * order), recursively. 205 244 */ 206 - int expr_eq(struct expr *e1, struct expr *e2) 245 + bool expr_eq(struct expr *e1, struct expr *e2) 207 246 { 208 - int res, old_count; 247 + int old_count; 248 + bool res; 209 249 210 250 /* 211 251 * A NULL expr is taken to be yes, but there's also a different way to ··· 216 254 return expr_is_yes(e1) && expr_is_yes(e2); 217 255 218 256 if (e1->type != e2->type) 219 - return 0; 257 + return false; 220 258 switch (e1->type) { 221 259 case E_EQUAL: 222 260 case E_GEQ: ··· 231 269 return expr_eq(e1->left.expr, e2->left.expr); 232 270 case E_AND: 233 271 case E_OR: 234 - e1 = expr_copy(e1); 235 - e2 = expr_copy(e2); 236 272 old_count = trans_count; 237 273 expr_eliminate_eq(&e1, &e2); 238 274 res = (e1->type == E_SYMBOL && e2->type == E_SYMBOL && 239 275 e1->left.sym == e2->left.sym); 240 - expr_free(e1); 241 - expr_free(e2); 242 276 trans_count = old_count; 243 277 return res; 244 278 case E_RANGE: ··· 249 291 printf(" ?\n"); 250 292 } 251 293 252 - return 0; 294 + return false; 253 295 } 254 296 255 297 /* 256 - * Recursively performs the following simplifications in-place (as well as the 298 + * Recursively performs the following simplifications (as well as the 257 299 * corresponding simplifications with swapped operands): 258 300 * 259 301 * expr && n -> n ··· 265 307 */ 266 308 static struct expr *expr_eliminate_yn(struct expr *e) 267 309 { 268 - struct expr *tmp; 310 + struct expr *l, *r; 269 311 270 312 if (e) switch (e->type) { 271 313 case E_AND: 272 - e->left.expr = expr_eliminate_yn(e->left.expr); 273 - e->right.expr = expr_eliminate_yn(e->right.expr); 274 - if (e->left.expr->type == E_SYMBOL) { 275 - if (e->left.expr->left.sym == &symbol_no) { 276 - expr_free(e->left.expr); 277 - expr_free(e->right.expr); 278 - e->type = E_SYMBOL; 279 - e->left.sym = &symbol_no; 280 - e->right.expr = NULL; 281 - return e; 282 - } else if (e->left.expr->left.sym == &symbol_yes) { 283 - free(e->left.expr); 284 - tmp = e->right.expr; 285 - *e = *(e->right.expr); 286 - free(tmp); 287 - return e; 288 - } 314 + l = expr_eliminate_yn(e->left.expr); 315 + r = expr_eliminate_yn(e->right.expr); 316 + if (l->type == E_SYMBOL) { 317 + if (l->left.sym == &symbol_no) 318 + return l; 319 + else if (l->left.sym == &symbol_yes) 320 + return r; 289 321 } 290 - if (e->right.expr->type == E_SYMBOL) { 291 - if (e->right.expr->left.sym == &symbol_no) { 292 - expr_free(e->left.expr); 293 - expr_free(e->right.expr); 294 - e->type = E_SYMBOL; 295 - e->left.sym = &symbol_no; 296 - e->right.expr = NULL; 297 - return e; 298 - } else if (e->right.expr->left.sym == &symbol_yes) { 299 - free(e->right.expr); 300 - tmp = e->left.expr; 301 - *e = *(e->left.expr); 302 - free(tmp); 303 - return e; 304 - } 322 + if (r->type == E_SYMBOL) { 323 + if (r->left.sym == &symbol_no) 324 + return r; 325 + else if (r->left.sym == &symbol_yes) 326 + return l; 305 327 } 306 328 break; 307 329 case E_OR: 308 - e->left.expr = expr_eliminate_yn(e->left.expr); 309 - e->right.expr = expr_eliminate_yn(e->right.expr); 310 - if (e->left.expr->type == E_SYMBOL) { 311 - if (e->left.expr->left.sym == &symbol_no) { 312 - free(e->left.expr); 313 - tmp = e->right.expr; 314 - *e = *(e->right.expr); 315 - free(tmp); 316 - return e; 317 - } else if (e->left.expr->left.sym == &symbol_yes) { 318 - expr_free(e->left.expr); 319 - expr_free(e->right.expr); 320 - e->type = E_SYMBOL; 321 - e->left.sym = &symbol_yes; 322 - e->right.expr = NULL; 323 - return e; 324 - } 330 + l = expr_eliminate_yn(e->left.expr); 331 + r = expr_eliminate_yn(e->right.expr); 332 + if (l->type == E_SYMBOL) { 333 + if (l->left.sym == &symbol_no) 334 + return r; 335 + else if (l->left.sym == &symbol_yes) 336 + return l; 325 337 } 326 - if (e->right.expr->type == E_SYMBOL) { 327 - if (e->right.expr->left.sym == &symbol_no) { 328 - free(e->right.expr); 329 - tmp = e->left.expr; 330 - *e = *(e->left.expr); 331 - free(tmp); 332 - return e; 333 - } else if (e->right.expr->left.sym == &symbol_yes) { 334 - expr_free(e->left.expr); 335 - expr_free(e->right.expr); 336 - e->type = E_SYMBOL; 337 - e->left.sym = &symbol_yes; 338 - e->right.expr = NULL; 339 - return e; 340 - } 338 + if (r->type == E_SYMBOL) { 339 + if (r->left.sym == &symbol_no) 340 + return l; 341 + else if (r->left.sym == &symbol_yes) 342 + return r; 341 343 } 342 344 break; 343 345 default: ··· 315 397 struct symbol *sym1, *sym2; 316 398 317 399 if (expr_eq(e1, e2)) 318 - return expr_copy(e1); 400 + return e1; 319 401 if (e1->type != E_EQUAL && e1->type != E_UNEQUAL && e1->type != E_SYMBOL && e1->type != E_NOT) 320 402 return NULL; 321 403 if (e2->type != E_EQUAL && e2->type != E_UNEQUAL && e2->type != E_SYMBOL && e2->type != E_NOT) ··· 358 440 } 359 441 } 360 442 if (sym1->type == S_BOOLEAN) { 443 + // a || !a -> y 361 444 if ((e1->type == E_NOT && e1->left.expr->type == E_SYMBOL && e2->type == E_SYMBOL) || 362 445 (e2->type == E_NOT && e2->left.expr->type == E_SYMBOL && e1->type == E_SYMBOL)) 363 446 return expr_alloc_symbol(&symbol_yes); ··· 380 461 struct symbol *sym1, *sym2; 381 462 382 463 if (expr_eq(e1, e2)) 383 - return expr_copy(e1); 464 + return e1; 384 465 if (e1->type != E_EQUAL && e1->type != E_UNEQUAL && e1->type != E_SYMBOL && e1->type != E_NOT) 385 466 return NULL; 386 467 if (e2->type != E_EQUAL && e2->type != E_UNEQUAL && e2->type != E_SYMBOL && e2->type != E_NOT) ··· 477 558 */ 478 559 static void expr_eliminate_dups1(enum expr_type type, struct expr **ep1, struct expr **ep2) 479 560 { 480 - struct expr *tmp; 561 + struct expr *tmp, *l, *r; 481 562 482 563 /* Recurse down to leaves */ 483 564 484 565 if ((*ep1)->type == type) { 485 - expr_eliminate_dups1(type, &(*ep1)->left.expr, ep2); 486 - expr_eliminate_dups1(type, &(*ep1)->right.expr, ep2); 566 + l = (*ep1)->left.expr; 567 + r = (*ep1)->right.expr; 568 + expr_eliminate_dups1(type, &l, ep2); 569 + expr_eliminate_dups1(type, &r, ep2); 570 + *ep1 = expr_alloc_two(type, l, r); 487 571 return; 488 572 } 489 573 if ((*ep2)->type == type) { 490 - expr_eliminate_dups1(type, ep1, &(*ep2)->left.expr); 491 - expr_eliminate_dups1(type, ep1, &(*ep2)->right.expr); 574 + l = (*ep2)->left.expr; 575 + r = (*ep2)->right.expr; 576 + expr_eliminate_dups1(type, ep1, &l); 577 + expr_eliminate_dups1(type, ep1, &r); 578 + *ep2 = expr_alloc_two(type, l, r); 492 579 return; 493 580 } 494 581 495 582 /* *ep1 and *ep2 are leaves. Compare and process them. */ 496 583 497 - if (*ep1 == *ep2) 498 - return; 499 - 500 - switch ((*ep1)->type) { 501 - case E_OR: case E_AND: 502 - expr_eliminate_dups1((*ep1)->type, ep1, ep1); 503 - default: 504 - ; 505 - } 506 - 507 584 switch (type) { 508 585 case E_OR: 509 586 tmp = expr_join_or(*ep1, *ep2); 510 587 if (tmp) { 511 - expr_free(*ep1); expr_free(*ep2); 512 588 *ep1 = expr_alloc_symbol(&symbol_no); 513 589 *ep2 = tmp; 514 590 trans_count++; ··· 512 598 case E_AND: 513 599 tmp = expr_join_and(*ep1, *ep2); 514 600 if (tmp) { 515 - expr_free(*ep1); expr_free(*ep2); 516 601 *ep1 = expr_alloc_symbol(&symbol_yes); 517 602 *ep2 = tmp; 518 603 trans_count++; ··· 541 628 542 629 oldcount = trans_count; 543 630 do { 631 + struct expr *l, *r; 632 + 544 633 trans_count = 0; 545 634 switch (e->type) { 546 635 case E_OR: case E_AND: 547 - expr_eliminate_dups1(e->type, &e, &e); 636 + l = expr_eliminate_dups(e->left.expr); 637 + r = expr_eliminate_dups(e->right.expr); 638 + expr_eliminate_dups1(e->type, &l, &r); 639 + e = expr_alloc_two(e->type, l, r); 548 640 default: 549 641 ; 550 642 } ··· 563 645 * Performs various simplifications involving logical operators and 564 646 * comparisons. 565 647 * 648 + * For bool type: 649 + * A=n -> !A 650 + * A=m -> n 651 + * A=y -> A 652 + * A!=n -> A 653 + * A!=m -> y 654 + * A!=y -> !A 655 + * 656 + * For any type: 657 + * !!A -> A 658 + * !(A=B) -> A!=B 659 + * !(A!=B) -> A=B 660 + * !(A<=B) -> A>B 661 + * !(A>=B) -> A<B 662 + * !(A<B) -> A>=B 663 + * !(A>B) -> A<=B 664 + * !(A || B) -> !A && !B 665 + * !(A && B) -> !A || !B 666 + * 667 + * For constant: 668 + * !y -> n 669 + * !m -> m 670 + * !n -> y 671 + * 566 672 * Allocates and returns a new expression. 567 673 */ 568 674 struct expr *expr_transform(struct expr *e) 569 675 { 570 - struct expr *tmp; 571 - 572 676 if (!e) 573 677 return NULL; 574 678 switch (e->type) { ··· 603 663 case E_SYMBOL: 604 664 break; 605 665 default: 606 - e->left.expr = expr_transform(e->left.expr); 607 - e->right.expr = expr_transform(e->right.expr); 666 + e = expr_alloc_two(e->type, 667 + expr_transform(e->left.expr), 668 + expr_transform(e->right.expr)); 608 669 } 609 670 610 671 switch (e->type) { ··· 613 672 if (e->left.sym->type != S_BOOLEAN) 614 673 break; 615 674 if (e->right.sym == &symbol_no) { 616 - e->type = E_NOT; 617 - e->left.expr = expr_alloc_symbol(e->left.sym); 618 - e->right.sym = NULL; 675 + // A=n -> !A 676 + e = expr_alloc_one(E_NOT, expr_alloc_symbol(e->left.sym)); 619 677 break; 620 678 } 621 679 if (e->right.sym == &symbol_mod) { 680 + // A=m -> n 622 681 printf("boolean symbol %s tested for 'm'? test forced to 'n'\n", e->left.sym->name); 623 - e->type = E_SYMBOL; 624 - e->left.sym = &symbol_no; 625 - e->right.sym = NULL; 682 + e = expr_alloc_symbol(&symbol_no); 626 683 break; 627 684 } 628 685 if (e->right.sym == &symbol_yes) { 629 - e->type = E_SYMBOL; 630 - e->right.sym = NULL; 686 + // A=y -> A 687 + e = expr_alloc_symbol(e->left.sym); 631 688 break; 632 689 } 633 690 break; ··· 633 694 if (e->left.sym->type != S_BOOLEAN) 634 695 break; 635 696 if (e->right.sym == &symbol_no) { 636 - e->type = E_SYMBOL; 637 - e->right.sym = NULL; 697 + // A!=n -> A 698 + e = expr_alloc_symbol(e->left.sym); 638 699 break; 639 700 } 640 701 if (e->right.sym == &symbol_mod) { 702 + // A!=m -> y 641 703 printf("boolean symbol %s tested for 'm'? test forced to 'y'\n", e->left.sym->name); 642 - e->type = E_SYMBOL; 643 - e->left.sym = &symbol_yes; 644 - e->right.sym = NULL; 704 + e = expr_alloc_symbol(&symbol_yes); 645 705 break; 646 706 } 647 707 if (e->right.sym == &symbol_yes) { 648 - e->type = E_NOT; 649 - e->left.expr = expr_alloc_symbol(e->left.sym); 650 - e->right.sym = NULL; 708 + // A!=y -> !A 709 + e = expr_alloc_one(E_NOT, e->left.expr); 651 710 break; 652 711 } 653 712 break; 654 713 case E_NOT: 655 714 switch (e->left.expr->type) { 656 715 case E_NOT: 657 - // !!a -> a 658 - tmp = e->left.expr->left.expr; 659 - free(e->left.expr); 660 - free(e); 661 - e = tmp; 662 - e = expr_transform(e); 716 + // !!A -> A 717 + e = e->left.expr->left.expr; 663 718 break; 664 719 case E_EQUAL: 665 720 case E_UNEQUAL: 666 - // !a='x' -> a!='x' 667 - tmp = e->left.expr; 668 - free(e); 669 - e = tmp; 670 - e->type = e->type == E_EQUAL ? E_UNEQUAL : E_EQUAL; 721 + // !(A=B) -> A!=B 722 + e = expr_alloc_comp(e->left.expr->type == E_EQUAL ? E_UNEQUAL : E_EQUAL, 723 + e->left.expr->left.sym, 724 + e->left.expr->right.sym); 671 725 break; 672 726 case E_LEQ: 673 727 case E_GEQ: 674 - // !a<='x' -> a>'x' 675 - tmp = e->left.expr; 676 - free(e); 677 - e = tmp; 678 - e->type = e->type == E_LEQ ? E_GTH : E_LTH; 728 + // !(A<=B) -> A>B 729 + e = expr_alloc_comp(e->left.expr->type == E_LEQ ? E_GTH : E_LTH, 730 + e->left.expr->left.sym, 731 + e->left.expr->right.sym); 679 732 break; 680 733 case E_LTH: 681 734 case E_GTH: 682 - // !a<'x' -> a>='x' 683 - tmp = e->left.expr; 684 - free(e); 685 - e = tmp; 686 - e->type = e->type == E_LTH ? E_GEQ : E_LEQ; 735 + // !(A<B) -> A>=B 736 + e = expr_alloc_comp(e->left.expr->type == E_LTH ? E_GEQ : E_LEQ, 737 + e->left.expr->left.sym, 738 + e->left.expr->right.sym); 687 739 break; 688 740 case E_OR: 689 - // !(a || b) -> !a && !b 690 - tmp = e->left.expr; 691 - e->type = E_AND; 692 - e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr); 693 - tmp->type = E_NOT; 694 - tmp->right.expr = NULL; 741 + // !(A || B) -> !A && !B 742 + e = expr_alloc_and(expr_alloc_one(E_NOT, e->left.expr->left.expr), 743 + expr_alloc_one(E_NOT, e->left.expr->right.expr)); 695 744 e = expr_transform(e); 696 745 break; 697 746 case E_AND: 698 - // !(a && b) -> !a || !b 699 - tmp = e->left.expr; 700 - e->type = E_OR; 701 - e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr); 702 - tmp->type = E_NOT; 703 - tmp->right.expr = NULL; 747 + // !(A && B) -> !A || !B 748 + e = expr_alloc_or(expr_alloc_one(E_NOT, e->left.expr->left.expr), 749 + expr_alloc_one(E_NOT, e->left.expr->right.expr)); 704 750 e = expr_transform(e); 705 751 break; 706 752 case E_SYMBOL: 707 - if (e->left.expr->left.sym == &symbol_yes) { 753 + if (e->left.expr->left.sym == &symbol_yes) 708 754 // !'y' -> 'n' 709 - tmp = e->left.expr; 710 - free(e); 711 - e = tmp; 712 - e->type = E_SYMBOL; 713 - e->left.sym = &symbol_no; 714 - break; 715 - } 716 - if (e->left.expr->left.sym == &symbol_mod) { 755 + e = expr_alloc_symbol(&symbol_no); 756 + else if (e->left.expr->left.sym == &symbol_mod) 717 757 // !'m' -> 'm' 718 - tmp = e->left.expr; 719 - free(e); 720 - e = tmp; 721 - e->type = E_SYMBOL; 722 - e->left.sym = &symbol_mod; 723 - break; 724 - } 725 - if (e->left.expr->left.sym == &symbol_no) { 758 + e = expr_alloc_symbol(&symbol_mod); 759 + else if (e->left.expr->left.sym == &symbol_no) 726 760 // !'n' -> 'y' 727 - tmp = e->left.expr; 728 - free(e); 729 - e = tmp; 730 - e->type = E_SYMBOL; 731 - e->left.sym = &symbol_yes; 732 - break; 733 - } 761 + e = expr_alloc_symbol(&symbol_yes); 734 762 break; 735 763 default: 736 764 ; ··· 709 803 return e; 710 804 } 711 805 712 - int expr_contains_symbol(struct expr *dep, struct symbol *sym) 806 + bool expr_contains_symbol(struct expr *dep, struct symbol *sym) 713 807 { 714 808 if (!dep) 715 - return 0; 809 + return false; 716 810 717 811 switch (dep->type) { 718 812 case E_AND: ··· 734 828 default: 735 829 ; 736 830 } 737 - return 0; 831 + return false; 738 832 } 739 833 740 834 bool expr_depends_symbol(struct expr *dep, struct symbol *sym) ··· 821 915 case E_EQUAL: 822 916 if (type == E_EQUAL) { 823 917 if (sym == &symbol_yes) 824 - return expr_copy(e); 918 + return e; 825 919 if (sym == &symbol_mod) 826 920 return expr_alloc_symbol(&symbol_no); 827 921 if (sym == &symbol_no) 828 - return expr_alloc_one(E_NOT, expr_copy(e)); 922 + return expr_alloc_one(E_NOT, e); 829 923 } else { 830 924 if (sym == &symbol_yes) 831 - return expr_alloc_one(E_NOT, expr_copy(e)); 925 + return expr_alloc_one(E_NOT, e); 832 926 if (sym == &symbol_mod) 833 927 return expr_alloc_symbol(&symbol_yes); 834 928 if (sym == &symbol_no) 835 - return expr_copy(e); 929 + return e; 836 930 } 837 931 break; 838 932 case E_SYMBOL: ··· 887 981 ? kind : k_string; 888 982 } 889 983 890 - tristate expr_calc_value(struct expr *e) 984 + static tristate __expr_calc_value(struct expr *e) 891 985 { 892 986 tristate val1, val2; 893 987 const char *str1, *str2; 894 988 enum string_value_kind k1 = k_string, k2 = k_string; 895 989 union string_value lval = {}, rval = {}; 896 990 int res; 897 - 898 - if (!e) 899 - return yes; 900 991 901 992 switch (e->type) { 902 993 case E_SYMBOL: ··· 956 1053 printf("expr_calc_value: relation %d?\n", e->type); 957 1054 return no; 958 1055 } 1056 + } 1057 + 1058 + /** 1059 + * expr_calc_value - return the tristate value of the given expression 1060 + * @e: expression 1061 + * return: tristate value of the expression 1062 + */ 1063 + tristate expr_calc_value(struct expr *e) 1064 + { 1065 + if (!e) 1066 + return yes; 1067 + 1068 + if (!e->val_is_valid) { 1069 + e->val = __expr_calc_value(e); 1070 + e->val_is_valid = true; 1071 + } 1072 + 1073 + return e->val; 1074 + } 1075 + 1076 + /** 1077 + * expr_invalidate_all - invalidate all cached expression values 1078 + */ 1079 + void expr_invalidate_all(void) 1080 + { 1081 + struct expr *e; 1082 + 1083 + hash_for_each(expr_hashtable, e, node) 1084 + e->val_is_valid = false; 959 1085 } 960 1086 961 1087 static int expr_compare_type(enum expr_type t1, enum expr_type t2)
+19 -8
scripts/kconfig/expr.h
··· 29 29 }; 30 30 31 31 union expr_data { 32 - struct expr *expr; 33 - struct symbol *sym; 32 + struct expr * const expr; 33 + struct symbol * const sym; 34 + void *_initdata; 34 35 }; 35 36 37 + /** 38 + * struct expr - expression 39 + * 40 + * @node: link node for the hash table 41 + * @type: expressoin type 42 + * @val: calculated tristate value 43 + * @val_is_valid: indicate whether the value is valid 44 + * @left: left node 45 + * @right: right node 46 + */ 36 47 struct expr { 48 + struct hlist_node node; 37 49 enum expr_type type; 50 + tristate val; 51 + bool val_is_valid; 38 52 union expr_data left, right; 39 53 }; 40 54 ··· 182 168 P_SELECT, /* select BAR */ 183 169 P_IMPLY, /* imply BAR */ 184 170 P_RANGE, /* range 7..100 (for a symbol) */ 185 - P_SYMBOL, /* where a symbol is defined */ 186 171 }; 187 172 188 173 struct property { ··· 289 276 struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2); 290 277 struct expr *expr_alloc_and(struct expr *e1, struct expr *e2); 291 278 struct expr *expr_alloc_or(struct expr *e1, struct expr *e2); 292 - struct expr *expr_copy(const struct expr *org); 293 - void expr_free(struct expr *e); 294 279 void expr_eliminate_eq(struct expr **ep1, struct expr **ep2); 295 - int expr_eq(struct expr *e1, struct expr *e2); 280 + bool expr_eq(struct expr *e1, struct expr *e2); 296 281 tristate expr_calc_value(struct expr *e); 297 282 struct expr *expr_eliminate_dups(struct expr *e); 298 283 struct expr *expr_transform(struct expr *e); 299 - int expr_contains_symbol(struct expr *dep, struct symbol *sym); 284 + bool expr_contains_symbol(struct expr *dep, struct symbol *sym); 300 285 bool expr_depends_symbol(struct expr *dep, struct symbol *sym); 301 286 struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym); 302 287 ··· 304 293 void expr_gstr_print_revdep(struct expr *e, struct gstr *gs, 305 294 tristate pr_type, const char *title); 306 295 307 - static inline int expr_is_yes(const struct expr *e) 296 + static inline bool expr_is_yes(const struct expr *e) 308 297 { 309 298 return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes); 310 299 }
+6
scripts/kconfig/internal.h
··· 11 11 #define for_all_symbols(sym) \ 12 12 hash_for_each(sym_hashtable, sym, node) 13 13 14 + #define EXPR_HASHSIZE (1U << 14) 15 + 16 + extern HASHTABLE_DECLARE(expr_hashtable, EXPR_HASHSIZE); 17 + 18 + void expr_invalidate_all(void); 19 + 14 20 struct menu; 15 21 16 22 extern struct menu *current_menu, *current_entry;
+1
scripts/kconfig/lexer.l
··· 13 13 #include <stdlib.h> 14 14 #include <string.h> 15 15 16 + #include <xalloc.h> 16 17 #include "lkc.h" 17 18 #include "preprocess.h" 18 19
-6
scripts/kconfig/lkc.h
··· 51 51 } 52 52 53 53 /* util.c */ 54 - unsigned int strhash(const char *s); 55 54 const char *file_lookup(const char *name); 56 - void *xmalloc(size_t size); 57 - void *xcalloc(size_t nmemb, size_t size); 58 - void *xrealloc(void *p, size_t size); 59 - char *xstrdup(const char *s); 60 - char *xstrndup(const char *s, size_t n); 61 55 62 56 /* lexer.l */ 63 57 int yylex(void);
+1
scripts/kconfig/mconf.c
··· 20 20 #include <unistd.h> 21 21 22 22 #include <list.h> 23 + #include <xalloc.h> 23 24 #include "lkc.h" 24 25 #include "lxdialog/dialog.h" 25 26 #include "mnconf-common.h"
+12 -26
scripts/kconfig/menu.c
··· 9 9 #include <string.h> 10 10 11 11 #include <list.h> 12 + #include <xalloc.h> 12 13 #include "lkc.h" 13 14 #include "internal.h" 14 15 ··· 79 78 *last_entry_ptr = menu; 80 79 last_entry_ptr = &menu->next; 81 80 current_entry = menu; 82 - if (sym) { 83 - menu_add_symbol(P_SYMBOL, sym, NULL); 81 + if (sym) 84 82 list_add_tail(&menu->link, &sym->menus); 85 - } 86 83 } 87 84 88 85 struct menu *menu_add_menu(void) ··· 107 108 108 109 switch (e->type) { 109 110 case E_NOT: 110 - e->left.expr = rewrite_m(e->left.expr); 111 + e = expr_alloc_one(E_NOT, rewrite_m(e->left.expr)); 111 112 break; 112 113 case E_OR: 113 114 case E_AND: 114 - e->left.expr = rewrite_m(e->left.expr); 115 - e->right.expr = rewrite_m(e->right.expr); 115 + e = expr_alloc_two(e->type, 116 + rewrite_m(e->left.expr), 117 + rewrite_m(e->right.expr)); 116 118 break; 117 119 case E_SYMBOL: 118 120 /* change 'm' into 'm' && MODULES */ ··· 193 193 struct menu *menu = current_entry; 194 194 195 195 while ((menu = menu->parent) != NULL) { 196 - struct expr *dup_expr; 197 196 198 197 if (!menu->visibility) 199 198 continue; 200 - /* 201 - * Do not add a reference to the menu's visibility 202 - * expression but use a copy of it. Otherwise the 203 - * expression reduction functions will modify 204 - * expressions that have multiple references which 205 - * can cause unwanted side effects. 206 - */ 207 - dup_expr = expr_copy(menu->visibility); 208 - 209 199 prop->visible.expr = expr_alloc_and(prop->visible.expr, 210 - dup_expr); 200 + menu->visibility); 211 201 } 212 202 } 213 203 ··· 313 323 */ 314 324 basedep = rewrite_m(menu->dep); 315 325 basedep = expr_transform(basedep); 316 - basedep = expr_alloc_and(expr_copy(parent->dep), basedep); 326 + basedep = expr_alloc_and(parent->dep, basedep); 317 327 basedep = expr_eliminate_dups(basedep); 318 328 menu->dep = basedep; 319 329 ··· 357 367 */ 358 368 dep = rewrite_m(prop->visible.expr); 359 369 dep = expr_transform(dep); 360 - dep = expr_alloc_and(expr_copy(basedep), dep); 370 + dep = expr_alloc_and(basedep, dep); 361 371 dep = expr_eliminate_dups(dep); 362 372 prop->visible.expr = dep; 363 373 ··· 368 378 if (prop->type == P_SELECT) { 369 379 struct symbol *es = prop_get_symbol(prop); 370 380 es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr, 371 - expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep))); 381 + expr_alloc_and(expr_alloc_symbol(menu->sym), dep)); 372 382 } else if (prop->type == P_IMPLY) { 373 383 struct symbol *es = prop_get_symbol(prop); 374 384 es->implied.expr = expr_alloc_or(es->implied.expr, 375 - expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep))); 385 + expr_alloc_and(expr_alloc_symbol(menu->sym), dep)); 376 386 } 377 387 } 378 388 } ··· 432 442 */ 433 443 dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no); 434 444 dep = expr_eliminate_dups(expr_transform(dep)); 435 - dep2 = expr_copy(basedep); 445 + dep2 = basedep; 436 446 expr_eliminate_eq(&dep, &dep2); 437 - expr_free(dep); 438 447 if (!expr_is_yes(dep2)) { 439 448 /* Not superset, quit */ 440 - expr_free(dep2); 441 449 break; 442 450 } 443 451 /* Superset, put in submenu */ 444 - expr_free(dep2); 445 452 next: 446 453 _menu_finalize(menu, false); 447 454 menu->parent = parent; 448 455 last_menu = menu; 449 456 } 450 - expr_free(basedep); 451 457 if (last_menu) { 452 458 parent->list = parent->next; 453 459 parent->next = last_menu->next;
+1
scripts/kconfig/nconf.c
··· 12 12 #include <stdlib.h> 13 13 14 14 #include <list.h> 15 + #include <xalloc.h> 15 16 #include "lkc.h" 16 17 #include "mnconf-common.h" 17 18 #include "nconf.h"
+1
scripts/kconfig/nconf.gui.c
··· 4 4 * 5 5 * Derived from menuconfig. 6 6 */ 7 + #include <xalloc.h> 7 8 #include "nconf.h" 8 9 #include "lkc.h" 9 10
+1 -12
scripts/kconfig/parser.y
··· 11 11 #include <string.h> 12 12 #include <stdbool.h> 13 13 14 + #include <xalloc.h> 14 15 #include "lkc.h" 15 16 #include "internal.h" 16 17 #include "preprocess.h" ··· 531 530 yydebug = 1; 532 531 yyparse(); 533 532 534 - /* 535 - * FIXME: 536 - * cur_filename and cur_lineno are used even after yyparse(); 537 - * menu_finalize() calls menu_add_symbol(). This should be fixed. 538 - */ 539 - cur_filename = "<none>"; 540 - cur_lineno = 0; 541 - 542 533 str_printf(&autoconf_cmd, 543 534 "\n" 544 535 "$(autoconfig): $(deps_config)\n" ··· 707 714 fputs( " menu ", out); 708 715 print_quoted_string(out, prop->text); 709 716 fputc('\n', out); 710 - break; 711 - case P_SYMBOL: 712 - fputs( " symbol ", out); 713 - fprintf(out, "%s\n", prop->menu->sym->name); 714 717 break; 715 718 default: 716 719 fprintf(out, " unknown prop %d!\n", prop->type);
+1
scripts/kconfig/preprocess.c
··· 11 11 12 12 #include <array_size.h> 13 13 #include <list.h> 14 + #include <xalloc.h> 14 15 #include "internal.h" 15 16 #include "lkc.h" 16 17 #include "preprocess.h"
+1 -1
scripts/kconfig/qconf.cc
··· 22 22 23 23 #include <stdlib.h> 24 24 25 + #include <xalloc.h> 25 26 #include "lkc.h" 26 27 #include "qconf.h" 27 28 ··· 1095 1094 case P_RANGE: 1096 1095 case P_COMMENT: 1097 1096 case P_IMPLY: 1098 - case P_SYMBOL: 1099 1097 stream << prop_get_type_name(prop->type); 1100 1098 stream << ": "; 1101 1099 expr_print(prop->expr, expr_print_help,
+5 -4
scripts/kconfig/symbol.c
··· 9 9 #include <string.h> 10 10 #include <regex.h> 11 11 12 + #include <hash.h> 13 + #include <xalloc.h> 12 14 #include "internal.h" 13 15 #include "lkc.h" 14 16 ··· 519 517 520 518 for_all_symbols(sym) 521 519 sym->flags &= ~SYMBOL_VALID; 520 + expr_invalidate_all(); 522 521 conf_set_changed(true); 523 522 sym_calc_value(modules_sym); 524 523 } ··· 895 892 case 'n': return &symbol_no; 896 893 } 897 894 } 898 - hash = strhash(name); 895 + hash = hash_str(name); 899 896 900 897 hash_for_each_possible(sym_hashtable, symbol, node, hash) { 901 898 if (symbol->name && ··· 938 935 case 'n': return &symbol_no; 939 936 } 940 937 } 941 - hash = strhash(name); 938 + hash = hash_str(name); 942 939 943 940 hash_for_each_possible(sym_hashtable, symbol, node, hash) { 944 941 if (symbol->name && ··· 1324 1321 return "imply"; 1325 1322 case P_RANGE: 1326 1323 return "range"; 1327 - case P_SYMBOL: 1328 - return "symbol"; 1329 1324 case P_UNKNOWN: 1330 1325 break; 1331 1326 }
+3 -60
scripts/kconfig/util.c
··· 8 8 #include <stdlib.h> 9 9 #include <string.h> 10 10 11 + #include <hash.h> 11 12 #include <hashtable.h> 13 + #include <xalloc.h> 12 14 #include "lkc.h" 13 - 14 - unsigned int strhash(const char *s) 15 - { 16 - /* fnv32 hash */ 17 - unsigned int hash = 2166136261U; 18 - 19 - for (; *s; s++) 20 - hash = (hash ^ *s) * 0x01000193; 21 - return hash; 22 - } 23 15 24 16 /* hash table of all parsed Kconfig files */ 25 17 static HASHTABLE_DEFINE(file_hashtable, 1U << 11); ··· 26 34 { 27 35 struct file *file; 28 36 size_t len; 29 - int hash = strhash(name); 37 + int hash = hash_str(name); 30 38 31 39 hash_for_each_possible(file_hashtable, file, node, hash) 32 40 if (!strcmp(name, file->name)) ··· 93 101 char *str_get(const struct gstr *gs) 94 102 { 95 103 return gs->s; 96 - } 97 - 98 - void *xmalloc(size_t size) 99 - { 100 - void *p = malloc(size); 101 - if (p) 102 - return p; 103 - fprintf(stderr, "Out of memory.\n"); 104 - exit(1); 105 - } 106 - 107 - void *xcalloc(size_t nmemb, size_t size) 108 - { 109 - void *p = calloc(nmemb, size); 110 - if (p) 111 - return p; 112 - fprintf(stderr, "Out of memory.\n"); 113 - exit(1); 114 - } 115 - 116 - void *xrealloc(void *p, size_t size) 117 - { 118 - p = realloc(p, size); 119 - if (p) 120 - return p; 121 - fprintf(stderr, "Out of memory.\n"); 122 - exit(1); 123 - } 124 - 125 - char *xstrdup(const char *s) 126 - { 127 - char *p; 128 - 129 - p = strdup(s); 130 - if (p) 131 - return p; 132 - fprintf(stderr, "Out of memory.\n"); 133 - exit(1); 134 - } 135 - 136 - char *xstrndup(const char *s, size_t n) 137 - { 138 - char *p; 139 - 140 - p = strndup(s, n); 141 - if (p) 142 - return p; 143 - fprintf(stderr, "Out of memory.\n"); 144 - exit(1); 145 104 }
-25
scripts/mod/mk_elfconfig.c
··· 8 8 main(int argc, char **argv) 9 9 { 10 10 unsigned char ei[EI_NIDENT]; 11 - union { short s; char c[2]; } endian_test; 12 11 13 12 if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { 14 13 fprintf(stderr, "Error: input truncated\n"); ··· 27 28 default: 28 29 exit(1); 29 30 } 30 - switch (ei[EI_DATA]) { 31 - case ELFDATA2LSB: 32 - printf("#define KERNEL_ELFDATA ELFDATA2LSB\n"); 33 - break; 34 - case ELFDATA2MSB: 35 - printf("#define KERNEL_ELFDATA ELFDATA2MSB\n"); 36 - break; 37 - default: 38 - exit(1); 39 - } 40 - 41 - if (sizeof(unsigned long) == 4) { 42 - printf("#define HOST_ELFCLASS ELFCLASS32\n"); 43 - } else if (sizeof(unsigned long) == 8) { 44 - printf("#define HOST_ELFCLASS ELFCLASS64\n"); 45 - } 46 - 47 - endian_test.s = 0x0102; 48 - if (memcmp(endian_test.c, "\x01\x02", 2) == 0) 49 - printf("#define HOST_ELFDATA ELFDATA2MSB\n"); 50 - else if (memcmp(endian_test.c, "\x02\x01", 2) == 0) 51 - printf("#define HOST_ELFDATA ELFDATA2LSB\n"); 52 - else 53 - exit(1); 54 31 55 32 return 0; 56 33 }
+65 -60
scripts/mod/modpost.c
··· 23 23 24 24 #include <hashtable.h> 25 25 #include <list.h> 26 + #include <xalloc.h> 26 27 #include "modpost.h" 27 28 #include "../../include/linux/license.h" 28 29 ··· 51 50 52 51 static bool extra_warn; 53 52 53 + bool target_is_big_endian; 54 + bool host_is_big_endian; 55 + 54 56 /* 55 57 * Cut off the warnings when there are too many. This typically occurs when 56 58 * vmlinux is missing. ('make modules' without building vmlinux.) ··· 67 63 68 64 #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr)) 69 65 70 - void modpost_log(enum loglevel loglevel, const char *fmt, ...) 66 + void modpost_log(bool is_error, const char *fmt, ...) 71 67 { 72 68 va_list arglist; 73 69 74 - switch (loglevel) { 75 - case LOG_WARN: 76 - fprintf(stderr, "WARNING: "); 77 - break; 78 - case LOG_ERROR: 70 + if (is_error) { 79 71 fprintf(stderr, "ERROR: "); 80 72 error_occurred = true; 81 - break; 82 - default: /* invalid loglevel, ignore */ 83 - break; 73 + } else { 74 + fprintf(stderr, "WARNING: "); 84 75 } 85 76 86 77 fprintf(stderr, "modpost: "); ··· 91 92 return false; 92 93 93 94 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; 94 - } 95 - 96 - void *do_nofail(void *ptr, const char *expr) 97 - { 98 - if (!ptr) 99 - fatal("Memory allocation failure: %s.\n", expr); 100 - 101 - return ptr; 102 95 } 103 96 104 97 char *read_text_file(const char *filename) ··· 111 120 exit(1); 112 121 } 113 122 114 - buf = NOFAIL(malloc(st.st_size + 1)); 123 + buf = xmalloc(st.st_size + 1); 115 124 116 125 nbytes = st.st_size; 117 126 ··· 169 178 { 170 179 struct module *mod; 171 180 172 - mod = NOFAIL(malloc(sizeof(*mod) + namelen + 1)); 181 + mod = xmalloc(sizeof(*mod) + namelen + 1); 173 182 memset(mod, 0, sizeof(*mod)); 174 183 175 184 INIT_LIST_HEAD(&mod->exported_symbols); ··· 228 237 **/ 229 238 static struct symbol *alloc_symbol(const char *name) 230 239 { 231 - struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); 240 + struct symbol *s = xmalloc(sizeof(*s) + strlen(name) + 1); 232 241 233 242 memset(s, 0, sizeof(*s)); 234 243 strcpy(s->name, name); ··· 301 310 struct namespace_list *ns_entry; 302 311 303 312 if (!contains_namespace(head, namespace)) { 304 - ns_entry = NOFAIL(malloc(sizeof(*ns_entry) + 305 - strlen(namespace) + 1)); 313 + ns_entry = xmalloc(sizeof(*ns_entry) + strlen(namespace) + 1); 306 314 strcpy(ns_entry->namespace, namespace); 307 315 list_add_tail(&ns_entry->list, head); 308 316 } ··· 356 366 s = alloc_symbol(name); 357 367 s->module = mod; 358 368 s->is_gpl_only = gpl_only; 359 - s->namespace = NOFAIL(strdup(namespace)); 369 + s->namespace = xstrdup(namespace); 360 370 list_add_tail(&s->list, &mod->exported_symbols); 361 371 hash_add_symbol(s); 362 372 ··· 428 438 /* Not an ELF file - silently ignore it */ 429 439 return 0; 430 440 } 441 + 442 + switch (hdr->e_ident[EI_DATA]) { 443 + case ELFDATA2LSB: 444 + target_is_big_endian = false; 445 + break; 446 + case ELFDATA2MSB: 447 + target_is_big_endian = true; 448 + break; 449 + default: 450 + fatal("target endian is unknown\n"); 451 + } 452 + 431 453 /* Fix endianness in ELF header */ 432 454 hdr->e_type = TO_NATIVE(hdr->e_type); 433 455 hdr->e_machine = TO_NATIVE(hdr->e_machine); ··· 624 622 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) 625 623 break; 626 624 if (symname[0] == '.') { 627 - char *munged = NOFAIL(strdup(symname)); 625 + char *munged = xstrdup(symname); 628 626 munged[0] = '_'; 629 627 munged[1] = toupper(munged[1]); 630 628 symname = munged; ··· 692 690 693 691 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) 694 692 { 695 - if (sym) 696 - return elf->strtab + sym->st_name; 697 - else 698 - return "(unknown)"; 693 + return sym ? elf->strtab + sym->st_name : ""; 699 694 } 700 695 701 696 /* ··· 1005 1006 Elf_Sym *from; 1006 1007 const char *tosym; 1007 1008 const char *fromsym; 1009 + char taddr_str[16]; 1008 1010 1009 1011 from = find_fromsym(elf, faddr, fsecndx); 1010 1012 fromsym = sym_name(elf, from); ··· 1019 1019 1020 1020 sec_mismatch_count++; 1021 1021 1022 - warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n", 1023 - modname, fromsym, 1024 - (unsigned int)(faddr - (from ? from->st_value : 0)), 1025 - fromsec, tosym, tosec); 1022 + if (!tosym[0]) 1023 + snprintf(taddr_str, sizeof(taddr_str), "0x%x", (unsigned int)taddr); 1024 + 1025 + /* 1026 + * The format for the reference source: <symbol_name>+<offset> or <address> 1027 + * The format for the reference destination: <symbol_name> or <address> 1028 + */ 1029 + warn("%s: section mismatch in reference: %s%s0x%x (section: %s) -> %s (section: %s)\n", 1030 + modname, fromsym, fromsym[0] ? "+" : "", 1031 + (unsigned int)(faddr - (fromsym[0] ? from->st_value : 0)), 1032 + fromsec, tosym[0] ? tosym : taddr_str, tosec); 1026 1033 1027 1034 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { 1028 1035 if (match(tosec, mismatch->bad_tosec)) ··· 1669 1662 { 1670 1663 if (buf->size - buf->pos < len) { 1671 1664 buf->size += len + SZ; 1672 - buf->p = NOFAIL(realloc(buf->p, buf->size)); 1665 + buf->p = xrealloc(buf->p, buf->size); 1673 1666 } 1674 1667 strncpy(buf->p + buf->pos, s, len); 1675 1668 buf->pos += len; ··· 1684 1677 exp = find_symbol(s->name); 1685 1678 if (!exp) { 1686 1679 if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) 1687 - modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR, 1680 + modpost_log(!warn_unresolved, 1688 1681 "\"%s\" [%s.ko] undefined!\n", 1689 1682 s->name, mod->name); 1690 1683 continue; ··· 1707 1700 basename = mod->name; 1708 1701 1709 1702 if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { 1710 - modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR, 1703 + modpost_log(!allow_missing_ns_imports, 1711 1704 "module %s uses symbol %s from namespace %s, but does not import it.\n", 1712 1705 basename, exp->name, exp->namespace); 1713 1706 add_namespace(&mod->missing_namespaces, exp->namespace); ··· 1755 1748 static void add_header(struct buffer *b, struct module *mod) 1756 1749 { 1757 1750 buf_printf(b, "#include <linux/module.h>\n"); 1758 - /* 1759 - * Include build-salt.h after module.h in order to 1760 - * inherit the definitions. 1761 - */ 1762 - buf_printf(b, "#define INCLUDE_VERMAGIC\n"); 1763 - buf_printf(b, "#include <linux/build-salt.h>\n"); 1764 - buf_printf(b, "#include <linux/elfnote-lto.h>\n"); 1765 1751 buf_printf(b, "#include <linux/export-internal.h>\n"); 1766 - buf_printf(b, "#include <linux/vermagic.h>\n"); 1767 1752 buf_printf(b, "#include <linux/compiler.h>\n"); 1768 1753 buf_printf(b, "\n"); 1769 - buf_printf(b, "#ifdef CONFIG_UNWINDER_ORC\n"); 1770 - buf_printf(b, "#include <asm/orc_header.h>\n"); 1771 - buf_printf(b, "ORC_HEADER;\n"); 1772 - buf_printf(b, "#endif\n"); 1773 - buf_printf(b, "\n"); 1774 - buf_printf(b, "BUILD_SALT;\n"); 1775 - buf_printf(b, "BUILD_LTO_INFO;\n"); 1776 - buf_printf(b, "\n"); 1777 - buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); 1778 1754 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); 1779 1755 buf_printf(b, "\n"); 1780 1756 buf_printf(b, "__visible struct module __this_module\n"); ··· 1774 1784 1775 1785 if (!external_module) 1776 1786 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); 1777 - 1778 - buf_printf(b, 1779 - "\n" 1780 - "#ifdef CONFIG_MITIGATION_RETPOLINE\n" 1781 - "MODULE_INFO(retpoline, \"Y\");\n" 1782 - "#endif\n"); 1783 1787 1784 1788 if (strstarts(mod->name, "drivers/staging")) 1785 1789 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); ··· 1931 1947 if (st.st_size != b->pos) 1932 1948 goto close_write; 1933 1949 1934 - tmp = NOFAIL(malloc(b->pos)); 1950 + tmp = xmalloc(b->pos); 1935 1951 if (fread(tmp, 1, b->pos, file) != b->pos) 1936 1952 goto free_write; 1937 1953 ··· 2101 2117 const char *file; 2102 2118 }; 2103 2119 2120 + static void check_host_endian(void) 2121 + { 2122 + static const union { 2123 + short s; 2124 + char c[2]; 2125 + } endian_test = { .c = {0x01, 0x02} }; 2126 + 2127 + switch (endian_test.s) { 2128 + case 0x0102: 2129 + host_is_big_endian = true; 2130 + break; 2131 + case 0x0201: 2132 + host_is_big_endian = false; 2133 + break; 2134 + default: 2135 + fatal("Unknown host endian\n"); 2136 + } 2137 + } 2138 + 2104 2139 int main(int argc, char **argv) 2105 2140 { 2106 2141 struct module *mod; ··· 2136 2133 external_module = true; 2137 2134 break; 2138 2135 case 'i': 2139 - dl = NOFAIL(malloc(sizeof(*dl))); 2136 + dl = xmalloc(sizeof(*dl)); 2140 2137 dl->file = optarg; 2141 2138 list_add_tail(&dl->list, &dump_lists); 2142 2139 break; ··· 2183 2180 exit(1); 2184 2181 } 2185 2182 } 2183 + 2184 + check_host_endian(); 2186 2185 2187 2186 list_for_each_entry_safe(dl, dl2, &dump_lists, list) { 2188 2187 read_dump(dl->file);
+7 -21
scripts/mod/modpost.h
··· 62 62 x); \ 63 63 }) 64 64 65 - #if KERNEL_ELFDATA != HOST_ELFDATA 66 - 67 - #define TO_NATIVE(x) (bswap(x)) 68 - 69 - #else /* endianness matches */ 70 - 71 - #define TO_NATIVE(x) (x) 72 - 73 - #endif 74 - 75 - #define NOFAIL(ptr) do_nofail((ptr), #ptr) 65 + #define TO_NATIVE(x) \ 66 + (target_is_big_endian == host_is_big_endian ? x : bswap(x)) 76 67 77 68 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 78 - 79 - void *do_nofail(void *ptr, const char *expr); 80 69 81 70 struct buffer { 82 71 char *p; ··· 176 187 void get_src_version(const char *modname, char sum[], unsigned sumlen); 177 188 178 189 /* from modpost.c */ 190 + extern bool target_is_big_endian; 191 + extern bool host_is_big_endian; 179 192 char *read_text_file(const char *filename); 180 193 char *get_line(char **stringp); 181 194 void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym); 182 195 183 - enum loglevel { 184 - LOG_WARN, 185 - LOG_ERROR, 186 - }; 187 - 188 196 void __attribute__((format(printf, 2, 3))) 189 - modpost_log(enum loglevel loglevel, const char *fmt, ...); 197 + modpost_log(bool is_error, const char *fmt, ...); 190 198 191 199 /* 192 200 * warn - show the given message, then let modpost continue running, still ··· 198 212 * fatal - show the given message, and bail out immediately. This should be 199 213 * used when there is no point to continue running modpost. 200 214 */ 201 - #define warn(fmt, args...) modpost_log(LOG_WARN, fmt, ##args) 202 - #define error(fmt, args...) modpost_log(LOG_ERROR, fmt, ##args) 215 + #define warn(fmt, args...) modpost_log(false, fmt, ##args) 216 + #define error(fmt, args...) modpost_log(true, fmt, ##args) 203 217 #define fatal(fmt, args...) do { error(fmt, ##args); exit(1); } while (1)
+4 -2
scripts/mod/sumversion.c
··· 8 8 #include <errno.h> 9 9 #include <string.h> 10 10 #include <limits.h> 11 + 12 + #include <xalloc.h> 11 13 #include "modpost.h" 12 14 13 15 /* ··· 307 305 const char *base; 308 306 int dirlen, ret = 0, check_files = 0; 309 307 310 - cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd"))); 308 + cmd = xmalloc(strlen(objfile) + sizeof("..cmd")); 311 309 312 310 base = strrchr(objfile, '/'); 313 311 if (base) { ··· 318 316 dirlen = 0; 319 317 sprintf(cmd, ".%s.cmd", objfile); 320 318 } 321 - dir = NOFAIL(malloc(dirlen + 1)); 319 + dir = xmalloc(dirlen + 1); 322 320 strncpy(dir, objfile, dirlen); 323 321 dir[dirlen] = '\0'; 324 322
+3 -3
scripts/mod/symsearch.c
··· 4 4 * Helper functions for finding the symbol in an ELF which is "nearest" 5 5 * to a given address. 6 6 */ 7 - 7 + #include <xalloc.h> 8 8 #include "modpost.h" 9 9 10 10 struct syminfo { ··· 125 125 { 126 126 unsigned int table_size = symbol_count(elf); 127 127 128 - elf->symsearch = NOFAIL(malloc(sizeof(struct symsearch) + 129 - sizeof(struct syminfo) * table_size)); 128 + elf->symsearch = xmalloc(sizeof(struct symsearch) + 129 + sizeof(struct syminfo) * table_size); 130 130 elf->symsearch->table_size = table_size; 131 131 132 132 symsearch_populate(elf, elf->symsearch->table, table_size);
+25
scripts/module-common.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/module.h> 4 + /* 5 + * Include build-salt.h after module.h in order to 6 + * inherit the definitions. 7 + */ 8 + #define INCLUDE_VERMAGIC 9 + #include <linux/build-salt.h> 10 + #include <linux/elfnote-lto.h> 11 + #include <linux/vermagic.h> 12 + 13 + #ifdef CONFIG_UNWINDER_ORC 14 + #include <asm/orc_header.h> 15 + ORC_HEADER; 16 + #endif 17 + 18 + BUILD_SALT; 19 + BUILD_LTO_INFO; 20 + 21 + MODULE_INFO(vermagic, VERMAGIC_STRING); 22 + 23 + #ifdef CONFIG_MITIGATION_RETPOLINE 24 + MODULE_INFO(retpoline, "Y"); 25 + #endif
+38 -14
scripts/package/PKGBUILD
··· 3 3 # Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org> 4 4 5 5 pkgbase=${PACMAN_PKGBASE:-linux-upstream} 6 - pkgname=("${pkgbase}" "${pkgbase}-api-headers") 7 - if grep -q CONFIG_MODULES=y include/config/auto.conf; then 8 - pkgname+=("${pkgbase}-headers") 9 - fi 6 + pkgname=("${pkgbase}") 7 + 8 + _extrapackages=${PACMAN_EXTRAPACKAGES-headers api-headers debug} 9 + for pkg in $_extrapackages; do 10 + pkgname+=("${pkgbase}-${pkg}") 11 + done 12 + 10 13 pkgver="${KERNELRELEASE//-/_}" 11 14 # The PKGBUILD is evaluated multiple times. 12 15 # Running scripts/build-version from here would introduce inconsistencies. ··· 36 33 ) 37 34 options=(!debug !strip !buildflags !makeflags) 38 35 39 - build() { 36 + _prologue() { 40 37 # MAKEFLAGS from makepkg.conf override the ones inherited from kbuild. 41 38 # Bypass this override with a custom variable. 42 39 export MAKEFLAGS="${KBUILD_MAKEFLAGS}" 43 - cd "${objtree}" 40 + 41 + # Kbuild works in the output directory, where this PKGBUILD is located. 42 + cd "$(dirname "${BASH_SOURCE[0]}")" 43 + } 44 + 45 + build() { 46 + _prologue 44 47 45 48 ${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}" 46 49 } ··· 54 45 _package() { 55 46 pkgdesc="The ${pkgdesc} kernel and modules" 56 47 57 - export MAKEFLAGS="${KBUILD_MAKEFLAGS}" 58 - cd "${objtree}" 59 48 local modulesdir="${pkgdir}/usr/${MODLIB}" 49 + 50 + _prologue 60 51 61 52 echo "Installing boot image..." 62 53 # systemd expects to find the kernel here to allow hibernation ··· 82 73 _package-headers() { 83 74 pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel" 84 75 85 - export MAKEFLAGS="${KBUILD_MAKEFLAGS}" 86 - cd "${objtree}" 87 76 local builddir="${pkgdir}/usr/${MODLIB}/build" 88 77 89 - echo "Installing build files..." 90 - "${srctree}/scripts/package/install-extmod-build" "${builddir}" 78 + _prologue 79 + 80 + if grep -q CONFIG_MODULES=y include/config/auto.conf; then 81 + echo "Installing build files..." 82 + "${srctree}/scripts/package/install-extmod-build" "${builddir}" 83 + fi 91 84 92 85 echo "Installing System.map and config..." 86 + mkdir -p "${builddir}" 93 87 cp System.map "${builddir}/System.map" 94 88 cp .config "${builddir}/.config" 95 89 ··· 106 94 provides=(linux-api-headers) 107 95 conflicts=(linux-api-headers) 108 96 109 - export MAKEFLAGS="${KBUILD_MAKEFLAGS}" 110 - cd "${objtree}" 97 + _prologue 111 98 112 99 ${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr" 100 + } 101 + 102 + _package-debug(){ 103 + pkgdesc="Non-stripped vmlinux file for the ${pkgdesc} kernel" 104 + 105 + local debugdir="${pkgdir}/usr/src/debug/${pkgbase}" 106 + local builddir="${pkgdir}/usr/${MODLIB}/build" 107 + 108 + _prologue 109 + 110 + install -Dt "${debugdir}" -m644 vmlinux 111 + mkdir -p "${builddir}" 112 + ln -sr "${debugdir}/vmlinux" "${builddir}/vmlinux" 113 113 } 114 114 115 115 for _p in "${pkgname[@]}"; do
+50 -5
scripts/package/install-extmod-build
··· 9 9 grep -q "^$1=y" include/config/auto.conf 10 10 } 11 11 12 + find_in_scripts() { 13 + find scripts \ 14 + \( -name atomic -o -name dtc -o -name kconfig -o -name package \) -prune -o \ 15 + ! -name unifdef -a ! -name mk_elfconfig -a \( -type f -o -type l \) -print 16 + } 17 + 12 18 mkdir -p "${destdir}" 13 19 14 20 ( 15 21 cd "${srctree}" 16 22 echo Makefile 17 23 find "arch/${SRCARCH}" -maxdepth 1 -name 'Makefile*' 18 - find include scripts -type f -o -type l 24 + find "arch/${SRCARCH}" -name generated -prune -o -name include -type d -print 19 25 find "arch/${SRCARCH}" -name Kbuild.platforms -o -name Platform 20 - find "arch/${SRCARCH}" -name include -type d 26 + find include \( -name config -o -name generated \) -prune -o \( -type f -o -type l \) -print 27 + find_in_scripts 21 28 ) | tar -c -f - -C "${srctree}" -T - | tar -xf - -C "${destdir}" 22 29 23 30 { ··· 32 25 echo tools/objtool/objtool 33 26 fi 34 27 35 - find "arch/${SRCARCH}/include" Module.symvers include scripts -type f 28 + echo Module.symvers 29 + echo "arch/${SRCARCH}/include/generated" 30 + echo include/config/auto.conf 31 + echo include/config/kernel.release 32 + echo include/generated 33 + find_in_scripts 36 34 37 35 if is_enabled CONFIG_GCC_PLUGINS; then 38 36 find scripts/gcc-plugins -name '*.so' 39 37 fi 40 38 } | tar -c -f - -T - | tar -xf - -C "${destdir}" 41 39 42 - # copy .config manually to be where it's expected to be 43 - cp "${KCONFIG_CONFIG}" "${destdir}/.config" 40 + # When ${CC} and ${HOSTCC} differ, we are likely cross-compiling. Rebuild host 41 + # programs using ${CC}. This assumes CC=${CROSS_COMPILE}gcc, which is usually 42 + # the case for package building. It does not cross-compile when CC=clang. 43 + # 44 + # This caters to host programs that participate in Kbuild. objtool and 45 + # resolve_btfids are out of scope. 46 + if [ "${CC}" != "${HOSTCC}" ] && is_enabled CONFIG_CC_CAN_LINK; then 47 + echo "Rebuilding host programs with ${CC}..." 48 + 49 + cat <<-'EOF' > "${destdir}/Kbuild" 50 + subdir-y := scripts 51 + EOF 52 + 53 + # HOSTCXX is not overridden. The C++ compiler is used to build: 54 + # - scripts/kconfig/qconf, which is unneeded for external module builds 55 + # - GCC plugins, which will not work on the installed system even after 56 + # being rebuilt. 57 + # 58 + # Use the single-target build to avoid the modpost invocation, which 59 + # would overwrite Module.symvers. 60 + "${MAKE}" HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/ 61 + 62 + cat <<-'EOF' > "${destdir}/scripts/Kbuild" 63 + subdir-y := basic 64 + hostprogs-always-y := mod/modpost 65 + mod/modpost-objs := $(addprefix mod/, modpost.o file2alias.o sumversion.o symsearch.o) 66 + EOF 67 + 68 + # Run once again to rebuild scripts/basic/ and scripts/mod/modpost. 69 + "${MAKE}" HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/ 70 + 71 + rm -f "${destdir}/Kbuild" "${destdir}/scripts/Kbuild" 72 + fi 73 + 74 + find "${destdir}" \( -name '.*.cmd' -o -name '*.o' \) -delete
+1 -1
scripts/subarch.include
··· 6 6 7 7 SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ 8 8 -e s/sun4u/sparc64/ \ 9 - -e s/arm.*/arm/ -e s/sa110/arm/ \ 9 + -e /^arm64$$/!s/arm.*/arm/ -e s/sa110/arm/ \ 10 10 -e s/s390x/s390/ \ 11 11 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 12 12 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
+370
scripts/verify_builtin_ranges.awk
··· 1 + #!/usr/bin/gawk -f 2 + # SPDX-License-Identifier: GPL-2.0 3 + # verify_builtin_ranges.awk: Verify address range data for builtin modules 4 + # Written by Kris Van Hees <kris.van.hees@oracle.com> 5 + # 6 + # Usage: verify_builtin_ranges.awk modules.builtin.ranges System.map \ 7 + # modules.builtin vmlinux.map vmlinux.o.map 8 + # 9 + 10 + # Return the module name(s) (if any) associated with the given object. 11 + # 12 + # If we have seen this object before, return information from the cache. 13 + # Otherwise, retrieve it from the corresponding .cmd file. 14 + # 15 + function get_module_info(fn, mod, obj, s) { 16 + if (fn in omod) 17 + return omod[fn]; 18 + 19 + if (match(fn, /\/[^/]+$/) == 0) 20 + return ""; 21 + 22 + obj = fn; 23 + mod = ""; 24 + fn = substr(fn, 1, RSTART) "." substr(fn, RSTART + 1) ".cmd"; 25 + if (getline s <fn == 1) { 26 + if (match(s, /DKBUILD_MODFILE=['"]+[^'"]+/) > 0) { 27 + mod = substr(s, RSTART + 16, RLENGTH - 16); 28 + gsub(/['"]/, "", mod); 29 + } else if (match(s, /RUST_MODFILE=[^ ]+/) > 0) 30 + mod = substr(s, RSTART + 13, RLENGTH - 13); 31 + } else { 32 + print "ERROR: Failed to read: " fn "\n\n" \ 33 + " For kernels built with O=<objdir>, cd to <objdir>\n" \ 34 + " and execute this script as ./source/scripts/..." \ 35 + >"/dev/stderr"; 36 + close(fn); 37 + total = 0; 38 + exit(1); 39 + } 40 + close(fn); 41 + 42 + # A single module (common case) also reflects objects that are not part 43 + # of a module. Some of those objects have names that are also a module 44 + # name (e.g. core). We check the associated module file name, and if 45 + # they do not match, the object is not part of a module. 46 + if (mod !~ / /) { 47 + if (!(mod in mods)) 48 + mod = ""; 49 + } 50 + 51 + gsub(/([^/ ]*\/)+/, "", mod); 52 + gsub(/-/, "_", mod); 53 + 54 + # At this point, mod is a single (valid) module name, or a list of 55 + # module names (that do not need validation). 56 + omod[obj] = mod; 57 + 58 + return mod; 59 + } 60 + 61 + # Return a representative integer value for a given hexadecimal address. 62 + # 63 + # Since all kernel addresses fall within the same memory region, we can safely 64 + # strip off the first 6 hex digits before performing the hex-to-dec conversion, 65 + # thereby avoiding integer overflows. 66 + # 67 + function addr2val(val) { 68 + sub(/^0x/, "", val); 69 + if (length(val) == 16) 70 + val = substr(val, 5); 71 + return strtonum("0x" val); 72 + } 73 + 74 + # Determine the kernel build directory to use (default is .). 75 + # 76 + BEGIN { 77 + if (ARGC < 6) { 78 + print "Syntax: verify_builtin_ranges.awk <ranges-file> <system-map>\n" \ 79 + " <builtin-file> <vmlinux-map> <vmlinux-o-map>\n" \ 80 + >"/dev/stderr"; 81 + total = 0; 82 + exit(1); 83 + } 84 + } 85 + 86 + # (1) Load the built-in module address range data. 87 + # 88 + ARGIND == 1 { 89 + ranges[FNR] = $0; 90 + rcnt++; 91 + next; 92 + } 93 + 94 + # (2) Annotate System.map symbols with module names. 95 + # 96 + ARGIND == 2 { 97 + addr = addr2val($1); 98 + name = $3; 99 + 100 + while (addr >= mod_eaddr) { 101 + if (sect_symb) { 102 + if (sect_symb != name) 103 + next; 104 + 105 + sect_base = addr - sect_off; 106 + if (dbg) 107 + printf "[%s] BASE (%s) %016x - %016x = %016x\n", sect_name, sect_symb, addr, sect_off, sect_base >"/dev/stderr"; 108 + sect_symb = 0; 109 + } 110 + 111 + if (++ridx > rcnt) 112 + break; 113 + 114 + $0 = ranges[ridx]; 115 + sub(/-/, " "); 116 + if ($4 != "=") { 117 + sub(/-/, " "); 118 + mod_saddr = strtonum("0x" $2) + sect_base; 119 + mod_eaddr = strtonum("0x" $3) + sect_base; 120 + $1 = $2 = $3 = ""; 121 + sub(/^ +/, ""); 122 + mod_name = $0; 123 + 124 + if (dbg) 125 + printf "[%s] %s from %016x to %016x\n", sect_name, mod_name, mod_saddr, mod_eaddr >"/dev/stderr"; 126 + } else { 127 + sect_name = $1; 128 + sect_off = strtonum("0x" $2); 129 + sect_symb = $5; 130 + } 131 + } 132 + 133 + idx = addr"-"name; 134 + if (addr >= mod_saddr && addr < mod_eaddr) 135 + sym2mod[idx] = mod_name; 136 + 137 + next; 138 + } 139 + 140 + # Once we are done annotating the System.map, we no longer need the ranges data. 141 + # 142 + FNR == 1 && ARGIND == 3 { 143 + delete ranges; 144 + } 145 + 146 + # (3) Build a lookup map of built-in module names. 147 + # 148 + # Lines from modules.builtin will be like: 149 + # kernel/crypto/lzo-rle.ko 150 + # and we record the object name "crypto/lzo-rle". 151 + # 152 + ARGIND == 3 { 153 + sub(/kernel\//, ""); # strip off "kernel/" prefix 154 + sub(/\.ko$/, ""); # strip off .ko suffix 155 + 156 + mods[$1] = 1; 157 + next; 158 + } 159 + 160 + # (4) Get a list of symbols (per object). 161 + # 162 + # Symbols by object are read from vmlinux.map, with fallback to vmlinux.o.map 163 + # if vmlinux is found to have inked in vmlinux.o. 164 + # 165 + 166 + # If we were able to get the data we need from vmlinux.map, there is no need to 167 + # process vmlinux.o.map. 168 + # 169 + FNR == 1 && ARGIND == 5 && total > 0 { 170 + if (dbg) 171 + printf "Note: %s is not needed.\n", FILENAME >"/dev/stderr"; 172 + exit; 173 + } 174 + 175 + # First determine whether we are dealing with a GNU ld or LLVM lld linker map. 176 + # 177 + ARGIND >= 4 && FNR == 1 && NF == 7 && $1 == "VMA" && $7 == "Symbol" { 178 + map_is_lld = 1; 179 + next; 180 + } 181 + 182 + # (LLD) Convert a section record fronm lld format to ld format. 183 + # 184 + ARGIND >= 4 && map_is_lld && NF == 5 && /[0-9] [^ ]+$/ { 185 + $0 = $5 " 0x"$1 " 0x"$3 " load address 0x"$2; 186 + } 187 + 188 + # (LLD) Convert an object record from lld format to ld format. 189 + # 190 + ARGIND >= 4 && map_is_lld && NF == 5 && $5 ~ /:\(/ { 191 + if (/\.a\(/ && !/ vmlinux\.a\(/) 192 + next; 193 + 194 + gsub(/\)/, ""); 195 + sub(/:\(/, " "); 196 + sub(/ vmlinux\.a\(/, " "); 197 + $0 = " "$6 " 0x"$1 " 0x"$3 " " $5; 198 + } 199 + 200 + # (LLD) Convert a symbol record from lld format to ld format. 201 + # 202 + ARGIND >= 4 && map_is_lld && NF == 5 && $5 ~ /^[A-Za-z_][A-Za-z0-9_]*$/ { 203 + $0 = " 0x" $1 " " $5; 204 + } 205 + 206 + # (LLD) We do not need any other ldd linker map records. 207 + # 208 + ARGIND >= 4 && map_is_lld && /^[0-9a-f]{16} / { 209 + next; 210 + } 211 + 212 + # Handle section records with long section names (spilling onto a 2nd line). 213 + # 214 + ARGIND >= 4 && !map_is_lld && NF == 1 && /^[^ ]/ { 215 + s = $0; 216 + getline; 217 + $0 = s " " $0; 218 + } 219 + 220 + # Next section - previous one is done. 221 + # 222 + ARGIND >= 4 && /^[^ ]/ { 223 + sect = 0; 224 + } 225 + 226 + # Get the (top level) section name. 227 + # 228 + ARGIND >= 4 && /^\./ { 229 + # Explicitly ignore a few sections that are not relevant here. 230 + if ($1 ~ /^\.orc_/ || $1 ~ /_sites$/ || $1 ~ /\.percpu/) 231 + next; 232 + 233 + # Sections with a 0-address can be ignored as well (in vmlinux.map). 234 + if (ARGIND == 4 && $2 ~ /^0x0+$/) 235 + next; 236 + 237 + sect = $1; 238 + 239 + next; 240 + } 241 + 242 + # If we are not currently in a section we care about, ignore records. 243 + # 244 + !sect { 245 + next; 246 + } 247 + 248 + # Handle object records with long section names (spilling onto a 2nd line). 249 + # 250 + ARGIND >= 4 && /^ [^ \*]/ && NF == 1 { 251 + # If the section name is long, the remainder of the entry is found on 252 + # the next line. 253 + s = $0; 254 + getline; 255 + $0 = s " " $0; 256 + } 257 + 258 + # Objects linked in from static libraries are ignored. 259 + # If the object is vmlinux.o, we need to consult vmlinux.o.map for per-object 260 + # symbol information 261 + # 262 + ARGIND == 4 && /^ [^ ]/ && NF == 4 { 263 + if ($4 ~ /\.a\(/) 264 + next; 265 + 266 + idx = sect":"$1; 267 + if (!(idx in sect_addend)) { 268 + sect_addend[idx] = addr2val($2); 269 + if (dbg) 270 + printf "ADDEND %s = %016x\n", idx, sect_addend[idx] >"/dev/stderr"; 271 + } 272 + if ($4 == "vmlinux.o") { 273 + need_o_map = 1; 274 + next; 275 + } 276 + } 277 + 278 + # If data from vmlinux.o.map is needed, we only process section and object 279 + # records from vmlinux.map to determine which section we need to pay attention 280 + # to in vmlinux.o.map. So skip everything else from vmlinux.map. 281 + # 282 + ARGIND == 4 && need_o_map { 283 + next; 284 + } 285 + 286 + # Get module information for the current object. 287 + # 288 + ARGIND >= 4 && /^ [^ ]/ && NF == 4 { 289 + msect = $1; 290 + mod_name = get_module_info($4); 291 + mod_eaddr = addr2val($2) + addr2val($3); 292 + 293 + next; 294 + } 295 + 296 + # Process a symbol record. 297 + # 298 + # Evaluate the module information obtained from vmlinux.map (or vmlinux.o.map) 299 + # as follows: 300 + # - For all symbols in a given object: 301 + # - If the symbol is annotated with the same module name(s) that the object 302 + # belongs to, count it as a match. 303 + # - Otherwise: 304 + # - If the symbol is known to have duplicates of which at least one is 305 + # in a built-in module, disregard it. 306 + # - If the symbol us not annotated with any module name(s) AND the 307 + # object belongs to built-in modules, count it as missing. 308 + # - Otherwise, count it as a mismatch. 309 + # 310 + ARGIND >= 4 && /^ / && NF == 2 && $1 ~ /^0x/ { 311 + idx = sect":"msect; 312 + if (!(idx in sect_addend)) 313 + next; 314 + 315 + addr = addr2val($1); 316 + 317 + # Handle the rare but annoying case where a 0-size symbol is placed at 318 + # the byte *after* the module range. Based on vmlinux.map it will be 319 + # considered part of the current object, but it falls just beyond the 320 + # module address range. Unfortunately, its address could be at the 321 + # start of another built-in module, so the only safe thing to do is to 322 + # ignore it. 323 + if (mod_name && addr == mod_eaddr) 324 + next; 325 + 326 + # If we are processing vmlinux.o.map, we need to apply the base address 327 + # of the section to the relative address on the record. 328 + # 329 + if (ARGIND == 5) 330 + addr += sect_addend[idx]; 331 + 332 + idx = addr"-"$2; 333 + mod = ""; 334 + if (idx in sym2mod) { 335 + mod = sym2mod[idx]; 336 + if (sym2mod[idx] == mod_name) { 337 + mod_matches++; 338 + matches++; 339 + } else if (mod_name == "") { 340 + print $2 " in " mod " (should NOT be)"; 341 + mismatches++; 342 + } else { 343 + print $2 " in " mod " (should be " mod_name ")"; 344 + mismatches++; 345 + } 346 + } else if (mod_name != "") { 347 + print $2 " should be in " mod_name; 348 + missing++; 349 + } else 350 + matches++; 351 + 352 + total++; 353 + 354 + next; 355 + } 356 + 357 + # Issue the comparison report. 358 + # 359 + END { 360 + if (total) { 361 + printf "Verification of %s:\n", ARGV[1]; 362 + printf " Correct matches: %6d (%d%% of total)\n", matches, 100 * matches / total; 363 + printf " Module matches: %6d (%d%% of matches)\n", mod_matches, 100 * mod_matches / matches; 364 + printf " Mismatches: %6d (%d%% of total)\n", mismatches, 100 * mismatches / total; 365 + printf " Missing: %6d (%d%% of total)\n", missing, 100 * missing / total; 366 + 367 + if (mismatches || missing) 368 + exit(1); 369 + } 370 + }