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.16' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

- Add support for the EXPORT_SYMBOL_GPL_FOR_MODULES() macro, which
exports a symbol only to specified modules

- Improve ABI handling in gendwarfksyms

- Forcibly link lib-y objects to vmlinux even if CONFIG_MODULES=n

- Add checkers for redundant or missing <linux/export.h> inclusion

- Deprecate the extra-y syntax

- Fix a genksyms bug when including enum constants from *.symref files

* tag 'kbuild-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (28 commits)
genksyms: Fix enum consts from a reference affecting new values
arch: use always-$(KBUILD_BUILTIN) for vmlinux.lds
kbuild: set y instead of 1 to KBUILD_{BUILTIN,MODULES}
efi/libstub: use 'targets' instead of extra-y in Makefile
module: make __mod_device_table__* symbols static
scripts/misc-check: check unnecessary #include <linux/export.h> when W=1
scripts/misc-check: check missing #include <linux/export.h> when W=1
scripts/misc-check: add double-quotes to satisfy shellcheck
kbuild: move W=1 check for scripts/misc-check to top-level Makefile
scripts/tags.sh: allow to use alternative ctags implementation
kconfig: introduce menu type enum
docs: symbol-namespaces: fix reST warning with literal block
kbuild: link lib-y objects to vmlinux forcibly even when CONFIG_MODULES=n
tinyconfig: enable CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
docs/core-api/symbol-namespaces: drop table of contents and section numbering
modpost: check forbidden MODULE_IMPORT_NS("module:") at compile time
kbuild: move kbuild syntax processing to scripts/Makefile.build
Makefile: remove dependency on archscripts for header installation
Documentation/kbuild: Add new gendwarfksyms kABI rules
Documentation/kbuild: Drop section numbers
...

