Skip to content

Commit 312b148

Browse files
committed
Introduce new section reference annotations tags: __ref, __refdata, __refconst
Today we have the following annotations for functions/data referencing __init/__exit functions / data: __init_refok => for init functions __initdata_refok => for init data __exit_refok => for exit functions There is really no difference between the __init and __exit versions and simplify it and to introduce a shorter annotation the following new annotations are introduced: __ref => for functions (code) that references __*init / __*exit __refdata => for variables __refconst => for const variables Whit this annotation is it more obvious what the annotation is for and there is no longer the arbitary division between __init and __exit code. The mechanishm is the same as before - a special section is created which is made part of the usual sections in the linker script. We will start to see annotations like this: -static struct pci_serial_quirk pci_serial_quirks[] = { +static const struct pci_serial_quirk pci_serial_quirks[] __refconst = { ----------------- -static struct notifier_block __cpuinitdata cpuid_class_cpu_notifier = +static struct notifier_block cpuid_class_cpu_notifier __refdata = ---------------- -static int threshold_cpu_callback(struct notifier_block *nfb, +static int __ref threshold_cpu_callback(struct notifier_block *nfb, [The above is just random samples]. Note: No modifications were needed in modpost to support the new sections due to the newly introduced blacklisting. Signed-off-by: Sam Ravnborg <[email protected]>
1 parent e241a63 commit 312b148

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define DATA_DATA \
4343
*(.data) \
4444
*(.data.init.refok) \
45+
*(.ref.data) \
4546
DEV_KEEP(init.data) \
4647
DEV_KEEP(exit.data) \
4748
CPU_KEEP(init.data) \
@@ -169,6 +170,7 @@
169170
\
170171
/* __*init sections */ \
171172
__init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
173+
*(.ref.rodata) \
172174
DEV_KEEP(init.rodata) \
173175
DEV_KEEP(exit.rodata) \
174176
CPU_KEEP(init.rodata) \
@@ -202,6 +204,7 @@
202204
#define TEXT_TEXT \
203205
ALIGN_FUNCTION(); \
204206
*(.text) \
207+
*(.ref.text) \
205208
*(.text.init.refok) \
206209
*(.exit.text.refok) \
207210
DEV_KEEP(init.text) \

include/linux/init.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,26 @@
5252
* when early init has completed so all such references are potential bugs.
5353
* For exit sections the same issue exists.
5454
* The following markers are used for the cases where the reference to
55-
* the init/exit section (code or data) is valid and will teach modpost
56-
* not to issue a warning.
55+
* the *init / *exit section (code or data) is valid and will teach
56+
* modpost not to issue a warning.
5757
* The markers follow same syntax rules as __init / __initdata. */
58-
#define __init_refok noinline __section(.text.init.refok)
59-
#define __initdata_refok __section(.data.init.refok)
60-
#define __exit_refok noinline __section(.exit.text.refok)
58+
#define __ref __section(.ref.text) noinline
59+
#define __refdata __section(.ref.data)
60+
#define __refconst __section(.ref.rodata)
61+
62+
/* backward compatibility note
63+
* A few places hardcode the old section names:
64+
* .text.init.refok
65+
* .data.init.refok
66+
* .exit.text.refok
67+
* They should be converted to use the defines from this file
68+
*/
69+
70+
/* compatibility defines */
71+
#define __init_refok __ref
72+
#define __initdata_refok __refdata
73+
#define __exit_refok __ref
74+
6175

6276
#ifdef MODULE
6377
#define __exitused
@@ -93,11 +107,9 @@
93107

94108
/* For assembly routines */
95109
#define __INIT .section ".init.text","ax"
96-
#define __INIT_REFOK .section ".text.init.refok","ax"
97110
#define __FINIT .previous
98111

99112
#define __INITDATA .section ".init.data","aw"
100-
#define __INITDATA_REFOK .section ".data.init.refok","aw"
101113

102114
#define __DEVINIT .section ".devinit.text", "ax"
103115
#define __DEVINITDATA .section ".devinit.data", "aw"
@@ -108,6 +120,14 @@
108120
#define __MEMINIT .section ".meminit.text", "ax"
109121
#define __MEMINITDATA .section ".meminit.data", "aw"
110122

123+
/* silence warnings when references are OK */
124+
#define __REF .section ".ref.text", "ax"
125+
#define __REFDATA .section ".ref.data", "aw"
126+
#define __REFCONST .section ".ref.rodata", "aw"
127+
/* backward compatibility */
128+
#define __INIT_REFOK .section __REF
129+
#define __INITDATA_REFOK .section __REFDATA
130+
111131
#ifndef __ASSEMBLY__
112132
/*
113133
* Used for initialization calls..

0 commit comments

Comments
 (0)