mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
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
...
This commit is contained in:
@@ -6,18 +6,8 @@ The following document describes how to use Symbol Namespaces to structure the
|
||||
export surface of in-kernel symbols exported through the family of
|
||||
EXPORT_SYMBOL() macros.
|
||||
|
||||
.. Table of Contents
|
||||
|
||||
=== 1 Introduction
|
||||
=== 2 How to define Symbol Namespaces
|
||||
--- 2.1 Using the EXPORT_SYMBOL macros
|
||||
--- 2.2 Using the DEFAULT_SYMBOL_NAMESPACE define
|
||||
=== 3 How to use Symbols exported in Namespaces
|
||||
=== 4 Loading Modules that use namespaced Symbols
|
||||
=== 5 Automatically creating MODULE_IMPORT_NS statements
|
||||
|
||||
1. Introduction
|
||||
===============
|
||||
Introduction
|
||||
============
|
||||
|
||||
Symbol Namespaces have been introduced as a means to structure the export
|
||||
surface of the in-kernel API. It allows subsystem maintainers to partition
|
||||
@@ -28,15 +18,18 @@ kernel. As of today, modules that make use of symbols exported into namespaces,
|
||||
are required to import the namespace. Otherwise the kernel will, depending on
|
||||
its configuration, reject loading the module or warn about a missing import.
|
||||
|
||||
2. How to define Symbol Namespaces
|
||||
==================================
|
||||
Additionally, it is possible to put symbols into a module namespace, strictly
|
||||
limiting which modules are allowed to use these symbols.
|
||||
|
||||
How to define Symbol Namespaces
|
||||
===============================
|
||||
|
||||
Symbols can be exported into namespace using different methods. All of them are
|
||||
changing the way EXPORT_SYMBOL and friends are instrumented to create ksymtab
|
||||
entries.
|
||||
|
||||
2.1 Using the EXPORT_SYMBOL macros
|
||||
==================================
|
||||
Using the EXPORT_SYMBOL macros
|
||||
------------------------------
|
||||
|
||||
In addition to the macros EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(), that allow
|
||||
exporting of kernel symbols to the kernel symbol table, variants of these are
|
||||
@@ -54,8 +47,8 @@ refer to ``NULL``. There is no default namespace if none is defined. ``modpost``
|
||||
and kernel/module/main.c make use the namespace at build time or module load
|
||||
time, respectively.
|
||||
|
||||
2.2 Using the DEFAULT_SYMBOL_NAMESPACE define
|
||||
=============================================
|
||||
Using the DEFAULT_SYMBOL_NAMESPACE define
|
||||
-----------------------------------------
|
||||
|
||||
Defining namespaces for all symbols of a subsystem can be very verbose and may
|
||||
become hard to maintain. Therefore a default define (DEFAULT_SYMBOL_NAMESPACE)
|
||||
@@ -83,8 +76,24 @@ unit as preprocessor statement. The above example would then read::
|
||||
within the corresponding compilation unit before the #include for
|
||||
<linux/export.h>. Typically it's placed before the first #include statement.
|
||||
|
||||
3. How to use Symbols exported in Namespaces
|
||||
============================================
|
||||
Using the EXPORT_SYMBOL_GPL_FOR_MODULES() macro
|
||||
-----------------------------------------------
|
||||
|
||||
Symbols exported using this macro are put into a module namespace. This
|
||||
namespace cannot be imported.
|
||||
|
||||
The macro takes a comma separated list of module names, allowing only those
|
||||
modules to access this symbol. Simple tail-globs are supported.
|
||||
|
||||
For example::
|
||||
|
||||
EXPORT_SYMBOL_GPL_FOR_MODULES(preempt_notifier_inc, "kvm,kvm-*")
|
||||
|
||||
will limit usage of this symbol to modules whoes name matches the given
|
||||
patterns.
|
||||
|
||||
How to use Symbols exported in Namespaces
|
||||
=========================================
|
||||
|
||||
In order to use symbols that are exported into namespaces, kernel modules need
|
||||
to explicitly import these namespaces. Otherwise the kernel might reject to
|
||||
@@ -106,11 +115,10 @@ inspected with modinfo::
|
||||
|
||||
|
||||
It is advisable to add the MODULE_IMPORT_NS() statement close to other module
|
||||
metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE(). Refer to section
|
||||
5. for a way to create missing import statements automatically.
|
||||
metadata definitions like MODULE_AUTHOR() or MODULE_LICENSE().
|
||||
|
||||
4. Loading Modules that use namespaced Symbols
|
||||
==============================================
|
||||
Loading Modules that use namespaced Symbols
|
||||
===========================================
|
||||
|
||||
At module loading time (e.g. ``insmod``), the kernel will check each symbol
|
||||
referenced from the module for its availability and whether the namespace it
|
||||
@@ -121,8 +129,8 @@ allow loading of modules that don't satisfy this precondition, a configuration
|
||||
option is available: Setting MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y will
|
||||
enable loading regardless, but will emit a warning.
|
||||
|
||||
5. Automatically creating MODULE_IMPORT_NS statements
|
||||
=====================================================
|
||||
Automatically creating MODULE_IMPORT_NS statements
|
||||
==================================================
|
||||
|
||||
Missing namespaces imports can easily be detected at build time. In fact,
|
||||
modpost will emit a warning if a module uses a symbol from a namespace
|
||||
@@ -154,3 +162,6 @@ in-tree modules::
|
||||
You can also run nsdeps for external module builds. A typical usage is::
|
||||
|
||||
$ make -C <path_to_kernel_src> M=$PWD nsdeps
|
||||
|
||||
Note: it will happily generate an import statement for the module namespace;
|
||||
which will not work and generates build and runtime failures.
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
DWARF module versioning
|
||||
=======================
|
||||
|
||||
1. Introduction
|
||||
===============
|
||||
Introduction
|
||||
============
|
||||
|
||||
When CONFIG_MODVERSIONS is enabled, symbol versions for modules
|
||||
are typically calculated from preprocessed source code using the
|
||||
@@ -14,8 +14,8 @@ selected, **gendwarfksyms** is used instead to calculate symbol versions
|
||||
from the DWARF debugging information, which contains the necessary
|
||||
details about the final module ABI.
|
||||
|
||||
1.1. Usage
|
||||
==========
|
||||
Usage
|
||||
-----
|
||||
|
||||
gendwarfksyms accepts a list of object files on the command line, and a
|
||||
list of symbol names (one per line) in standard input::
|
||||
@@ -33,8 +33,8 @@ list of symbol names (one per line) in standard input::
|
||||
-h, --help Print this message
|
||||
|
||||
|
||||
2. Type information availability
|
||||
================================
|
||||
Type information availability
|
||||
=============================
|
||||
|
||||
While symbols are typically exported in the same translation unit (TU)
|
||||
where they're defined, it's also perfectly fine for a TU to export
|
||||
@@ -56,8 +56,8 @@ type for calculating symbol versions even if the symbol is defined
|
||||
elsewhere. The name of the symbol pointer is expected to start with
|
||||
`__gendwarfksyms_ptr_`, followed by the name of the exported symbol.
|
||||
|
||||
3. Symtypes output format
|
||||
=========================
|
||||
Symtypes output format
|
||||
======================
|
||||
|
||||
Similarly to genksyms, gendwarfksyms supports writing a symtypes
|
||||
file for each processed object that contain types for exported
|
||||
@@ -85,8 +85,8 @@ produces C-style type strings, gendwarfksyms uses the same simple parsed
|
||||
DWARF format produced by **--dump-dies**, but with type references
|
||||
instead of fully expanded strings.
|
||||
|
||||
4. Maintaining a stable kABI
|
||||
============================
|
||||
Maintaining a stable kABI
|
||||
=========================
|
||||
|
||||
Distribution maintainers often need the ability to make ABI compatible
|
||||
changes to kernel data structures due to LTS updates or backports. Using
|
||||
@@ -104,8 +104,8 @@ for source code annotation. Note that as these features are only used to
|
||||
transform the inputs for symbol versioning, the user is responsible for
|
||||
ensuring that their changes actually won't break the ABI.
|
||||
|
||||
4.1. kABI rules
|
||||
===============
|
||||
kABI rules
|
||||
----------
|
||||
|
||||
kABI rules allow distributions to fine-tune certain parts
|
||||
of gendwarfksyms output and thus control how symbol
|
||||
@@ -125,22 +125,25 @@ the rules. The fields are as follows:
|
||||
qualified name of the DWARF Debugging Information Entry (DIE).
|
||||
- `value`: Provides rule-specific data.
|
||||
|
||||
The following helper macro, for example, can be used to specify rules
|
||||
The following helper macros, for example, can be used to specify rules
|
||||
in the source code::
|
||||
|
||||
#define __KABI_RULE(hint, target, value) \
|
||||
static const char __PASTE(__gendwarfksyms_rule_, \
|
||||
#define ___KABI_RULE(hint, target, value) \
|
||||
static const char __PASTE(__gendwarfksyms_rule_, \
|
||||
__COUNTER__)[] __used __aligned(1) \
|
||||
__section(".discard.gendwarfksyms.kabi_rules") = \
|
||||
"1\0" #hint "\0" #target "\0" #value
|
||||
"1\0" #hint "\0" target "\0" value
|
||||
|
||||
#define __KABI_RULE(hint, target, value) \
|
||||
___KABI_RULE(hint, #target, #value)
|
||||
|
||||
|
||||
Currently, only the rules discussed in this section are supported, but
|
||||
the format is extensible enough to allow further rules to be added as
|
||||
need arises.
|
||||
|
||||
4.1.1. Managing definition visibility
|
||||
=====================================
|
||||
Managing definition visibility
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A declaration can change into a full definition when additional includes
|
||||
are pulled into the translation unit. This changes the versions of any
|
||||
@@ -168,8 +171,8 @@ Example usage::
|
||||
|
||||
KABI_DECLONLY(s);
|
||||
|
||||
4.1.2. Adding enumerators
|
||||
=========================
|
||||
Adding enumerators
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
For enums, all enumerators and their values are included in calculating
|
||||
symbol versions, which becomes a problem if we later need to add more
|
||||
@@ -223,8 +226,89 @@ Example usage::
|
||||
KABI_ENUMERATOR_IGNORE(e, C);
|
||||
KABI_ENUMERATOR_VALUE(e, LAST, 2);
|
||||
|
||||
4.3. Adding structure members
|
||||
=============================
|
||||
Managing structure size changes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A data structure can be partially opaque to modules if its allocation is
|
||||
handled by the core kernel, and modules only need to access some of its
|
||||
members. In this situation, it's possible to append new members to the
|
||||
structure without breaking the ABI, as long as the layout for the original
|
||||
members remains unchanged.
|
||||
|
||||
To append new members, we can hide them from symbol versioning as
|
||||
described in section :ref:`Hiding members <hiding_members>`, but we can't
|
||||
hide the increase in structure size. The `byte_size` rule allows us to
|
||||
override the structure size used for symbol versioning.
|
||||
|
||||
The rule fields are expected to be as follows:
|
||||
|
||||
- `type`: "byte_size"
|
||||
- `target`: The fully qualified name of the target data structure
|
||||
(as shown in **--dump-dies** output).
|
||||
- `value`: A positive decimal number indicating the structure size
|
||||
in bytes.
|
||||
|
||||
Using the `__KABI_RULE` macro, this rule can be defined as::
|
||||
|
||||
#define KABI_BYTE_SIZE(fqn, value) \
|
||||
__KABI_RULE(byte_size, fqn, value)
|
||||
|
||||
Example usage::
|
||||
|
||||
struct s {
|
||||
/* Unchanged original members */
|
||||
unsigned long a;
|
||||
void *p;
|
||||
|
||||
/* Appended new members */
|
||||
KABI_IGNORE(0, unsigned long n);
|
||||
};
|
||||
|
||||
KABI_BYTE_SIZE(s, 16);
|
||||
|
||||
Overriding type strings
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
In rare situations where distributions must make significant changes to
|
||||
otherwise opaque data structures that have inadvertently been included
|
||||
in the published ABI, keeping symbol versions stable using the more
|
||||
targeted kABI rules can become tedious. The `type_string` rule allows us
|
||||
to override the full type string for a type or a symbol, and even add
|
||||
types for versioning that no longer exist in the kernel.
|
||||
|
||||
The rule fields are expected to be as follows:
|
||||
|
||||
- `type`: "type_string"
|
||||
- `target`: The fully qualified name of the target data structure
|
||||
(as shown in **--dump-dies** output) or symbol.
|
||||
- `value`: A valid type string (as shown in **--symtypes**) output)
|
||||
to use instead of the real type.
|
||||
|
||||
Using the `__KABI_RULE` macro, this rule can be defined as::
|
||||
|
||||
#define KABI_TYPE_STRING(type, str) \
|
||||
___KABI_RULE("type_string", type, str)
|
||||
|
||||
Example usage::
|
||||
|
||||
/* Override type for a structure */
|
||||
KABI_TYPE_STRING("s#s",
|
||||
"structure_type s { "
|
||||
"member base_type int byte_size(4) "
|
||||
"encoding(5) n "
|
||||
"data_member_location(0) "
|
||||
"} byte_size(8)");
|
||||
|
||||
/* Override type for a symbol */
|
||||
KABI_TYPE_STRING("my_symbol", "variable s#s");
|
||||
|
||||
The `type_string` rule should be used only as a last resort if maintaining
|
||||
a stable symbol versions cannot be reasonably achieved using other
|
||||
means. Overriding a type string increases the risk of actual ABI breakages
|
||||
going unnoticed as it hides all changes to the type.
|
||||
|
||||
Adding structure members
|
||||
------------------------
|
||||
|
||||
Perhaps the most common ABI compatible change is adding a member to a
|
||||
kernel data structure. When changes to a structure are anticipated,
|
||||
@@ -237,8 +321,8 @@ natural method. This section describes gendwarfksyms support for using
|
||||
reserved space in data structures and hiding members that don't change
|
||||
the ABI when calculating symbol versions.
|
||||
|
||||
4.3.1. Reserving space and replacing members
|
||||
============================================
|
||||
Reserving space and replacing members
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Space is typically reserved for later use by appending integer types, or
|
||||
arrays, to the end of the data structure, but any type can be used. Each
|
||||
@@ -276,8 +360,10 @@ The examples include `KABI_(RESERVE|USE|REPLACE)*` macros that help
|
||||
simplify the process and also ensure the replacement member is correctly
|
||||
aligned and its size won't exceed the reserved space.
|
||||
|
||||
4.3.2. Hiding members
|
||||
=====================
|
||||
.. _hiding_members:
|
||||
|
||||
Hiding members
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Predicting which structures will require changes during the support
|
||||
timeframe isn't always possible, in which case one might have to resort
|
||||
@@ -305,4 +391,5 @@ member to a union where one of the fields has a name starting with
|
||||
unsigned long b;
|
||||
};
|
||||
|
||||
With **--stable**, both versions produce the same symbol version.
|
||||
With **--stable**, both versions produce the same symbol version. The
|
||||
examples include a `KABI_IGNORE` macro to simplify the code.
|
||||
|
||||
@@ -291,6 +291,10 @@ Example::
|
||||
# arch/x86/kernel/Makefile
|
||||
extra-y += vmlinux.lds
|
||||
|
||||
extra-y is now deprecated because this is equivalent to:
|
||||
|
||||
always-$(KBUILD_BUILTIN) += vmlinux.lds
|
||||
|
||||
$(extra-y) should only contain targets needed for vmlinux.
|
||||
|
||||
Kbuild skips extra-y when vmlinux is apparently not a final goal.
|
||||
|
||||
@@ -10,8 +10,8 @@ Questo documento descrive come usare lo spazio dei nomi dei simboli
|
||||
per strutturare quello che viene esportato internamente al kernel
|
||||
grazie alle macro della famiglia EXPORT_SYMBOL().
|
||||
|
||||
1. Introduzione
|
||||
===============
|
||||
Introduzione
|
||||
============
|
||||
|
||||
Lo spazio dei nomi dei simboli è stato introdotto come mezzo per strutturare
|
||||
l'API esposta internamente al kernel. Permette ai manutentori di un
|
||||
@@ -24,15 +24,15 @@ devono prima importare detto spazio. Altrimenti il kernel, a seconda
|
||||
della configurazione, potrebbe rifiutare di caricare il modulo o
|
||||
avvisare l'utente di un'importazione mancante.
|
||||
|
||||
2. Come definire uno spazio dei nomi dei simboli
|
||||
================================================
|
||||
Come definire uno spazio dei nomi dei simboli
|
||||
=============================================
|
||||
|
||||
I simboli possono essere esportati in spazi dei nomi usando diversi
|
||||
meccanismi. Tutti questi meccanismi cambiano il modo in cui
|
||||
EXPORT_SYMBOL e simili vengono guidati verso la creazione di voci in ksymtab.
|
||||
|
||||
2.1 Usare le macro EXPORT_SYMBOL
|
||||
================================
|
||||
Usare le macro EXPORT_SYMBOL
|
||||
----------------------------
|
||||
|
||||
In aggiunta alle macro EXPORT_SYMBOL() e EXPORT_SYMBOL_GPL(), che permettono
|
||||
di esportare simboli del kernel nella rispettiva tabella, ci sono
|
||||
@@ -53,8 +53,8 @@ di base. Il programma ``modpost`` e il codice in kernel/module/main.c usano lo
|
||||
spazio dei nomi, rispettivamente, durante la compilazione e durante il
|
||||
caricamento di un modulo.
|
||||
|
||||
2.2 Usare il simbolo di preprocessore DEFAULT_SYMBOL_NAMESPACE
|
||||
==============================================================
|
||||
Usare il simbolo di preprocessore DEFAULT_SYMBOL_NAMESPACE
|
||||
----------------------------------------------------------
|
||||
|
||||
Definire lo spazio dei nomi per tutti i simboli di un sottosistema può essere
|
||||
logorante e di difficile manutenzione. Perciò è stato fornito un simbolo
|
||||
@@ -83,8 +83,8 @@ direttamente nei file da compilare. L'esempio precedente diventerebbe::
|
||||
|
||||
Questo va messo prima di un qualsiasi uso di EXPORT_SYMBOL.
|
||||
|
||||
3. Come usare i simboli esportati attraverso uno spazio dei nomi
|
||||
================================================================
|
||||
Come usare i simboli esportati attraverso uno spazio dei nomi
|
||||
=============================================================
|
||||
|
||||
Per usare i simboli esportati da uno spazio dei nomi, i moduli del
|
||||
kernel devono esplicitamente importare il relativo spazio dei nomi; altrimenti
|
||||
@@ -108,12 +108,10 @@ modinfo::
|
||||
|
||||
|
||||
Si consiglia di posizionare la dichiarazione MODULE_IMPORT_NS() vicino
|
||||
ai metadati del modulo come MODULE_AUTHOR() o MODULE_LICENSE(). Fate
|
||||
riferimento alla sezione 5. per creare automaticamente le importazioni
|
||||
mancanti.
|
||||
ai metadati del modulo come MODULE_AUTHOR() o MODULE_LICENSE().
|
||||
|
||||
4. Caricare moduli che usano simboli provenienti da spazi dei nomi
|
||||
==================================================================
|
||||
Caricare moduli che usano simboli provenienti da spazi dei nomi
|
||||
===============================================================
|
||||
|
||||
Quando un modulo viene caricato (per esempio usando ``insmod``), il kernel
|
||||
verificherà la disponibilità di ogni simbolo usato e se lo spazio dei nomi
|
||||
@@ -125,8 +123,8 @@ un'opzione di configurazione: impostare
|
||||
MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y caricherà i moduli comunque ma
|
||||
emetterà un avviso.
|
||||
|
||||
5. Creare automaticamente la dichiarazione MODULE_IMPORT_NS
|
||||
===========================================================
|
||||
Creare automaticamente la dichiarazione MODULE_IMPORT_NS
|
||||
========================================================
|
||||
|
||||
La mancanza di un'importazione può essere individuata facilmente al momento
|
||||
della compilazione. Infatti, modpost emetterà un avviso se il modulo usa
|
||||
|
||||
@@ -14,18 +14,8 @@
|
||||
|
||||
本文档描述了如何使用符号命名空间来构造通过EXPORT_SYMBOL()系列宏导出的内核内符号的导出面。
|
||||
|
||||
.. 目录
|
||||
|
||||
=== 1 简介
|
||||
=== 2 如何定义符号命名空间
|
||||
--- 2.1 使用EXPORT_SYMBOL宏
|
||||
--- 2.2 使用DEFAULT_SYMBOL_NAMESPACE定义
|
||||
=== 3 如何使用命名空间中导出的符号
|
||||
=== 4 加载使用命名空间符号的模块
|
||||
=== 5 自动创建MODULE_IMPORT_NS声明
|
||||
|
||||
1. 简介
|
||||
=======
|
||||
简介
|
||||
====
|
||||
|
||||
符号命名空间已经被引入,作为构造内核内API的导出面的一种手段。它允许子系统维护者将
|
||||
他们导出的符号划分进独立的命名空间。这对于文档的编写非常有用(想想SUBSYSTEM_DEBUG
|
||||
@@ -33,14 +23,14 @@
|
||||
的模块必须导入命名空间。否则,内核将根据其配置,拒绝加载该模块或警告说缺少
|
||||
导入。
|
||||
|
||||
2. 如何定义符号命名空间
|
||||
=======================
|
||||
如何定义符号命名空间
|
||||
====================
|
||||
|
||||
符号可以用不同的方法导出到命名空间。所有这些都在改变 EXPORT_SYMBOL 和与之类似的那些宏
|
||||
被检测到的方式,以创建 ksymtab 条目。
|
||||
|
||||
2.1 使用EXPORT_SYMBOL宏
|
||||
=======================
|
||||
使用EXPORT_SYMBOL宏
|
||||
-------------------
|
||||
|
||||
除了允许将内核符号导出到内核符号表的宏EXPORT_SYMBOL()和EXPORT_SYMBOL_GPL()之外,
|
||||
这些宏的变体还可以将符号导出到某个命名空间:EXPORT_SYMBOL_NS() 和 EXPORT_SYMBOL_NS_GPL()。
|
||||
@@ -54,8 +44,8 @@
|
||||
导出时未指明命名空间的符号将指向 ``NULL`` 。如果没有定义命名空间,则默认没有。
|
||||
``modpost`` 和kernel/module/main.c分别在构建时或模块加载时使用名称空间。
|
||||
|
||||
2.2 使用DEFAULT_SYMBOL_NAMESPACE定义
|
||||
====================================
|
||||
使用DEFAULT_SYMBOL_NAMESPACE定义
|
||||
--------------------------------
|
||||
|
||||
为一个子系统的所有符号定义命名空间可能会非常冗长,并可能变得难以维护。因此,我
|
||||
们提供了一个默认定义(DEFAULT_SYMBOL_NAMESPACE),如果设置了这个定义, 它将成
|
||||
@@ -80,8 +70,8 @@
|
||||
|
||||
应置于相关编译单元中任何 EXPORT_SYMBOL 宏之前
|
||||
|
||||
3. 如何使用命名空间中导出的符号
|
||||
===============================
|
||||
如何使用命名空间中导出的符号
|
||||
============================
|
||||
|
||||
为了使用被导出到命名空间的符号,内核模块需要明确地导入这些命名空间。
|
||||
否则内核可能会拒绝加载该模块。模块代码需要使用宏MODULE_IMPORT_NS来
|
||||
@@ -100,11 +90,10 @@
|
||||
|
||||
|
||||
建议将 MODULE_IMPORT_NS() 语句添加到靠近其他模块元数据定义的地方,
|
||||
如 MODULE_AUTHOR() 或 MODULE_LICENSE() 。关于自动创建缺失的导入
|
||||
语句的方法,请参考第5节。
|
||||
如 MODULE_AUTHOR() 或 MODULE_LICENSE() 。
|
||||
|
||||
4. 加载使用命名空间符号的模块
|
||||
=============================
|
||||
加载使用命名空间符号的模块
|
||||
==========================
|
||||
|
||||
在模块加载时(比如 ``insmod`` ),内核将检查每个从模块中引用的符号是否可
|
||||
用,以及它可能被导出到的名字空间是否被模块导入。内核的默认行为是拒绝
|
||||
@@ -113,8 +102,8 @@ EINVAL方式失败。要允许加载不满足这个前提条件的模块,可
|
||||
设置 MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=y 将使加载不受影响,但会
|
||||
发出警告。
|
||||
|
||||
5. 自动创建MODULE_IMPORT_NS声明
|
||||
===============================
|
||||
自动创建MODULE_IMPORT_NS声明
|
||||
============================
|
||||
|
||||
缺少命名空间的导入可以在构建时很容易被检测到。事实上,如果一个模块
|
||||
使用了一个命名空间的符号而没有导入它,modpost会发出警告。
|
||||
|
||||
@@ -754,7 +754,7 @@ targets :=
|
||||
# Normally, just do built-in.
|
||||
|
||||
KBUILD_MODULES :=
|
||||
KBUILD_BUILTIN := 1
|
||||
KBUILD_BUILTIN := y
|
||||
|
||||
# If we have only "make modules", don't compile built-in objects.
|
||||
ifeq ($(MAKECMDGOALS),modules)
|
||||
@@ -766,11 +766,11 @@ endif
|
||||
# Just "make" or "make all" shall build modules as well
|
||||
|
||||
ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMDGOALS)),)
|
||||
KBUILD_MODULES := 1
|
||||
KBUILD_MODULES := y
|
||||
endif
|
||||
|
||||
ifeq ($(MAKECMDGOALS),)
|
||||
KBUILD_MODULES := 1
|
||||
KBUILD_MODULES := y
|
||||
endif
|
||||
|
||||
export KBUILD_MODULES KBUILD_BUILTIN
|
||||
@@ -1189,13 +1189,8 @@ export ARCH_LIB := $(filter %/, $(libs-y))
|
||||
export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
|
||||
# Externally visible symbols (used by link-vmlinux.sh)
|
||||
|
||||
KBUILD_VMLINUX_OBJS := ./built-in.a
|
||||
ifdef CONFIG_MODULES
|
||||
KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
|
||||
KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
|
||||
KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
|
||||
else
|
||||
KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
|
||||
endif
|
||||
|
||||
export KBUILD_VMLINUX_LIBS
|
||||
export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
|
||||
@@ -1203,7 +1198,7 @@ export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
|
||||
ifdef CONFIG_TRIM_UNUSED_KSYMS
|
||||
# For the kernel to actually contain only the needed exported symbols,
|
||||
# we have to build modules as well to determine what those symbols are.
|
||||
KBUILD_MODULES := 1
|
||||
KBUILD_MODULES := y
|
||||
endif
|
||||
|
||||
# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
|
||||
@@ -1370,7 +1365,7 @@ PHONY += archheaders archscripts
|
||||
hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
|
||||
|
||||
PHONY += headers
|
||||
headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
|
||||
headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders
|
||||
ifdef HEADER_ARCH
|
||||
$(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers
|
||||
else
|
||||
@@ -1543,7 +1538,7 @@ all: modules
|
||||
# the built-in objects during the descend as well, in order to
|
||||
# make sure the checksums are up to date before we record them.
|
||||
ifdef CONFIG_MODVERSIONS
|
||||
KBUILD_BUILTIN := 1
|
||||
KBUILD_BUILTIN := y
|
||||
endif
|
||||
|
||||
# Build modules
|
||||
@@ -1552,7 +1547,7 @@ endif
|
||||
# *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES
|
||||
# is an exception.
|
||||
ifdef CONFIG_DEBUG_INFO_BTF_MODULES
|
||||
KBUILD_BUILTIN := 1
|
||||
KBUILD_BUILTIN := y
|
||||
modules: vmlinux
|
||||
endif
|
||||
|
||||
@@ -1837,9 +1832,12 @@ rustfmtcheck: rustfmt
|
||||
# Misc
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Run misc checks when ${KBUILD_EXTRA_WARN} contains 1
|
||||
PHONY += misc-check
|
||||
ifneq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
|
||||
misc-check:
|
||||
$(Q)$(srctree)/scripts/misc-check
|
||||
endif
|
||||
|
||||
all: misc-check
|
||||
|
||||
@@ -1865,7 +1863,7 @@ filechk_kernel.release = echo $(KERNELRELEASE)
|
||||
|
||||
# We are always building only modules.
|
||||
KBUILD_BUILTIN :=
|
||||
KBUILD_MODULES := 1
|
||||
KBUILD_MODULES := y
|
||||
|
||||
build-dir := .
|
||||
|
||||
@@ -1993,7 +1991,7 @@ endif
|
||||
|
||||
single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
|
||||
|
||||
KBUILD_MODULES := 1
|
||||
KBUILD_MODULES := y
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Makefile for the linux kernel.
|
||||
#
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
asflags-y := $(KBUILD_CFLAGS)
|
||||
ccflags-y := -Wno-sign-compare
|
||||
|
||||
|
||||
@@ -26,4 +26,4 @@ ifdef CONFIG_ISA_ARCOMPACT
|
||||
CFLAGS_fpu.o += -mdpfp
|
||||
endif
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
@@ -104,4 +104,4 @@ obj-$(CONFIG_HAVE_ARM_SMCCC) += smccc-call.o
|
||||
|
||||
obj-$(CONFIG_GENERIC_CPU_VULNERABILITIES) += spectre.o
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
@@ -78,7 +78,7 @@ $(obj)/vdso32-wrap.o: $(obj)/vdso32/vdso.so
|
||||
|
||||
obj-y += probes/
|
||||
obj-y += head.o
|
||||
extra-y += vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) += vmlinux.lds
|
||||
|
||||
ifeq ($(CONFIG_DEBUG_EFI),y)
|
||||
AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y += head.o entry.o atomic.o signal.o traps.o irq.o time.o vdso.o vdso/
|
||||
obj-y += power.o syscall.o syscall_table.o setup.o
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y += head.o
|
||||
obj-$(CONFIG_SMP) += smp.o
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
OBJECT_FILES_NON_STANDARD_head.o := y
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y += head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
|
||||
traps.o irq.o idle.o process.o dma.o mem.o reset.o switch.o \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Makefile for the linux kernel.
|
||||
#
|
||||
|
||||
extra-y += vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) += vmlinux.lds
|
||||
|
||||
obj-$(CONFIG_MMU_MOTOROLA) := head.o
|
||||
obj-$(CONFIG_SUN3) := sun3-head.o
|
||||
|
||||
@@ -11,7 +11,7 @@ CFLAGS_REMOVE_ftrace.o = -pg
|
||||
CFLAGS_REMOVE_process.o = -pg
|
||||
endif
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y += head.o dma.o exceptions.o \
|
||||
hw_exception_handler.o irq.o \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Makefile for the Linux/MIPS kernel.
|
||||
#
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y += head.o branch.o cmpxchg.o elf.o entry.o genex.o idle.o irq.o \
|
||||
process.o prom.o ptrace.o reset.o setup.o signal.o \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Makefile for the nios2 linux kernel.
|
||||
#
|
||||
|
||||
extra-y += vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) += vmlinux.lds
|
||||
|
||||
obj-y += head.o
|
||||
obj-y += cpuinfo.o
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Makefile for the linux kernel.
|
||||
#
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y := head.o setup.o or32_ksyms.o process.o dma.o \
|
||||
traps.o time.o irq.o entry.o ptrace.o signal.o \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Makefile for arch/parisc/kernel
|
||||
#
|
||||
|
||||
extra-y := vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) := vmlinux.lds
|
||||
|
||||
obj-y := head.o cache.o pacache.o setup.o pdt.o traps.o time.o irq.o \
|
||||
syscall.o entry.o sys_parisc.o firmware.o \
|
||||
|
||||
@@ -126,7 +126,7 @@ obj-$(CONFIG_PPC_BOOK3S_32) += head_book3s_32.o
|
||||
obj-$(CONFIG_44x) += head_44x.o
|
||||
obj-$(CONFIG_PPC_8xx) += head_8xx.o
|
||||
obj-$(CONFIG_PPC_85xx) += head_85xx.o
|
||||
extra-y += vmlinux.lds
|
||||
always-$(KBUILD_BUILTIN) += vmlinux.lds
|
||||
|
||||
obj-$(CONFIG_RELOCATABLE) += reloc_$(BITS).o
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user