+919 -335
+37 -26
Documentation/core-api/symbol-namespaces.rst
··· 6 6 export surface of in-kernel symbols exported through the family of 7 7 EXPORT_SYMBOL() macros. 8 8 9 - .. Table of Contents 10 - 11 - === 1 Introduction 12 - === 2 How to define Symbol Namespaces 13 - --- 2.1 Using the EXPORT_SYMBOL macros 14 - --- 2.2 Using the DEFAULT_SYMBOL_NAMESPACE define 15 - === 3 How to use Symbols exported in Namespaces 16 - === 4 Loading Modules that use namespaced Symbols 17 - === 5 Automatically creating MODULE_IMPORT_NS statements 18 - 19 - 1. Introduction 20 - =============== 9 + Introduction 10 + ============ 21 11 22 12 Symbol Namespaces have been introduced as a means to structure the export 23 13 surface of the in-kernel API. It allows subsystem maintainers to partition ··· 18 28 are required to import the namespace. Otherwise the kernel will, depending on 19 29 its configuration, reject loading the module or warn about a missing import. 20 30 21 - 2. How to define Symbol Namespaces 22 - ================================== 31 + Additionally, it is possible to put symbols into a module namespace, strictly 32 + limiting which modules are allowed to use these symbols. 33 + 34 + How to define Symbol Namespaces 35 + =============================== 23 36 24 37 Symbols can be exported into namespace using different methods. All of them are 25 38 changing the way EXPORT_SYMBOL and friends are instrumented to create ksymtab 26 39 entries. 27 40 28 - 2.1 Using the EXPORT_SYMBOL macros 29 - ================================== 41 + Using the EXPORT_SYMBOL macros 42 + ------------------------------ 30 43 31 44 In addition to the macros EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(), that allow 32 45 exporting of kernel symbols to the kernel symbol table, variants of these are ··· 47 54 and kernel/module/main.c make use the namespace at build time or module load 48 55 time, respectively. 49 56 50 - 2.2 Using the DEFAULT_SYMBOL_NAMESPACE define 51 - ============================================= 57 + Using the DEFAULT_SYMBOL_NAMESPACE define 58 + ----------------------------------------- 52 59 53 60 Defining namespaces for all symbols of a subsystem can be very verbose and may 54 61 become hard to maintain. Therefore a default define (DEFAULT_SYMBOL_NAMESPACE) ··· 76 83 within the corresponding compilation unit before the #include for 77 84 <linux/export.h>. Typically it's placed before the first #include statement. 78 85 79 - 3. How to use Symbols exported in Namespaces 80 - ============================================ 86 + Using the EXPORT_SYMBOL_GPL_FOR_MODULES() macro 87 + ----------------------------------------------- 88 + 89 + Symbols exported using this macro are put into a module namespace. This 90 + namespace cannot be imported. 91 + 92 + The macro takes a comma separated list of module names, allowing only those 93 + modules to access this symbol. Simple tail-globs are supported. 94 + 95 + For example:: 96 + 97 + EXPORT_SYMBOL_GPL_FOR_MODULES(preempt_notifier_inc, "kvm,kvm-*") 98 + 99 + will limit usage of this symbol to modules whoes name matches the given 100 + patterns. 101 + 102 + How to use Symbols exported in Namespaces 103 + ========================================= 81 104 82 105 In order to use symbols that are exported into namespaces, kernel modules need 83 106 to explicitly import these namespaces. Otherwise the kernel might reject to ··· 115 106 116 107 117 108 It is advisable to add the MODULE_IMPORT_NS() statement close to other module 118 - metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE(). Refer to section 119 - 5. for a way to create missing import statements automatically. 109 + metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE(). 120 110 121 - 4. Loading Modules that use namespaced Symbols 122 - ============================================== 111 + Loading Modules that use namespaced Symbols 112 + =========================================== 123 113 124 114 At module loading time (e.g. ``insmod``), the kernel will check each symbol 125 115 referenced from the module for its availability and whether the namespace it ··· 129 121 option is available: Setting MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y will 130 122 enable loading regardless, but will emit a warning. 131 123 132 - 5. Automatically creating MODULE_IMPORT_NS statements 133 - ===================================================== 124 + Automatically creating MODULE_IMPORT_NS statements 125 + ================================================== 134 126 135 127 Missing namespaces imports can easily be detected at build time. In fact, 136 128 modpost will emit a warning if a module uses a symbol from a namespace ··· 162 154 You can also run nsdeps for external module builds. A typical usage is:: 163 155 164 156 $ make -C <path_to_kernel_src> M=$PWD nsdeps 157 + 158 + Note: it will happily generate an import statement for the module namespace; 159 + which will not work and generates build and runtime failures.
+114 -27
Documentation/kbuild/gendwarfksyms.rst
··· 2 2 DWARF module versioning 3 3 ======================= 4 4 5 - 1. Introduction 6 - =============== 5 + Introduction 6 + ============ 7 7 8 8 When CONFIG_MODVERSIONS is enabled, symbol versions for modules 9 9 are typically calculated from preprocessed source code using the ··· 14 14 from the DWARF debugging information, which contains the necessary 15 15 details about the final module ABI. 16 16 17 - 1.1. Usage 18 - ========== 17 + Usage 18 + ----- 19 19 20 20 gendwarfksyms accepts a list of object files on the command line, and a 21 21 list of symbol names (one per line) in standard input:: ··· 33 33 -h, --help Print this message 34 34 35 35 36 - 2. Type information availability 37 - ================================ 36 + Type information availability 37 + ============================= 38 38 39 39 While symbols are typically exported in the same translation unit (TU) 40 40 where they're defined, it's also perfectly fine for a TU to export ··· 56 56 elsewhere. The name of the symbol pointer is expected to start with 57 57 `__gendwarfksyms_ptr_`, followed by the name of the exported symbol. 58 58 59 - 3. Symtypes output format 60 - ========================= 59 + Symtypes output format 60 + ====================== 61 61 62 62 Similarly to genksyms, gendwarfksyms supports writing a symtypes 63 63 file for each processed object that contain types for exported ··· 85 85 DWARF format produced by **--dump-dies**, but with type references 86 86 instead of fully expanded strings. 87 87 88 - 4. Maintaining a stable kABI 89 - ============================ 88 + Maintaining a stable kABI 89 + ========================= 90 90 91 91 Distribution maintainers often need the ability to make ABI compatible 92 92 changes to kernel data structures due to LTS updates or backports. Using ··· 104 104 transform the inputs for symbol versioning, the user is responsible for 105 105 ensuring that their changes actually won't break the ABI. 106 106 107 - 4.1. kABI rules 108 - =============== 107 + kABI rules 108 + ---------- 109 109 110 110 kABI rules allow distributions to fine-tune certain parts 111 111 of gendwarfksyms output and thus control how symbol ··· 125 125 qualified name of the DWARF Debugging Information Entry (DIE). 126 126 - `value`: Provides rule-specific data. 127 127 128 - The following helper macro, for example, can be used to specify rules 128 + The following helper macros, for example, can be used to specify rules 129 129 in the source code:: 130 130 131 - #define __KABI_RULE(hint, target, value) \ 132 - static const char __PASTE(__gendwarfksyms_rule_, \ 131 + #define ___KABI_RULE(hint, target, value) \ 132 + static const char __PASTE(__gendwarfksyms_rule_, \ 133 133 __COUNTER__)[] __used __aligned(1) \ 134 134 __section(".discard.gendwarfksyms.kabi_rules") = \ 135 - "1\0" #hint "\0" #target "\0" #value 135 + "1\0" #hint "\0" target "\0" value 136 + 137 + #define __KABI_RULE(hint, target, value) \ 138 + ___KABI_RULE(hint, #target, #value) 136 139 137 140 138 141 Currently, only the rules discussed in this section are supported, but 139 142 the format is extensible enough to allow further rules to be added as 140 143 need arises. 141 144 142 - 4.1.1. Managing definition visibility 143 - ===================================== 145 + Managing definition visibility 146 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 144 147 145 148 A declaration can change into a full definition when additional includes 146 149 are pulled into the translation unit. This changes the versions of any ··· 171 168 172 169 KABI_DECLONLY(s); 173 170 174 - 4.1.2. Adding enumerators 175 - ========================= 171 + Adding enumerators 172 + ~~~~~~~~~~~~~~~~~~ 176 173 177 174 For enums, all enumerators and their values are included in calculating 178 175 symbol versions, which becomes a problem if we later need to add more ··· 226 223 KABI_ENUMERATOR_IGNORE(e, C); 227 224 KABI_ENUMERATOR_VALUE(e, LAST, 2); 228 225 229 - 4.3. Adding structure members 230 - ============================= 226 + Managing structure size changes 227 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 228 + 229 + A data structure can be partially opaque to modules if its allocation is 230 + handled by the core kernel, and modules only need to access some of its 231 + members. In this situation, it's possible to append new members to the 232 + structure without breaking the ABI, as long as the layout for the original 233 + members remains unchanged. 234 + 235 + To append new members, we can hide them from symbol versioning as 236 + described in section :ref:`Hiding members <hiding_members>`, but we can't 237 + hide the increase in structure size. The `byte_size` rule allows us to 238 + override the structure size used for symbol versioning. 239 + 240 + The rule fields are expected to be as follows: 241 + 242 + - `type`: "byte_size" 243 + - `target`: The fully qualified name of the target data structure 244 + (as shown in **--dump-dies** output). 245 + - `value`: A positive decimal number indicating the structure size 246 + in bytes. 247 + 248 + Using the `__KABI_RULE` macro, this rule can be defined as:: 249 + 250 + #define KABI_BYTE_SIZE(fqn, value) \ 251 + __KABI_RULE(byte_size, fqn, value) 252 + 253 + Example usage:: 254 + 255 + struct s { 256 + /* Unchanged original members */ 257 + unsigned long a; 258 + void *p; 259 + 260 + /* Appended new members */ 261 + KABI_IGNORE(0, unsigned long n); 262 + }; 263 + 264 + KABI_BYTE_SIZE(s, 16); 265 + 266 + Overriding type strings 267 + ~~~~~~~~~~~~~~~~~~~~~~~ 268 + 269 + In rare situations where distributions must make significant changes to 270 + otherwise opaque data structures that have inadvertently been included 271 + in the published ABI, keeping symbol versions stable using the more 272 + targeted kABI rules can become tedious. The `type_string` rule allows us 273 + to override the full type string for a type or a symbol, and even add 274 + types for versioning that no longer exist in the kernel. 275 + 276 + The rule fields are expected to be as follows: 277 + 278 + - `type`: "type_string" 279 + - `target`: The fully qualified name of the target data structure 280 + (as shown in **--dump-dies** output) or symbol. 281 + - `value`: A valid type string (as shown in **--symtypes**) output) 282 + to use instead of the real type. 283 + 284 + Using the `__KABI_RULE` macro, this rule can be defined as:: 285 + 286 + #define KABI_TYPE_STRING(type, str) \ 287 + ___KABI_RULE("type_string", type, str) 288 + 289 + Example usage:: 290 + 291 + /* Override type for a structure */ 292 + KABI_TYPE_STRING("s#s", 293 + "structure_type s { " 294 + "member base_type int byte_size(4) " 295 + "encoding(5) n " 296 + "data_member_location(0) " 297 + "} byte_size(8)"); 298 + 299 + /* Override type for a symbol */ 300 + KABI_TYPE_STRING("my_symbol", "variable s#s"); 301 + 302 + The `type_string` rule should be used only as a last resort if maintaining 303 + a stable symbol versions cannot be reasonably achieved using other 304 + means. Overriding a type string increases the risk of actual ABI breakages 305 + going unnoticed as it hides all changes to the type. 306 + 307 + Adding structure members 308 + ------------------------ 231 309 232 310 Perhaps the most common ABI compatible change is adding a member to a 233 311 kernel data structure. When changes to a structure are anticipated, ··· 321 237 reserved space in data structures and hiding members that don't change 322 238 the ABI when calculating symbol versions. 323 239 324 - 4.3.1. Reserving space and replacing members 325 - ============================================ 240 + Reserving space and replacing members 241 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 326 242 327 243 Space is typically reserved for later use by appending integer types, or 328 244 arrays, to the end of the data structure, but any type can be used. Each ··· 360 276 simplify the process and also ensure the replacement member is correctly 361 277 aligned and its size won't exceed the reserved space. 362 278 363 - 4.3.2. Hiding members 364 - ===================== 279 + .. _hiding_members: 280 + 281 + Hiding members 282 + ~~~~~~~~~~~~~~ 365 283 366 284 Predicting which structures will require changes during the support 367 285 timeframe isn't always possible, in which case one might have to resort ··· 391 305 unsigned long b; 392 306 }; 393 307 394 - With **--stable**, both versions produce the same symbol version. 308 + With **--stable**, both versions produce the same symbol version. The 309 + examples include a `KABI_IGNORE` macro to simplify the code.
+4
Documentation/kbuild/makefiles.rst
··· 291 291 # arch/x86/kernel/Makefile 292 292 extra-y += vmlinux.lds 293 293 294 + extra-y is now deprecated because this is equivalent to: 295 + 296 + always-$(KBUILD_BUILTIN) += vmlinux.lds 297 + 294 298 $(extra-y) should only contain targets needed for vmlinux. 295 299 296 300 Kbuild skips extra-y when vmlinux is apparently not a final goal.
+15 -17
Documentation/translations/it_IT/core-api/symbol-namespaces.rst
··· 10 10 per strutturare quello che viene esportato internamente al kernel 11 11 grazie alle macro della famiglia EXPORT_SYMBOL(). 12 12 13 - 1. Introduzione 14 - =============== 13 + Introduzione 14 + ============ 15 15 16 16 Lo spazio dei nomi dei simboli è stato introdotto come mezzo per strutturare 17 17 l'API esposta internamente al kernel. Permette ai manutentori di un ··· 24 24 della configurazione, potrebbe rifiutare di caricare il modulo o 25 25 avvisare l'utente di un'importazione mancante. 26 26 27 - 2. Come definire uno spazio dei nomi dei simboli 28 - ================================================ 27 + Come definire uno spazio dei nomi dei simboli 28 + ============================================= 29 29 30 30 I simboli possono essere esportati in spazi dei nomi usando diversi 31 31 meccanismi. Tutti questi meccanismi cambiano il modo in cui 32 32 EXPORT_SYMBOL e simili vengono guidati verso la creazione di voci in ksymtab. 33 33 34 - 2.1 Usare le macro EXPORT_SYMBOL 35 - ================================ 34 + Usare le macro EXPORT_SYMBOL 35 + ---------------------------- 36 36 37 37 In aggiunta alle macro EXPORT_SYMBOL() e EXPORT_SYMBOL_GPL(), che permettono 38 38 di esportare simboli del kernel nella rispettiva tabella, ci sono ··· 53 53 spazio dei nomi, rispettivamente, durante la compilazione e durante il 54 54 caricamento di un modulo. 55 55 56 - 2.2 Usare il simbolo di preprocessore DEFAULT_SYMBOL_NAMESPACE 57 - ============================================================== 56 + Usare il simbolo di preprocessore DEFAULT_SYMBOL_NAMESPACE 57 + ---------------------------------------------------------- 58 58 59 59 Definire lo spazio dei nomi per tutti i simboli di un sottosistema può essere 60 60 logorante e di difficile manutenzione. Perciò è stato fornito un simbolo ··· 83 83 84 84 Questo va messo prima di un qualsiasi uso di EXPORT_SYMBOL. 85 85 86 - 3. Come usare i simboli esportati attraverso uno spazio dei nomi 87 - ================================================================ 86 + Come usare i simboli esportati attraverso uno spazio dei nomi 87 + ============================================================= 88 88 89 89 Per usare i simboli esportati da uno spazio dei nomi, i moduli del 90 90 kernel devono esplicitamente importare il relativo spazio dei nomi; altrimenti ··· 108 108 109 109 110 110 Si consiglia di posizionare la dichiarazione MODULE_IMPORT_NS() vicino 111 - ai metadati del modulo come MODULE_AUTHOR() o MODULE_LICENSE(). Fate 112 - riferimento alla sezione 5. per creare automaticamente le importazioni 113 - mancanti. 111 + ai metadati del modulo come MODULE_AUTHOR() o MODULE_LICENSE(). 114 112 115 - 4. Caricare moduli che usano simboli provenienti da spazi dei nomi 116 - ================================================================== 113 + Caricare moduli che usano simboli provenienti da spazi dei nomi 114 + =============================================================== 117 115 118 116 Quando un modulo viene caricato (per esempio usando ``insmod``), il kernel 119 117 verificherà la disponibilità di ogni simbolo usato e se lo spazio dei nomi ··· 123 125 MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y caricherà i moduli comunque ma 124 126 emetterà un avviso. 125 127 126 - 5. Creare automaticamente la dichiarazione MODULE_IMPORT_NS 127 - =========================================================== 128 + Creare automaticamente la dichiarazione MODULE_IMPORT_NS 129 + ======================================================== 128 130 129 131 La mancanza di un'importazione può essere individuata facilmente al momento 130 132 della compilazione. Infatti, modpost emetterà un avviso se il modulo usa
+15 -26
Documentation/translations/zh_CN/core-api/symbol-namespaces.rst
··· 14 14 15 15 本文档描述了如何使用符号命名空间来构造通过EXPORT_SYMBOL()系列宏导出的内核内符号的导出面。 16 16 17 - .. 目录 18 - 19 - === 1 简介 20 - === 2 如何定义符号命名空间 21 - --- 2.1 使用EXPORT_SYMBOL宏 22 - --- 2.2 使用DEFAULT_SYMBOL_NAMESPACE定义 23 - === 3 如何使用命名空间中导出的符号 24 - === 4 加载使用命名空间符号的模块 25 - === 5 自动创建MODULE_IMPORT_NS声明 26 - 27 - 1. 简介 28 - ======= 17 + 简介 18 + ==== 29 19 30 20 符号命名空间已经被引入,作为构造内核内API的导出面的一种手段。它允许子系统维护者将 31 21 他们导出的符号划分进独立的命名空间。这对于文档的编写非常有用(想想SUBSYSTEM_DEBUG ··· 23 33 的模块必须导入命名空间。否则,内核将根据其配置,拒绝加载该模块或警告说缺少 24 34 导入。 25 35 26 - 2. 如何定义符号命名空间 27 - ======================= 36 + 如何定义符号命名空间 37 + ==================== 28 38 29 39 符号可以用不同的方法导出到命名空间。所有这些都在改变 EXPORT_SYMBOL 和与之类似的那些宏 30 40 被检测到的方式,以创建 ksymtab 条目。 31 41 32 - 2.1 使用EXPORT_SYMBOL宏 33 - ======================= 42 + 使用EXPORT_SYMBOL宏 43 + ------------------- 34 44 35 45 除了允许将内核符号导出到内核符号表的宏EXPORT_SYMBOL()和EXPORT_SYMBOL_GPL()之外, 36 46 这些宏的变体还可以将符号导出到某个命名空间:EXPORT_SYMBOL_NS() 和 EXPORT_SYMBOL_NS_GPL()。 ··· 44 54 导出时未指明命名空间的符号将指向 ``NULL`` 。如果没有定义命名空间,则默认没有。 45 55 ``modpost`` 和kernel/module/main.c分别在构建时或模块加载时使用名称空间。 46 56 47 - 2.2 使用DEFAULT_SYMBOL_NAMESPACE定义 48 - ==================================== 57 + 使用DEFAULT_SYMBOL_NAMESPACE定义 58 + -------------------------------- 49 59 50 60 为一个子系统的所有符号定义命名空间可能会非常冗长,并可能变得难以维护。因此,我 51 61 们提供了一个默认定义(DEFAULT_SYMBOL_NAMESPACE),如果设置了这个定义, 它将成 ··· 70 80 71 81 应置于相关编译单元中任何 EXPORT_SYMBOL 宏之前 72 82 73 - 3. 如何使用命名空间中导出的符号 74 - =============================== 83 + 如何使用命名空间中导出的符号 84 + ============================ 75 85 76 86 为了使用被导出到命名空间的符号,内核模块需要明确地导入这些命名空间。 77 87 否则内核可能会拒绝加载该模块。模块代码需要使用宏MODULE_IMPORT_NS来 ··· 90 100 91 101 92 102 建议将 MODULE_IMPORT_NS() 语句添加到靠近其他模块元数据定义的地方, 93 - 如 MODULE_AUTHOR() 或 MODULE_LICENSE() 。关于自动创建缺失的导入 94 - 语句的方法,请参考第5节。 103 + 如 MODULE_AUTHOR() 或 MODULE_LICENSE() 。 95 104 96 - 4. 加载使用命名空间符号的模块 97 - ============================= 105 + 加载使用命名空间符号的模块 106 + ========================== 98 107 99 108 在模块加载时(比如 ``insmod`` ),内核将检查每个从模块中引用的符号是否可 100 109 用,以及它可能被导出到的名字空间是否被模块导入。内核的默认行为是拒绝 ··· 102 113 设置 MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y 将使加载不受影响,但会 103 114 发出警告。 104 115 105 - 5. 自动创建MODULE_IMPORT_NS声明 106 - =============================== 116 + 自动创建MODULE_IMPORT_NS声明 117 + ============================ 107 118 108 119 缺少命名空间的导入可以在构建时很容易被检测到。事实上,如果一个模块 109 120 使用了一个命名空间的符号而没有导入它,modpost会发出警告。
+13 -15
Makefile
··· 754 754 # Normally, just do built-in. 755 755 756 756 KBUILD_MODULES := 757 - KBUILD_BUILTIN := 1 757 + KBUILD_BUILTIN := y 758 758 759 759 # If we have only "make modules", don't compile built-in objects. 760 760 ifeq ($(MAKECMDGOALS),modules) ··· 766 766 # Just "make" or "make all" shall build modules as well 767 767 768 768 ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMDGOALS)),) 769 - KBUILD_MODULES := 1 769 + KBUILD_MODULES := y 770 770 endif 771 771 772 772 ifeq ($(MAKECMDGOALS),) 773 - KBUILD_MODULES := 1 773 + KBUILD_MODULES := y 774 774 endif 775 775 776 776 export KBUILD_MODULES KBUILD_BUILTIN ··· 1189 1189 export ARCH_DRIVERS := $(drivers-y) $(drivers-m) 1190 1190 # Externally visible symbols (used by link-vmlinux.sh) 1191 1191 1192 - KBUILD_VMLINUX_OBJS := ./built-in.a 1193 - ifdef CONFIG_MODULES 1194 - KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) 1192 + KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) 1195 1193 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) 1196 - else 1197 - KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) 1198 - endif 1199 1194 1200 1195 export KBUILD_VMLINUX_LIBS 1201 1196 export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds ··· 1198 1203 ifdef CONFIG_TRIM_UNUSED_KSYMS 1199 1204 # For the kernel to actually contain only the needed exported symbols, 1200 1205 # we have to build modules as well to determine what those symbols are. 1201 - KBUILD_MODULES := 1 1206 + KBUILD_MODULES := y 1202 1207 endif 1203 1208 1204 1209 # '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14 ··· 1365 1370 hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 1366 1371 1367 1372 PHONY += headers 1368 - headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts 1373 + headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders 1369 1374 ifdef HEADER_ARCH 1370 1375 $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers 1371 1376 else ··· 1538 1543 # the built-in objects during the descend as well, in order to 1539 1544 # make sure the checksums are up to date before we record them. 1540 1545 ifdef CONFIG_MODVERSIONS 1541 - KBUILD_BUILTIN := 1 1546 + KBUILD_BUILTIN := y 1542 1547 endif 1543 1548 1544 1549 # Build modules ··· 1547 1552 # *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES 1548 1553 # is an exception. 1549 1554 ifdef CONFIG_DEBUG_INFO_BTF_MODULES 1550 - KBUILD_BUILTIN := 1 1555 + KBUILD_BUILTIN := y 1551 1556 modules: vmlinux 1552 1557 endif 1553 1558 ··· 1832 1837 # Misc 1833 1838 # --------------------------------------------------------------------------- 1834 1839 1840 + # Run misc checks when ${KBUILD_EXTRA_WARN} contains 1 1835 1841 PHONY += misc-check 1842 + ifneq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) 1836 1843 misc-check: 1837 1844 $(Q)$(srctree)/scripts/misc-check 1845 + endif 1838 1846 1839 1847 all: misc-check 1840 1848 ··· 1863 1865 1864 1866 # We are always building only modules. 1865 1867 KBUILD_BUILTIN := 1866 - KBUILD_MODULES := 1 1868 + KBUILD_MODULES := y 1867 1869 1868 1870 build-dir := . 1869 1871 ··· 1991 1993 1992 1994 single-goals := $(addprefix $(build-dir)/, $(single-no-ko)) 1993 1995 1994 - KBUILD_MODULES := 1 1996 + KBUILD_MODULES := y 1995 1997 1996 1998 endif 1997 1999
+1 -1
arch/alpha/kernel/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - extra-y := vmlinux.lds 6 + always-$(KBUILD_BUILTIN) := vmlinux.lds 7 7 asflags-y := $(KBUILD_CFLAGS) 8 8 ccflags-y := -Wno-sign-compare 9 9
+1 -1
arch/arc/kernel/Makefile
··· 26 26 CFLAGS_fpu.o += -mdpfp 27 27 endif 28 28 29 - extra-y := vmlinux.lds 29 + always-$(KBUILD_BUILTIN) := vmlinux.lds
+1 -1
arch/arm/kernel/Makefile
··· 104 104 105 105 obj-$(CONFIG_GENERIC_CPU_VULNERABILITIES) += spectre.o 106 106 107 - extra-y := vmlinux.lds 107 + always-$(KBUILD_BUILTIN) := vmlinux.lds
+1 -1
arch/arm64/kernel/Makefile
··· 78 78 79 79 obj-y += probes/ 80 80 obj-y += head.o 81 - extra-y += vmlinux.lds 81 + always-$(KBUILD_BUILTIN) += vmlinux.lds 82 82 83 83 ifeq ($(CONFIG_DEBUG_EFI),y) 84 84 AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
+1 -1
arch/csky/kernel/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 - extra-y := vmlinux.lds 2 + always-$(KBUILD_BUILTIN) := vmlinux.lds 3 3 4 4 obj-y += head.o entry.o atomic.o signal.o traps.o irq.o time.o vdso.o vdso/ 5 5 obj-y += power.o syscall.o syscall_table.o setup.o
+1 -1
arch/hexagon/kernel/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - extra-y := vmlinux.lds 2 + always-$(KBUILD_BUILTIN) := vmlinux.lds 3 3 4 4 obj-y += head.o 5 5 obj-$(CONFIG_SMP) += smp.o
+1 -1
arch/loongarch/kernel/Makefile
··· 5 5 6 6 OBJECT_FILES_NON_STANDARD_head.o := y 7 7 8 - extra-y := vmlinux.lds 8 + always-$(KBUILD_BUILTIN) := vmlinux.lds 9 9 10 10 obj-y += head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \ 11 11 traps.o irq.o idle.o process.o dma.o mem.o reset.o switch.o \
+1 -1
arch/m68k/kernel/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - extra-y += vmlinux.lds 6 + always-$(KBUILD_BUILTIN) += vmlinux.lds 7 7 8 8 obj-$(CONFIG_MMU_MOTOROLA) := head.o 9 9 obj-$(CONFIG_SUN3) := sun3-head.o
+1 -1
arch/microblaze/kernel/Makefile
··· 11 11 CFLAGS_REMOVE_process.o = -pg 12 12 endif 13 13 14 - extra-y := vmlinux.lds 14 + always-$(KBUILD_BUILTIN) := vmlinux.lds 15 15 16 16 obj-y += head.o dma.o exceptions.o \ 17 17 hw_exception_handler.o irq.o \
+1 -1
arch/mips/kernel/Makefile
··· 3 3 # Makefile for the Linux/MIPS kernel. 4 4 # 5 5 6 - extra-y := vmlinux.lds 6 + always-$(KBUILD_BUILTIN) := vmlinux.lds 7 7 8 8 obj-y += head.o branch.o cmpxchg.o elf.o entry.o genex.o idle.o irq.o \ 9 9 process.o prom.o ptrace.o reset.o setup.o signal.o \
+1 -1
arch/nios2/kernel/Makefile
··· 3 3 # Makefile for the nios2 linux kernel. 4 4 # 5 5 6 - extra-y += vmlinux.lds 6 + always-$(KBUILD_BUILTIN) += vmlinux.lds 7 7 8 8 obj-y += head.o 9 9 obj-y += cpuinfo.o
+1 -1
arch/openrisc/kernel/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - extra-y := vmlinux.lds 6 + always-$(KBUILD_BUILTIN) := vmlinux.lds 7 7 8 8 obj-y := head.o setup.o or32_ksyms.o process.o dma.o \ 9 9 traps.o time.o irq.o entry.o ptrace.o signal.o \
+1 -1
arch/parisc/kernel/Makefile
··· 3 3 # Makefile for arch/parisc/kernel 4 4 # 5 5 6 - extra-y := vmlinux.lds 6 + always-$(KBUILD_BUILTIN) := vmlinux.lds 7 7 8 8 obj-y := head.o cache.o pacache.o setup.o pdt.o traps.o time.o irq.o \ 9 9 syscall.o entry.o sys_parisc.o firmware.o \
+1 -1
arch/powerpc/kernel/Makefile
··· 126 126 obj-$(CONFIG_44x) += head_44x.o 127 127 obj-$(CONFIG_PPC_8xx) += head_8xx.o 128 128 obj-$(CONFIG_PPC_85xx) += head_85xx.o 129 - extra-y += vmlinux.lds 129 + always-$(KBUILD_BUILTIN) += vmlinux.lds 130 130 131 131 obj-$(CONFIG_RELOCATABLE) += reloc_$(BITS).o 132 132
+1 -1
arch/riscv/kernel/Makefile
··· 43 43 endif 44 44 endif 45 45 46 - extra-y += vmlinux.lds 46 + always-$(KBUILD_BUILTIN) += vmlinux.lds 47 47 48 48 obj-y += head.o 49 49 obj-y += soc.o
+1 -1
arch/s390/kernel/Makefile
··· 46 46 obj-y += smp.o text_amode31.o stacktrace.o abs_lowcore.o facility.o uv.o wti.o 47 47 obj-y += diag/ 48 48 49 - extra-y += vmlinux.lds 49 + always-$(KBUILD_BUILTIN) += vmlinux.lds 50 50 51 51 obj-$(CONFIG_SYSFS) += nospec-sysfs.o 52 52 CFLAGS_REMOVE_nospec-branch.o += $(CC_FLAGS_EXPOLINE)
+1 -1
arch/sh/kernel/Makefile
··· 3 3 # Makefile for the Linux/SuperH kernel. 4 4 # 5 5 6 - extra-y := vmlinux.lds 6 + always-$(KBUILD_BUILTIN) := vmlinux.lds 7 7 8 8 ifdef CONFIG_FUNCTION_TRACER 9 9 # Do not profile debug and lowlevel utilities
+1 -1
arch/sparc/kernel/Makefile
··· 9 9 # Undefine sparc when processing vmlinux.lds - it is used 10 10 # And teach CPP we are doing $(BITS) builds (for this case) 11 11 CPPFLAGS_vmlinux.lds := -Usparc -m$(BITS) 12 - extra-y += vmlinux.lds 12 + always-$(KBUILD_BUILTIN) += vmlinux.lds 13 13 14 14 ifdef CONFIG_FUNCTION_TRACER 15 15 # Do not profile debug and lowlevel utilities
+1 -1
arch/um/kernel/Makefile
··· 12 12 -DELF_ARCH=$(LDS_ELF_ARCH) \ 13 13 -DELF_FORMAT=$(LDS_ELF_FORMAT) \ 14 14 $(LDS_EXTRA) 15 - extra-y := vmlinux.lds 15 + always-$(KBUILD_BUILTIN) := vmlinux.lds 16 16 17 17 obj-y = config.o exec.o exitcode.o irq.o ksyms.o mem.o \ 18 18 physmem.o process.o ptrace.o reboot.o sigio.o \
+1 -1
arch/x86/kernel/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - extra-y += vmlinux.lds 6 + always-$(KBUILD_BUILTIN) += vmlinux.lds 7 7 8 8 CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE) 9 9
+1 -1
arch/xtensa/kernel/Makefile
··· 3 3 # Makefile for the Linux/Xtensa kernel. 4 4 # 5 5 6 - extra-y := vmlinux.lds 6 + always-$(KBUILD_BUILTIN) := vmlinux.lds 7 7 8 8 obj-y := head.o align.o coprocessor.o entry.o irq.o platform.o process.o \ 9 9 ptrace.o setup.o signal.o stacktrace.o syscall.o time.o traps.o \
+1 -1
drivers/firmware/efi/libstub/Makefile
··· 101 101 102 102 lib-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o bitmap.o find.o 103 103 104 - extra-y := $(lib-y) 104 + targets := $(lib-y) 105 105 lib-y := $(patsubst %.o,%.stub.o,$(lib-y)) 106 106 107 107 # Even when -mbranch-protection=none is set, Clang will generate a
+10 -2
include/linux/export.h
··· 24 24 .long sym 25 25 #endif 26 26 27 - #define ___EXPORT_SYMBOL(sym, license, ns) \ 27 + /* 28 + * LLVM integrated assembler cam merge adjacent string literals (like 29 + * C and GNU-as) passed to '.ascii', but not to '.asciz' and chokes on: 30 + * 31 + * .asciz "MODULE_" "kvm" ; 32 + */ 33 + #define ___EXPORT_SYMBOL(sym, license, ns...) \ 28 34 .section ".export_symbol","a" ASM_NL \ 29 35 __export_symbol_##sym: ASM_NL \ 30 36 .asciz license ASM_NL \ 31 - .asciz ns ASM_NL \ 37 + .ascii ns "\0" ASM_NL \ 32 38 __EXPORT_SYMBOL_REF(sym) ASM_NL \ 33 39 .previous 34 40 ··· 90 84 #define EXPORT_SYMBOL_GPL(sym) _EXPORT_SYMBOL(sym, "GPL") 91 85 #define EXPORT_SYMBOL_NS(sym, ns) __EXPORT_SYMBOL(sym, "", ns) 92 86 #define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "GPL", ns) 87 + 88 + #define EXPORT_SYMBOL_GPL_FOR_MODULES(sym, mods) __EXPORT_SYMBOL(sym, "GPL", "module:" mods) 93 89 94 90 #endif /* _LINUX_EXPORT_H */
+2 -2
include/linux/module.h
··· 249 249 #ifdef MODULE 250 250 /* Creates an alias so file2alias.c can find device table. */ 251 251 #define MODULE_DEVICE_TABLE(type, name) \ 252 - extern typeof(name) __mod_device_table__##type##__##name \ 253 - __attribute__ ((unused, alias(__stringify(name)))) 252 + static typeof(name) __mod_device_table__##type##__##name \ 253 + __attribute__ ((used, alias(__stringify(name)))) 254 254 #else /* !MODULE */ 255 255 #define MODULE_DEVICE_TABLE(type, name) 256 256 #endif
+1
kernel/configs/tiny.config
··· 2 2 CONFIG_KERNEL_XZ=y 3 3 CONFIG_SLUB=y 4 4 CONFIG_SLUB_TINY=y 5 + CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y
+87 -2
kernel/module/main.c
··· 170 170 } 171 171 172 172 /* 173 + * Like strncmp(), except s/-/_/g as per scripts/Makefile.lib:name-fix-token rule. 174 + */ 175 + static int mod_strncmp(const char *str_a, const char *str_b, size_t n) 176 + { 177 + for (int i = 0; i < n; i++) { 178 + char a = str_a[i]; 179 + char b = str_b[i]; 180 + int d; 181 + 182 + if (a == '-') a = '_'; 183 + if (b == '-') b = '_'; 184 + 185 + d = a - b; 186 + if (d) 187 + return d; 188 + 189 + if (!a) 190 + break; 191 + } 192 + 193 + return 0; 194 + } 195 + 196 + /* 173 197 * A thread that wants to hold a reference to a module only while it 174 198 * is running can call this to safely exit. 175 199 */ ··· 1107 1083 return get_next_modinfo(info, tag, NULL); 1108 1084 } 1109 1085 1086 + /** 1087 + * verify_module_namespace() - does @modname have access to this symbol's @namespace 1088 + * @namespace: export symbol namespace 1089 + * @modname: module name 1090 + * 1091 + * If @namespace is prefixed with "module:" to indicate it is a module namespace 1092 + * then test if @modname matches any of the comma separated patterns. 1093 + * 1094 + * The patterns only support tail-glob. 1095 + */ 1096 + static bool verify_module_namespace(const char *namespace, const char *modname) 1097 + { 1098 + size_t len, modlen = strlen(modname); 1099 + const char *prefix = "module:"; 1100 + const char *sep; 1101 + bool glob; 1102 + 1103 + if (!strstarts(namespace, prefix)) 1104 + return false; 1105 + 1106 + for (namespace += strlen(prefix); *namespace; namespace = sep) { 1107 + sep = strchrnul(namespace, ','); 1108 + len = sep - namespace; 1109 + 1110 + glob = false; 1111 + if (sep[-1] == '*') { 1112 + len--; 1113 + glob = true; 1114 + } 1115 + 1116 + if (*sep) 1117 + sep++; 1118 + 1119 + if (mod_strncmp(namespace, modname, len) == 0 && (glob || len == modlen)) 1120 + return true; 1121 + } 1122 + 1123 + return false; 1124 + } 1125 + 1110 1126 static int verify_namespace_is_imported(const struct load_info *info, 1111 1127 const struct kernel_symbol *sym, 1112 1128 struct module *mod) ··· 1156 1092 1157 1093 namespace = kernel_symbol_namespace(sym); 1158 1094 if (namespace && namespace[0]) { 1095 + 1096 + if (verify_module_namespace(namespace, mod->name)) 1097 + return 0; 1098 + 1159 1099 for_each_modinfo_entry(imported_namespace, info, "import_ns") { 1160 1100 if (strcmp(namespace, imported_namespace) == 0) 1161 1101 return 0; ··· 1726 1658 } 1727 1659 } 1728 1660 1729 - static void setup_modinfo(struct module *mod, struct load_info *info) 1661 + static int setup_modinfo(struct module *mod, struct load_info *info) 1730 1662 { 1731 1663 const struct module_attribute *attr; 1664 + char *imported_namespace; 1732 1665 int i; 1733 1666 1734 1667 for (i = 0; (attr = modinfo_attrs[i]); i++) { 1735 1668 if (attr->setup) 1736 1669 attr->setup(mod, get_modinfo(info, attr->attr.name)); 1737 1670 } 1671 + 1672 + for_each_modinfo_entry(imported_namespace, info, "import_ns") { 1673 + /* 1674 + * 'module:' prefixed namespaces are implicit, disallow 1675 + * explicit imports. 1676 + */ 1677 + if (strstarts(imported_namespace, "module:")) { 1678 + pr_err("%s: module tries to import module namespace: %s\n", 1679 + mod->name, imported_namespace); 1680 + return -EPERM; 1681 + } 1682 + } 1683 + 1684 + return 0; 1738 1685 } 1739 1686 1740 1687 static void free_modinfo(struct module *mod) ··· 3406 3323 goto free_unload; 3407 3324 3408 3325 /* Set up MODINFO_ATTR fields */ 3409 - setup_modinfo(mod, info); 3326 + err = setup_modinfo(mod, info); 3327 + if (err) 3328 + goto free_modinfo; 3410 3329 3411 3330 /* Fix up syms, so that st_value is a pointer to location. */ 3412 3331 err = simplify_symbols(mod, info);
+84
scripts/Makefile.build
··· 37 37 include $(kbuild-file) 38 38 include $(srctree)/scripts/Makefile.lib 39 39 40 + # flags that take effect in current and sub directories 41 + KBUILD_AFLAGS += $(subdir-asflags-y) 42 + KBUILD_CFLAGS += $(subdir-ccflags-y) 43 + KBUILD_RUSTFLAGS += $(subdir-rustflags-y) 44 + 45 + # Figure out what we need to build from the various variables 46 + # =========================================================================== 47 + 48 + # When an object is listed to be built compiled-in and modular, 49 + # only build the compiled-in version 50 + obj-m := $(filter-out $(obj-y),$(obj-m)) 51 + 52 + # Libraries are always collected in one lib file. 53 + # Filter out objects already built-in 54 + lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 55 + 56 + # Subdirectories we need to descend into 57 + subdir-ym := $(sort $(subdir-y) $(subdir-m) \ 58 + $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) 59 + 60 + # Handle objects in subdirs: 61 + # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and 62 + # foo/modules.order 63 + # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order 64 + # 65 + # Generate modules.order to determine modorder. Unfortunately, we don't have 66 + # information about ordering between -y and -m subdirs. Just put -y's first. 67 + 68 + ifdef need-modorder 69 + obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m)) 70 + else 71 + obj-m := $(filter-out %/, $(obj-m)) 72 + endif 73 + 74 + ifdef need-builtin 75 + obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) 76 + else 77 + obj-y := $(filter-out %/, $(obj-y)) 78 + endif 79 + 80 + # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals 81 + suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s)))) 82 + # List composite targets that are constructed by combining other targets 83 + multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m))) 84 + # List primitive targets that are compiled from source files 85 + real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m)) 86 + 87 + # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object 88 + multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y) 89 + multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m) 90 + multi-obj-ym := $(multi-obj-y) $(multi-obj-m) 91 + 92 + # Replace multi-part objects by their individual parts, 93 + # including built-in.a from subdirectories 94 + real-obj-y := $(call real-search, $(obj-y), .o, -objs -y) 95 + real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m) 96 + 97 + always-y += $(always-m) 98 + 99 + # hostprogs-always-y += foo 100 + # ... is a shorthand for 101 + # hostprogs += foo 102 + # always-y += foo 103 + hostprogs += $(hostprogs-always-y) $(hostprogs-always-m) 104 + always-y += $(hostprogs-always-y) $(hostprogs-always-m) 105 + 106 + # userprogs-always-y is likewise. 107 + userprogs += $(userprogs-always-y) $(userprogs-always-m) 108 + always-y += $(userprogs-always-y) $(userprogs-always-m) 109 + 110 + # Add subdir path 111 + 112 + ifneq ($(obj),.) 113 + extra-y := $(addprefix $(obj)/, $(extra-y)) 114 + always-y := $(addprefix $(obj)/, $(always-y)) 115 + targets := $(addprefix $(obj)/, $(targets)) 116 + obj-m := $(addprefix $(obj)/, $(obj-m)) 117 + lib-y := $(addprefix $(obj)/, $(lib-y)) 118 + real-obj-y := $(addprefix $(obj)/, $(real-obj-y)) 119 + real-obj-m := $(addprefix $(obj)/, $(real-obj-m)) 120 + multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) 121 + subdir-ym := $(addprefix $(obj)/, $(subdir-ym)) 122 + endif 123 + 40 124 ifndef obj 41 125 $(warning kbuild: Makefile.build is included improperly) 42 126 endif
-84
scripts/Makefile.lib
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - # flags that take effect in current and sub directories 4 - KBUILD_AFLAGS += $(subdir-asflags-y) 5 - KBUILD_CFLAGS += $(subdir-ccflags-y) 6 - KBUILD_RUSTFLAGS += $(subdir-rustflags-y) 7 - 8 - # Figure out what we need to build from the various variables 9 - # =========================================================================== 10 - 11 - # When an object is listed to be built compiled-in and modular, 12 - # only build the compiled-in version 13 - obj-m := $(filter-out $(obj-y),$(obj-m)) 14 - 15 - # Libraries are always collected in one lib file. 16 - # Filter out objects already built-in 17 - lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 18 - 19 - # Subdirectories we need to descend into 20 - subdir-ym := $(sort $(subdir-y) $(subdir-m) \ 21 - $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) 22 - 23 - # Handle objects in subdirs: 24 - # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and 25 - # foo/modules.order 26 - # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order 27 - # 28 - # Generate modules.order to determine modorder. Unfortunately, we don't have 29 - # information about ordering between -y and -m subdirs. Just put -y's first. 30 - 31 - ifdef need-modorder 32 - obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m)) 33 - else 34 - obj-m := $(filter-out %/, $(obj-m)) 35 - endif 36 - 37 - ifdef need-builtin 38 - obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) 39 - else 40 - obj-y := $(filter-out %/, $(obj-y)) 41 - endif 42 - 43 - # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals 44 - suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s)))) 45 - # List composite targets that are constructed by combining other targets 46 - multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m))) 47 - # List primitive targets that are compiled from source files 48 - real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m)) 49 - 50 - # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object 51 - multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y) 52 - multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m) 53 - multi-obj-ym := $(multi-obj-y) $(multi-obj-m) 54 - 55 - # Replace multi-part objects by their individual parts, 56 - # including built-in.a from subdirectories 57 - real-obj-y := $(call real-search, $(obj-y), .o, -objs -y) 58 - real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m) 59 - 60 - always-y += $(always-m) 61 - 62 - # hostprogs-always-y += foo 63 - # ... is a shorthand for 64 - # hostprogs += foo 65 - # always-y += foo 66 - hostprogs += $(hostprogs-always-y) $(hostprogs-always-m) 67 - always-y += $(hostprogs-always-y) $(hostprogs-always-m) 68 - 69 - # userprogs-always-y is likewise. 70 - userprogs += $(userprogs-always-y) $(userprogs-always-m) 71 - always-y += $(userprogs-always-y) $(userprogs-always-m) 72 - 73 - # Add subdir path 74 - 75 - ifneq ($(obj),.) 76 - extra-y := $(addprefix $(obj)/,$(extra-y)) 77 - always-y := $(addprefix $(obj)/,$(always-y)) 78 - targets := $(addprefix $(obj)/,$(targets)) 79 - obj-m := $(addprefix $(obj)/,$(obj-m)) 80 - lib-y := $(addprefix $(obj)/,$(lib-y)) 81 - real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) 82 - real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) 83 - multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) 84 - subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 85 - endif 86 - 87 3 # Finds the multi-part object the current object will be linked into. 88 4 # If the object belongs to two or more multi-part objects, list them all. 89 5 modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
+13 -1
scripts/gendwarfksyms/dwarf.c
··· 228 228 DEFINE_PROCESS_UDATA_ATTRIBUTE(accessibility) 229 229 DEFINE_PROCESS_UDATA_ATTRIBUTE(alignment) 230 230 DEFINE_PROCESS_UDATA_ATTRIBUTE(bit_size) 231 - DEFINE_PROCESS_UDATA_ATTRIBUTE(byte_size) 232 231 DEFINE_PROCESS_UDATA_ATTRIBUTE(encoding) 233 232 DEFINE_PROCESS_UDATA_ATTRIBUTE(data_bit_offset) 234 233 DEFINE_PROCESS_UDATA_ATTRIBUTE(data_member_location) 235 234 DEFINE_PROCESS_UDATA_ATTRIBUTE(discr_value) 235 + 236 + static void process_byte_size_attr(struct die *cache, Dwarf_Die *die) 237 + { 238 + Dwarf_Word value; 239 + unsigned long override; 240 + 241 + if (get_udata_attr(die, DW_AT_byte_size, &value)) { 242 + if (stable && kabi_get_byte_size(cache->fqn, &override)) 243 + value = override; 244 + 245 + process_fmt(cache, " byte_size(%" PRIu64 ")", value); 246 + } 247 + } 236 248 237 249 /* Match functions -- die_match_callback_t */ 238 250 #define DEFINE_MATCH(type) \
+19 -2
scripts/gendwarfksyms/examples/kabi.h
··· 37 37 #define __stringify(x...) __stringify_1(x) 38 38 #endif 39 39 40 - #define __KABI_RULE(hint, target, value) \ 40 + #define ___KABI_RULE(hint, target, value) \ 41 41 static const char __PASTE(__gendwarfksyms_rule_, \ 42 42 __COUNTER__)[] __used __aligned(1) \ 43 43 __section(".discard.gendwarfksyms.kabi_rules") = \ 44 - "1\0" #hint "\0" #target "\0" #value 44 + "1\0" #hint "\0" target "\0" value 45 + 46 + #define __KABI_RULE(hint, target, value) \ 47 + ___KABI_RULE(hint, #target, #value) 45 48 46 49 #define __KABI_NORMAL_SIZE_ALIGN(_orig, _new) \ 47 50 union { \ ··· 91 88 */ 92 89 #define KABI_ENUMERATOR_VALUE(fqn, field, value) \ 93 90 __KABI_RULE(enumerator_value, fqn field, value) 91 + 92 + /* 93 + * KABI_BYTE_SIZE(fqn, value) 94 + * Set the byte_size attribute for the struct/union/enum fqn to 95 + * value bytes. 96 + */ 97 + #define KABI_BYTE_SIZE(fqn, value) __KABI_RULE(byte_size, fqn, value) 98 + 99 + /* 100 + * KABI_TYPE_STRING(type, str) 101 + * For the given type, override the type string used in symtypes 102 + * output and version calculation with str. 103 + */ 104 + #define KABI_TYPE_STRING(type, str) ___KABI_RULE(type_string, type, str) 94 105 95 106 /* 96 107 * KABI_RESERVE
+7
scripts/gendwarfksyms/examples/kabi_ex.c
··· 28 28 struct ex3a ex3a; 29 29 struct ex3b ex3b; 30 30 struct ex3c ex3c; 31 + 32 + struct ex4a ex4a; 33 + 34 + struct ex5a ex5a; 35 + struct ex5b ex5b; 36 + 37 + int ex6a;
+99 -2
scripts/gendwarfksyms/examples/kabi_ex.h
··· 21 21 * ./gendwarfksyms --stable --dump-dies \ 22 22 * examples/kabi_ex.o 2>&1 >/dev/null | \ 23 23 * FileCheck examples/kabi_ex.h --check-prefix=STABLE 24 + 25 + * $ nm examples/kabi_ex.o | awk '{ print $NF }' | \ 26 + * ./gendwarfksyms --stable --dump-versions \ 27 + * examples/kabi_ex.o 2>&1 >/dev/null | \ 28 + * sort | \ 29 + * FileCheck examples/kabi_ex.h --check-prefix=VERSIONS 24 30 */ 25 31 26 32 #ifndef __KABI_EX_H__ ··· 176 170 /* 177 171 * STABLE: variable structure_type ex2a { 178 172 * STABLE-NEXT: member base_type int byte_size(4) encoding(5) a data_member_location(0) , 179 - * STABLE-NEXT: member base_type [[ULONG:long unsigned int|unsigned long]] byte_size(8) encoding(7) b data_member_location(8) 173 + * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) b data_member_location(8) 180 174 * STABLE-NEXT: member base_type int byte_size(4) encoding(5) c data_member_location(16) , 181 175 * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) d data_member_location(24) 182 176 * STABLE-NEXT: } byte_size(32) ··· 233 227 234 228 /* 235 229 * STABLE: variable structure_type ex3a { 236 - * STABLE-NEXT: member base_type [[ULONG:long unsigned int|unsigned long]] byte_size(8) encoding(7) a data_member_location(0) 230 + * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) a data_member_location(0) 237 231 * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) unused data_member_location(8) 238 232 * STABLE-NEXT: } byte_size(16) 239 233 */ ··· 266 260 * STABLE-NEXT: } byte_size(16) 267 261 */ 268 262 263 + /* 264 + * Example: An ignored field added to an end of a partially opaque struct, 265 + * while keeping the byte_size attribute unchanged. 266 + */ 267 + 268 + struct ex4a { 269 + unsigned long a; 270 + KABI_IGNORE(0, unsigned long b); 271 + }; 272 + 273 + /* 274 + * This may be safe if the structure allocation is managed by the core kernel 275 + * and the layout remains unchanged except for appended new members. 276 + */ 277 + KABI_BYTE_SIZE(ex4a, 8); 278 + 279 + /* 280 + * STABLE: variable structure_type ex4a { 281 + * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) a data_member_location(0) 282 + * STABLE-NEXT: } byte_size(8) 283 + */ 284 + 285 + /* 286 + * Example: A type string override. 287 + */ 288 + 289 + struct ex5a { 290 + unsigned long a; 291 + }; 292 + 293 + /* 294 + * This may be safe if the structure is fully opaque to modules, even though 295 + * its definition has inadvertently become part of the ABI. 296 + */ 297 + KABI_TYPE_STRING( 298 + "s#ex5a", 299 + "structure_type ex5a { member pointer_type { s#ex4a } byte_size(8) p data_member_location(0) } byte_size(8)"); 300 + 301 + /* 302 + * Make sure the fully expanded type string includes ex4a. 303 + * 304 + * VERSIONS: ex5a variable structure_type ex5a { 305 + * VERSIONS-SAME: member pointer_type { 306 + * VERSIONS-SAME: structure_type ex4a { 307 + * VERSIONS-SAME: member base_type [[ULONG:long unsigned int|unsigned long]] byte_size(8) encoding(7) a data_member_location(0) 308 + * VERSIONS-SAME: } byte_size(8) 309 + * VERSIONS-SAME: } byte_size(8) p data_member_location(0) 310 + * VERSIONS-SAME: } byte_size(8) 311 + */ 312 + 313 + /* 314 + * Example: A type string definition for a non-existent type. 315 + */ 316 + 317 + struct ex5b { 318 + unsigned long a; 319 + }; 320 + 321 + /* Replace the type string for struct ex5b */ 322 + KABI_TYPE_STRING( 323 + "s#ex5b", 324 + "structure_type ex5b { member pointer_type { s#ex5c } byte_size(8) p data_member_location(0) } byte_size(8)"); 325 + 326 + /* Define a type string for a non-existent struct ex5c */ 327 + KABI_TYPE_STRING( 328 + "s#ex5c", 329 + "structure_type ex5c { member base_type int byte_size(4) encoding(5) n data_member_location(0) } byte_size(8)"); 330 + 331 + /* 332 + * Make sure the fully expanded type string includes the definition for ex5c. 333 + * 334 + * VERSIONS: ex5b variable structure_type ex5b { 335 + * VERSIONS-SAME: member pointer_type { 336 + * VERSIONS-SAME: structure_type ex5c { 337 + * VERSIONS-SAME: member base_type int byte_size(4) encoding(5) n data_member_location(0) 338 + * VERSIONS-SAME: } byte_size(8) 339 + * VERSIONS-SAME: } byte_size(8) p data_member_location(0) 340 + * VERSIONS-SAME: } byte_size(8) 341 + */ 342 + 343 + /* 344 + * Example: A type string override for a symbol. 345 + */ 346 + 347 + KABI_TYPE_STRING("ex6a", "variable s#ex5c"); 348 + 349 + /* 350 + * VERSIONS: ex6a variable structure_type ex5c { 351 + * VERSIONS-SAME: member base_type int byte_size(4) encoding(5) n data_member_location(0) 352 + * VERSIONS-SAME: } byte_size(8) 353 + */ 269 354 #endif /* __KABI_EX_H__ */
+2
scripts/gendwarfksyms/gendwarfksyms.h
··· 287 287 * kabi.c 288 288 */ 289 289 290 + bool kabi_get_byte_size(const char *fqn, unsigned long *value); 290 291 bool kabi_is_enumerator_ignored(const char *fqn, const char *field); 291 292 bool kabi_get_enumerator_value(const char *fqn, const char *field, 292 293 unsigned long *value); 293 294 bool kabi_is_declonly(const char *fqn); 295 + bool kabi_get_type_string(const char *type, const char **str); 294 296 295 297 void kabi_read_rules(int fd); 296 298 void kabi_free(void);
+99 -62
scripts/gendwarfksyms/kabi.c
··· 54 54 */ 55 55 #define KABI_RULE_TAG_ENUMERATOR_VALUE "enumerator_value" 56 56 57 + /* 58 + * Rule: byte_size 59 + * - For the fqn_field in the target field, set the byte_size 60 + * attribute to the value in the value field. 61 + */ 62 + #define KABI_RULE_TAG_BYTE_SIZE "byte_size" 63 + 64 + /* 65 + * Rule: type_string 66 + * - For the type reference in the fqn field, use the type string 67 + * in the value field. 68 + */ 69 + #define KABI_RULE_TAG_TYPE_STRING "type_string" 70 + 57 71 enum kabi_rule_type { 58 72 KABI_RULE_TYPE_UNKNOWN, 59 73 KABI_RULE_TYPE_DECLONLY, 60 74 KABI_RULE_TYPE_ENUMERATOR_IGNORE, 61 75 KABI_RULE_TYPE_ENUMERATOR_VALUE, 76 + KABI_RULE_TYPE_BYTE_SIZE, 77 + KABI_RULE_TYPE_TYPE_STRING, 62 78 }; 63 79 64 80 #define RULE_HASH_BITS 7 ··· 142 126 { 143 127 .type = KABI_RULE_TYPE_ENUMERATOR_VALUE, 144 128 .tag = KABI_RULE_TAG_ENUMERATOR_VALUE, 129 + }, 130 + { 131 + .type = KABI_RULE_TYPE_BYTE_SIZE, 132 + .tag = KABI_RULE_TAG_BYTE_SIZE, 133 + }, 134 + { 135 + .type = KABI_RULE_TYPE_TYPE_STRING, 136 + .tag = KABI_RULE_TAG_TYPE_STRING, 145 137 }, 146 138 }; 147 139 ··· 246 222 check(elf_end(elf)); 247 223 } 248 224 249 - bool kabi_is_declonly(const char *fqn) 250 - { 251 - struct rule *rule; 252 - 253 - if (!stable) 254 - return false; 255 - if (!fqn || !*fqn) 256 - return false; 257 - 258 - hash_for_each_possible(rules, rule, hash, 259 - rule_values_hash(KABI_RULE_TYPE_DECLONLY, fqn)) { 260 - if (rule->type == KABI_RULE_TYPE_DECLONLY && 261 - !strcmp(fqn, rule->target)) 262 - return true; 263 - } 264 - 265 - return false; 266 - } 267 - 268 225 static char *get_enumerator_target(const char *fqn, const char *field) 269 226 { 270 227 char *target = NULL; ··· 254 249 error("asprintf failed for '%s %s'", fqn, field); 255 250 256 251 return target; 252 + } 253 + 254 + static struct rule *find_rule(enum kabi_rule_type type, const char *target) 255 + { 256 + struct rule *rule; 257 + 258 + if (!stable) 259 + return NULL; 260 + if (!target || !*target) 261 + return NULL; 262 + 263 + hash_for_each_possible(rules, rule, hash, 264 + rule_values_hash(type, target)) { 265 + if (rule->type == type && !strcmp(target, rule->target)) 266 + return rule; 267 + } 268 + 269 + return NULL; 270 + } 271 + 272 + static struct rule *find_enumerator_rule(enum kabi_rule_type type, 273 + const char *fqn, const char *field) 274 + { 275 + struct rule *rule; 276 + char *target; 277 + 278 + if (!stable) 279 + return NULL; 280 + if (!fqn || !*fqn || !field || !*field) 281 + return NULL; 282 + 283 + target = get_enumerator_target(fqn, field); 284 + rule = find_rule(type, target); 285 + 286 + free(target); 287 + return rule; 288 + } 289 + 290 + bool kabi_is_declonly(const char *fqn) 291 + { 292 + return !!find_rule(KABI_RULE_TYPE_DECLONLY, fqn); 257 293 } 258 294 259 295 static unsigned long get_ulong_value(const char *value) ··· 313 267 314 268 bool kabi_is_enumerator_ignored(const char *fqn, const char *field) 315 269 { 316 - bool match = false; 317 - struct rule *rule; 318 - char *target; 319 - 320 - if (!stable) 321 - return false; 322 - if (!fqn || !*fqn || !field || !*field) 323 - return false; 324 - 325 - target = get_enumerator_target(fqn, field); 326 - 327 - hash_for_each_possible( 328 - rules, rule, hash, 329 - rule_values_hash(KABI_RULE_TYPE_ENUMERATOR_IGNORE, target)) { 330 - if (rule->type == KABI_RULE_TYPE_ENUMERATOR_IGNORE && 331 - !strcmp(target, rule->target)) { 332 - match = true; 333 - break; 334 - } 335 - } 336 - 337 - free(target); 338 - return match; 270 + return !!find_enumerator_rule(KABI_RULE_TYPE_ENUMERATOR_IGNORE, fqn, 271 + field); 339 272 } 340 273 341 274 bool kabi_get_enumerator_value(const char *fqn, const char *field, 342 275 unsigned long *value) 343 276 { 344 - bool match = false; 345 277 struct rule *rule; 346 - char *target; 347 278 348 - if (!stable) 349 - return false; 350 - if (!fqn || !*fqn || !field || !*field) 351 - return false; 352 - 353 - target = get_enumerator_target(fqn, field); 354 - 355 - hash_for_each_possible(rules, rule, hash, 356 - rule_values_hash(KABI_RULE_TYPE_ENUMERATOR_VALUE, 357 - target)) { 358 - if (rule->type == KABI_RULE_TYPE_ENUMERATOR_VALUE && 359 - !strcmp(target, rule->target)) { 360 - *value = get_ulong_value(rule->value); 361 - match = true; 362 - break; 363 - } 279 + rule = find_enumerator_rule(KABI_RULE_TYPE_ENUMERATOR_VALUE, fqn, 280 + field); 281 + if (rule) { 282 + *value = get_ulong_value(rule->value); 283 + return true; 364 284 } 365 285 366 - free(target); 367 - return match; 286 + return false; 287 + } 288 + 289 + bool kabi_get_byte_size(const char *fqn, unsigned long *value) 290 + { 291 + struct rule *rule; 292 + 293 + rule = find_rule(KABI_RULE_TYPE_BYTE_SIZE, fqn); 294 + if (rule) { 295 + *value = get_ulong_value(rule->value); 296 + return true; 297 + } 298 + 299 + return false; 300 + } 301 + 302 + bool kabi_get_type_string(const char *type, const char **str) 303 + { 304 + struct rule *rule; 305 + 306 + rule = find_rule(KABI_RULE_TYPE_TYPE_STRING, type); 307 + if (rule) { 308 + *str = rule->value; 309 + return true; 310 + } 311 + 312 + return false; 368 313 } 369 314 370 315 void kabi_free(void)
+126 -14
scripts/gendwarfksyms/types.c
··· 100 100 #define TYPE_HASH_BITS 12 101 101 static HASHTABLE_DEFINE(type_map, 1 << TYPE_HASH_BITS); 102 102 103 - static int type_map_get(const char *name, struct type_expansion **res) 103 + static int __type_map_get(const char *name, struct type_expansion **res) 104 104 { 105 105 struct type_expansion *e; 106 106 ··· 114 114 return -1; 115 115 } 116 116 117 - static void type_map_add(const char *name, struct type_expansion *type) 117 + static struct type_expansion *type_map_add(const char *name, 118 + struct type_expansion *type) 118 119 { 119 120 struct type_expansion *e; 120 121 121 - if (type_map_get(name, &e)) { 122 + if (__type_map_get(name, &e)) { 122 123 e = xmalloc(sizeof(struct type_expansion)); 123 124 type_expansion_init(e); 124 125 e->name = xstrdup(name); ··· 131 130 } else { 132 131 /* Use the longest available expansion */ 133 132 if (type->len <= e->len) 134 - return; 133 + return e; 135 134 136 135 type_list_free(&e->expanded); 137 136 ··· 149 148 type_list_write(&e->expanded, stderr); 150 149 checkp(fputs("\n", stderr)); 151 150 } 151 + 152 + return e; 153 + } 154 + 155 + static void type_parse(const char *name, const char *str, 156 + struct type_expansion *type); 157 + 158 + static int type_map_get(const char *name, struct type_expansion **res) 159 + { 160 + struct type_expansion type; 161 + const char *override; 162 + 163 + if (!__type_map_get(name, res)) 164 + return 0; 165 + 166 + /* 167 + * If die_map didn't contain a type, we might still have 168 + * a type_string kABI rule that defines it. 169 + */ 170 + if (stable && kabi_get_type_string(name, &override)) { 171 + type_expansion_init(&type); 172 + type_parse(name, override, &type); 173 + *res = type_map_add(name, &type); 174 + type_expansion_free(&type); 175 + return 0; 176 + } 177 + 178 + return -1; 152 179 } 153 180 154 181 static void type_map_write(FILE *file) ··· 296 267 return name; 297 268 } 298 269 299 - static void __calculate_version(struct version *version, struct list_head *list) 270 + static void __calculate_version(struct version *version, 271 + struct type_expansion *type) 300 272 { 301 273 struct type_list_entry *entry; 302 274 struct type_expansion *e; 303 275 304 276 /* Calculate a CRC over an expanded type string */ 305 - list_for_each_entry(entry, list, list) { 277 + list_for_each_entry(entry, &type->expanded, list) { 306 278 if (is_type_prefix(entry->str)) { 307 - check(type_map_get(entry->str, &e)); 279 + if (type_map_get(entry->str, &e)) 280 + error("unknown type reference to '%s' when expanding '%s'", 281 + entry->str, type->name); 308 282 309 283 /* 310 284 * It's sufficient to expand each type reference just ··· 317 285 version_add(version, entry->str); 318 286 } else { 319 287 cache_mark_expanded(&expansion_cache, e); 320 - __calculate_version(version, &e->expanded); 288 + __calculate_version(version, e); 321 289 } 322 290 } else { 323 291 version_add(version, entry->str); ··· 325 293 } 326 294 } 327 295 328 - static void calculate_version(struct version *version, struct list_head *list) 296 + static void calculate_version(struct version *version, 297 + struct type_expansion *type) 329 298 { 330 299 version_init(version); 331 - __calculate_version(version, list); 300 + __calculate_version(version, type); 332 301 cache_free(&expansion_cache); 333 302 } 334 303 ··· 405 372 cache_free(&expansion_cache); 406 373 } 407 374 375 + static void type_parse(const char *name, const char *str, 376 + struct type_expansion *type) 377 + { 378 + char *fragment; 379 + size_t start = 0; 380 + size_t end; 381 + size_t pos; 382 + 383 + if (!*str) 384 + error("empty type string override for '%s'", name); 385 + 386 + type_expansion_init(type); 387 + 388 + for (pos = 0; str[pos]; ++pos) { 389 + bool empty; 390 + char marker = ' '; 391 + 392 + if (!is_type_prefix(&str[pos])) 393 + continue; 394 + 395 + end = pos + 2; 396 + 397 + /* 398 + * Find the end of the type reference. If the type name contains 399 + * spaces, it must be in single quotes. 400 + */ 401 + if (str[end] == '\'') { 402 + marker = '\''; 403 + ++end; 404 + } 405 + while (str[end] && str[end] != marker) 406 + ++end; 407 + 408 + /* Check that we have a non-empty type name */ 409 + if (marker == '\'') { 410 + if (str[end] != marker) 411 + error("incomplete %c# type reference for '%s' (string : '%s')", 412 + str[pos], name, str); 413 + empty = end == pos + 3; 414 + ++end; 415 + } else { 416 + empty = end == pos + 2; 417 + } 418 + if (empty) 419 + error("empty %c# type name for '%s' (string: '%s')", 420 + str[pos], name, str); 421 + 422 + /* Append the part of the string before the type reference */ 423 + if (pos > start) { 424 + fragment = xstrndup(&str[start], pos - start); 425 + type_expansion_append(type, fragment, fragment); 426 + } 427 + 428 + /* 429 + * Append the type reference -- note that if the reference 430 + * is invalid, i.e. points to a non-existent type, we will 431 + * print out an error when calculating versions. 432 + */ 433 + fragment = xstrndup(&str[pos], end - pos); 434 + type_expansion_append(type, fragment, fragment); 435 + 436 + start = end; 437 + pos = end - 1; 438 + } 439 + 440 + /* Append the rest of the type string, if there's any left */ 441 + if (str[start]) 442 + type_expansion_append(type, &str[start], NULL); 443 + } 444 + 408 445 static void expand_type(struct die *cache, void *arg) 409 446 { 410 447 struct type_expansion type; 448 + const char *override; 411 449 char *name; 412 450 413 451 if (cache->mapped) ··· 503 399 return; 504 400 505 401 debug("%s", name); 506 - type_expand(cache, &type, true); 507 - type_map_add(name, &type); 508 402 403 + if (stable && kabi_get_type_string(name, &override)) 404 + type_parse(name, override, &type); 405 + else 406 + type_expand(cache, &type, true); 407 + 408 + type_map_add(name, &type); 509 409 type_expansion_free(&type); 510 410 free(name); 511 411 } ··· 518 410 { 519 411 struct type_expansion type; 520 412 struct version version; 413 + const char *override; 521 414 struct die *cache; 522 415 523 416 /* ··· 532 423 if (__die_map_get(sym->die_addr, DIE_SYMBOL, &cache)) 533 424 return; /* We'll warn about missing CRCs later. */ 534 425 535 - type_expand(cache, &type, false); 426 + if (stable && kabi_get_type_string(sym->name, &override)) 427 + type_parse(sym->name, override, &type); 428 + else 429 + type_expand(cache, &type, false); 536 430 537 431 /* If the symbol already has a version, don't calculate it again. */ 538 432 if (sym->state != SYMBOL_PROCESSED) { 539 - calculate_version(&version, &type.expanded); 433 + calculate_version(&version, &type); 540 434 symbol_set_crc(sym, version.crc); 541 435 debug("%s = %lx", sym->name, version.crc); 542 436
+20 -7
scripts/genksyms/genksyms.c
··· 181 181 strcmp(defn->string, "{") == 0); 182 182 } 183 183 184 - static struct symbol *__add_symbol(const char *name, enum symbol_type type, 185 - struct string_list *defn, int is_extern, 186 - int is_reference) 184 + static struct string_list *process_enum(const char *name, enum symbol_type type, 185 + struct string_list *defn) 187 186 { 188 - unsigned long h; 189 - struct symbol *sym; 190 - enum symbol_status status = STATUS_UNCHANGED; 191 187 /* The parser adds symbols in the order their declaration completes, 192 188 * so it is safe to store the value of the previous enum constant in 193 189 * a static variable. ··· 212 216 defn = mk_node(buf); 213 217 } 214 218 } 215 - } else if (type == SYM_ENUM) { 219 + } else { 216 220 free_list(last_enum_expr, NULL); 217 221 last_enum_expr = NULL; 218 222 enum_counter = 0; 219 223 if (!name) 220 224 /* Anonymous enum definition, nothing more to do */ 225 + return NULL; 226 + } 227 + 228 + return defn; 229 + } 230 + 231 + static struct symbol *__add_symbol(const char *name, enum symbol_type type, 232 + struct string_list *defn, int is_extern, 233 + int is_reference) 234 + { 235 + unsigned long h; 236 + struct symbol *sym; 237 + enum symbol_status status = STATUS_UNCHANGED; 238 + 239 + if ((type == SYM_ENUM_CONST || type == SYM_ENUM) && !is_reference) { 240 + defn = process_enum(name, type, defn); 241 + if (defn == NULL) 221 242 return NULL; 222 243 } 223 244
+11
scripts/kconfig/expr.h
··· 205 205 for (st = sym->prop; st; st = st->next) \ 206 206 if (st->text) 207 207 208 + enum menu_type { 209 + M_CHOICE, // "choice" 210 + M_COMMENT, // "comment" 211 + M_IF, // "if" 212 + M_MENU, // "mainmenu", "menu", "menuconfig" 213 + M_NORMAL, // others, i.e., "config" 214 + }; 215 + 208 216 /* 209 217 * Represents a node in the menu tree, as seen in e.g. menuconfig (though used 210 218 * for all front ends). Each symbol, menu, etc. defined in the Kconfig files 211 219 * gets a node. A symbol defined in multiple locations gets one node at each 212 220 * location. 213 221 * 222 + * @type: type of the menu entry 214 223 * @choice_members: list of choice members with priority. 215 224 */ 216 225 struct menu { 226 + enum menu_type type; 227 + 217 228 /* The next menu node at the same level */ 218 229 struct menu *next; 219 230
+1 -1
scripts/kconfig/lkc.h
··· 81 81 void menu_warn(const struct menu *menu, const char *fmt, ...); 82 82 struct menu *menu_add_menu(void); 83 83 void menu_end_menu(void); 84 - void menu_add_entry(struct symbol *sym); 84 + void menu_add_entry(struct symbol *sym, enum menu_type type); 85 85 void menu_add_dep(struct expr *dep); 86 86 void menu_add_visibility(struct expr *dep); 87 87 struct property *menu_add_prompt(enum prop_type type, const char *prompt,
+3 -2
scripts/kconfig/menu.c
··· 15 15 16 16 static const char nohelp_text[] = "There is no help available for this option."; 17 17 18 - struct menu rootmenu; 18 + struct menu rootmenu = { .type = M_MENU }; 19 19 static struct menu **last_entry_ptr; 20 20 21 21 /** ··· 65 65 last_entry_ptr = &rootmenu.list; 66 66 } 67 67 68 - void menu_add_entry(struct symbol *sym) 68 + void menu_add_entry(struct symbol *sym, enum menu_type type) 69 69 { 70 70 struct menu *menu; 71 71 72 72 menu = xmalloc(sizeof(*menu)); 73 73 memset(menu, 0, sizeof(*menu)); 74 + menu->type = type; 74 75 menu->sym = sym; 75 76 menu->parent = current_menu; 76 77 menu->filename = cur_filename;
+6 -6
scripts/kconfig/parser.y
··· 139 139 140 140 config_entry_start: T_CONFIG nonconst_symbol T_EOL 141 141 { 142 - menu_add_entry($2); 142 + menu_add_entry($2, M_NORMAL); 143 143 printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name); 144 144 }; 145 145 ··· 173 173 174 174 menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL 175 175 { 176 - menu_add_entry($2); 176 + menu_add_entry($2, M_MENU); 177 177 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name); 178 178 }; 179 179 ··· 246 246 { 247 247 struct symbol *sym = sym_lookup(NULL, 0); 248 248 249 - menu_add_entry(sym); 249 + menu_add_entry(sym, M_CHOICE); 250 250 menu_set_type(S_BOOLEAN); 251 251 INIT_LIST_HEAD(&current_entry->choice_members); 252 252 ··· 315 315 if_entry: T_IF expr T_EOL 316 316 { 317 317 printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno); 318 - menu_add_entry(NULL); 318 + menu_add_entry(NULL, M_IF); 319 319 menu_add_dep($2); 320 320 $$ = menu_add_menu(); 321 321 }; ··· 338 338 339 339 menu: T_MENU T_WORD_QUOTE T_EOL 340 340 { 341 - menu_add_entry(NULL); 341 + menu_add_entry(NULL, M_MENU); 342 342 menu_add_prompt(P_MENU, $2, NULL); 343 343 printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno); 344 344 }; ··· 376 376 377 377 comment: T_COMMENT T_WORD_QUOTE T_EOL 378 378 { 379 - menu_add_entry(NULL); 379 + menu_add_entry(NULL, M_COMMENT); 380 380 menu_add_prompt(P_COMMENT, $2, NULL); 381 381 printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno); 382 382 };
+57 -9
scripts/misc-check
··· 3 3 4 4 set -e 5 5 6 - # Detect files that are tracked but ignored by git. This is checked only when 7 - # ${KBUILD_EXTRA_WARN} contains 1, git is installed, and the source tree is 8 - # tracked by git. 6 + # Detect files that are tracked but ignored by git. 9 7 check_tracked_ignored_files () { 10 - case "${KBUILD_EXTRA_WARN}" in 11 - *1*) ;; 12 - *) return;; 13 - esac 14 - 15 - git -C ${srctree:-.} ls-files -i -c --exclude-per-directory=.gitignore 2>/dev/null | 8 + git -C "${srctree:-.}" ls-files -i -c --exclude-per-directory=.gitignore 2>/dev/null | 16 9 sed 's/$/: warning: ignored by one of the .gitignore files/' >&2 17 10 } 18 11 12 + # Check for missing #include <linux/export.h> 13 + # 14 + # The rule for including <linux/export.h> is very simple: 15 + # Include <linux/export.h> only when you use EXPORT_SYMBOL(). That's it. 16 + # 17 + # However, some headers include <linux/export.h> even though they are completely 18 + # unrelated to EXPORT_SYMBOL(). 19 + # 20 + # One example is include/linux/module.h. Please note <linux/module.h> and 21 + # <linux/export.h> are orthogonal. <linux/module.h> should be included by files 22 + # that can be compiled as modules. In other words, <linux/module.h> should be 23 + # included by EXPORT_SYMBOL consumers. In contrast, <linux/export.h> should be 24 + # included from EXPORT_SYMBOL providers, which may or may not be modular. 25 + # Hence, include/linux/module.h should *not* include <linux/export.h>. 26 + # 27 + # Another example is include/linux/linkage.h, which is completely unrelated to 28 + # EXPORT_SYMBOL(). Worse, it is included by most C files, which means, most C 29 + # files end up including <linux/export.h>, even though only some of them 30 + # actually export symbols. Hence, include/linux/linkage.h should *not* include 31 + # <linux/export.h>. 32 + # 33 + # Before fixing such headers, we must ensure that C files using EXPORT_SYMBOL() 34 + # include <linux/export.h> directly, since many C files currently rely on 35 + # <linux/export.h> being included indirectly (likely, via <linux/linkage> etc.). 36 + # 37 + # Therefore, this check. 38 + # 39 + # The problem is simple - the warned files use EXPORT_SYMBOL(), but do not 40 + # include <linux/export.h>. Please add #include <linux/export.h> to them. 41 + # 42 + # If the included headers are sorted alphabetically, please insert 43 + # <linux/export.h> in the appropriate position to maintain the sort order. 44 + # For this reason, this script only checks missing <linux/export.h>, but 45 + # does not automatically fix it. 46 + check_missing_include_linux_export_h () { 47 + 48 + git -C "${srctree:-.}" grep --files-with-matches -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_GPL_FOR_MODULES)\(.*\)' \ 49 + -- '*.[ch]' :^tools/ :^include/linux/export.h | 50 + xargs -r git -C "${srctree:-.}" grep --files-without-match '#include[[:space:]]*<linux/export\.h>' | 51 + xargs -r printf "%s: warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing\n" >&2 52 + } 53 + 54 + # If you do not use EXPORT_SYMBOL(), please do not include <linux/export.h>. 55 + # Currently, this is checked for *.c files, but not for *.h files, because some 56 + # *.c files rely on <linux/export.h> being included indirectly. 57 + check_unnecessary_include_linux_export_h () { 58 + 59 + git -C "${srctree:-.}" grep --files-with-matches '#include[[:space:]]*<linux/export\.h>' \ 60 + -- '*.[c]' :^tools/ | 61 + xargs -r git -C "${srctree:-.}" grep --files-without-match -E 'EXPORT_SYMBOL((_NS)?(_GPL)?|_GPL_FOR_MODULES)\(.*\)' | 62 + xargs -r printf "%s: warning: EXPORT_SYMBOL() is not used, but #include <linux/export.h> is present\n" >&2 63 + } 64 + 19 65 check_tracked_ignored_files 66 + check_missing_include_linux_export_h 67 + check_unnecessary_include_linux_export_h
+51 -5
scripts/mod/modpost.c
··· 28 28 #include "modpost.h" 29 29 #include "../../include/linux/license.h" 30 30 31 + #define MODULE_NS_PREFIX "module:" 32 + 31 33 static bool module_enabled; 32 34 /* Are we using CONFIG_MODVERSIONS? */ 33 35 static bool modversions; ··· 1597 1595 license = get_next_modinfo(&info, "license", license); 1598 1596 } 1599 1597 1600 - namespace = get_modinfo(&info, "import_ns"); 1601 - while (namespace) { 1598 + for (namespace = get_modinfo(&info, "import_ns"); 1599 + namespace; 1600 + namespace = get_next_modinfo(&info, "import_ns", namespace)) { 1601 + if (strstarts(namespace, MODULE_NS_PREFIX)) 1602 + error("%s: explicitly importing namespace \"%s\" is not allowed.\n", 1603 + mod->name, namespace); 1604 + 1602 1605 add_namespace(&mod->imported_namespaces, namespace); 1603 - namespace = get_next_modinfo(&info, "import_ns", 1604 - namespace); 1605 1606 } 1606 1607 1607 1608 if (!get_modinfo(&info, "description")) ··· 1689 1684 buf->pos += len; 1690 1685 } 1691 1686 1687 + /** 1688 + * verify_module_namespace() - does @modname have access to this symbol's @namespace 1689 + * @namespace: export symbol namespace 1690 + * @modname: module name 1691 + * 1692 + * If @namespace is prefixed with "module:" to indicate it is a module namespace 1693 + * then test if @modname matches any of the comma separated patterns. 1694 + * 1695 + * The patterns only support tail-glob. 1696 + */ 1697 + static bool verify_module_namespace(const char *namespace, const char *modname) 1698 + { 1699 + size_t len, modlen = strlen(modname); 1700 + const char *prefix = "module:"; 1701 + const char *sep; 1702 + bool glob; 1703 + 1704 + if (!strstarts(namespace, prefix)) 1705 + return false; 1706 + 1707 + for (namespace += strlen(prefix); *namespace; namespace = sep) { 1708 + sep = strchrnul(namespace, ','); 1709 + len = sep - namespace; 1710 + 1711 + glob = false; 1712 + if (sep[-1] == '*') { 1713 + len--; 1714 + glob = true; 1715 + } 1716 + 1717 + if (*sep) 1718 + sep++; 1719 + 1720 + if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen)) 1721 + return true; 1722 + } 1723 + 1724 + return false; 1725 + } 1726 + 1692 1727 static void check_exports(struct module *mod) 1693 1728 { 1694 1729 struct symbol *s, *exp; ··· 1756 1711 1757 1712 basename = get_basename(mod->name); 1758 1713 1759 - if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { 1714 + if (!verify_module_namespace(exp->namespace, basename) && 1715 + !contains_namespace(&mod->imported_namespaces, exp->namespace)) { 1760 1716 modpost_log(!allow_missing_ns_imports, 1761 1717 "module %s uses symbol %s from namespace %s, but does not import it.\n", 1762 1718 basename, exp->name, exp->namespace);
+1 -1
scripts/tags.sh
··· 344 344 345 345 "tags") 346 346 rm -f tags 347 - xtags ctags 347 + xtags ${CTAGS:-ctags} 348 348 remove_structs=y 349 349 ;; 350 350