Skip to contentSkip to conversation

modpost: remove ALL_EXIT_DATA_SECTIONS macro

PATCH In review Masahiro Yamada 3 participants 13 messages Oct 22, 2023 – Oct 28, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/10 modpost: remove ALL_EXIT_DATA_SECTIONS macro

This is unused.

---

 scripts/mod/modpost.c | 2 --
 1 file changed, 2 deletions(-)
scripts/mod/modpost.c +0 -2
index f1f658122ad8..d936fa5fbbb1 100644
@@ -794,8 +794,6 @@ static void check_section(const char *modname, struct elf_info *elf,
 #define ALL_INIT_DATA_SECTIONS \
 	".init.setup", ".init.rodata", ".meminit.rodata", \
 	".init.data", ".meminit.data"
-#define ALL_EXIT_DATA_SECTIONS \
-	".exit.data", ".memexit.data"
 
 #define ALL_INIT_TEXT_SECTIONS \
 	".init.text", ".meminit.text"
Signature · 1 line
2.40.1
#1 lore raw

PATCH 2/10 linux/init: remove __memexit* annotations

We have never used __memexit, __memexitdata, or __memexitconst.

These were unneeded.

---

 include/asm-generic/vmlinux.lds.h |  6 ------
 include/linux/init.h              |  3 ---
 scripts/mod/modpost.c             | 15 +++------------
 3 files changed, 3 insertions(+), 21 deletions(-)
include/asm-generic/vmlinux.lds.h +0 -6
index 67d8dd2f1bde..bae0fe4d499b 100644
@@ -356,7 +356,6 @@
 	*(.ref.data)							\
 	*(.data..shared_aligned) /* percpu related */			\
 	MEM_KEEP(init.data*)						\
-	MEM_KEEP(exit.data*)						\
 	*(.data.unlikely)						\
 	__start_once = .;						\
 	*(.data.once)							\
@@ -521,7 +520,6 @@
 	__init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) {		\
 		*(.ref.rodata)						\
 		MEM_KEEP(init.rodata)					\
-		MEM_KEEP(exit.rodata)					\
 	}								\
 									\
 	/* Built-in module parameters. */				\
@@ -574,7 +572,6 @@
 		*(.ref.text)						\
 		*(.text.asan.* .text.tsan.*)				\
 	MEM_KEEP(init.text*)						\
-	MEM_KEEP(exit.text*)						\
 
 
 /* sched.text is aling to function alignment to secure we have same
@@ -714,13 +711,10 @@
 	*(.exit.data .exit.data.*)					\
 	*(.fini_array .fini_array.*)					\
 	*(.dtors .dtors.*)						\
-	MEM_DISCARD(exit.data*)						\
-	MEM_DISCARD(exit.rodata*)
 
 #define EXIT_TEXT							\
 	*(.exit.text)							\
 	*(.text.exit)							\
-	MEM_DISCARD(exit.text)
 
 #define EXIT_CALL							\
 	*(.exitcall.exit)
include/linux/init.h +0 -3
index 266c3e1640d4..01b52c9c7526 100644
@@ -89,9 +89,6 @@
 						  __latent_entropy
 #define __meminitdata    __section(".meminit.data")
 #define __meminitconst   __section(".meminit.rodata")
-#define __memexit        __section(".memexit.text") __exitused __cold notrace
-#define __memexitdata    __section(".memexit.data")
-#define __memexitconst   __section(".memexit.rodata")
 
 /* For assembly routines */
 #define __HEAD		.section	".head.text","ax"
scripts/mod/modpost.c +3 -12
index d936fa5fbbb1..bcc334b28a2c 100644
@@ -798,7 +798,7 @@ static void check_section(const char *modname, struct elf_info *elf,
 #define ALL_INIT_TEXT_SECTIONS \
 	".init.text", ".meminit.text"
 #define ALL_EXIT_TEXT_SECTIONS \
-	".exit.text", ".memexit.text"
+	".exit.text"
 
 #define ALL_PCI_INIT_SECTIONS	\
 	".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \
@@ -806,10 +806,9 @@ static void check_section(const char *modname, struct elf_info *elf,
 	".pci_fixup_resume_early", ".pci_fixup_suspend"
 
 #define ALL_XXXINIT_SECTIONS MEM_INIT_SECTIONS
-#define ALL_XXXEXIT_SECTIONS MEM_EXIT_SECTIONS
 
 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
-#define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS
+#define ALL_EXIT_SECTIONS EXIT_SECTIONS
 
 #define DATA_SECTIONS ".data", ".data.rel"
 #define TEXT_SECTIONS ".text", ".text.*", ".sched.text", \
@@ -822,7 +821,6 @@ static void check_section(const char *modname, struct elf_info *elf,
 #define MEM_INIT_SECTIONS  ".meminit.*"
 
 #define EXIT_SECTIONS      ".exit.*"
-#define MEM_EXIT_SECTIONS  ".memexit.*"
 
 #define ALL_TEXT_SECTIONS  ALL_INIT_TEXT_SECTIONS, ALL_EXIT_TEXT_SECTIONS, \
 		TEXT_SECTIONS, OTHER_TEXT_SECTIONS
@@ -832,7 +830,6 @@ enum mismatch {
 	DATA_TO_ANY_INIT,
 	TEXTDATA_TO_ANY_EXIT,
 	XXXINIT_TO_SOME_INIT,
-	XXXEXIT_TO_SOME_EXIT,
 	ANY_INIT_TO_ANY_EXIT,
 	ANY_EXIT_TO_ANY_INIT,
 	EXTABLE_TO_NON_TEXT,
@@ -883,12 +880,6 @@ static const struct sectioncheck sectioncheck[] = {
 	.bad_tosec = { INIT_SECTIONS, NULL },
 	.mismatch = XXXINIT_TO_SOME_INIT,
 },
-/* Do not reference exit code/data from memexit code/data */
-{
-	.fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
-	.bad_tosec = { EXIT_SECTIONS, NULL },
-	.mismatch = XXXEXIT_TO_SOME_EXIT,
-},
 /* Do not use exit code/data from init code */
 {
 	.fromsec = { ALL_INIT_SECTIONS, NULL },
@@ -1017,7 +1008,7 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
 
 	/* symbols in data sections that may refer to meminit sections */
 	if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
-	    match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS, ALL_XXXEXIT_SECTIONS)) &&
+	    match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS)) &&
 	    match(fromsym, PATTERNS("*driver")))
 		return 0;
 
Signature · 1 line
2.40.1
#3 lore raw

PATCH 3/10 modpost: disallow *driver to reference .meminit* sections

In reply to Masahiro Yamada

Drivers must not reference .meminit* sections, which are discarded when CONFIG_MEMORY_HOTPLUG=n.

The reason for whitelisting "*driver" in the section mismatch check was to allow drivers to reference symbols annotated as __devinit or __devexit that existed in the past.

Those annotations were removed by the following commits:

- 54b956b90360 ("Remove __dev* markings from init.h")
- 92e9e6d1f984 ("modpost.c: Stop checking __dev* section mismatches")

Remove the wrong whitelist.

---

 scripts/mod/modpost.c | 6 ------
 1 file changed, 6 deletions(-)
scripts/mod/modpost.c +0 -6
index bcc334b28a2c..792ba9da0f27 100644
@@ -1006,12 +1006,6 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
 				    "*_console")))
 		return 0;
 
-	/* symbols in data sections that may refer to meminit sections */
-	if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
-	    match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS)) &&
-	    match(fromsym, PATTERNS("*driver")))
-		return 0;
-
 	/*
 	 * symbols in data sections must not refer to .exit.*, but there are
 	 * quite a few offenders, so hide these unless for W=1 builds until
Signature · 1 line
2.40.1
#4 lore raw

PATCH 4/10 modpost: remove more symbol patterns from the section check whitelist

In reply to Masahiro Yamada

These symbol patterns were whitelisted to allow them to reference to functions with the old __devinit and __devexit annotations.

We stopped doing this a long time ago, for example, commit 6f039790510f ("Drivers: scsi: remove __dev* attributes.") remove those annotations from the scsi drivers.

Keep *_ops and *_console, otherwise they will really cause section mismatch warnings.

---

 scripts/mod/modpost.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
scripts/mod/modpost.c +1 -7
index 792ba9da0f27..19b138664f75 100644
@@ -997,13 +997,7 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
 	/* symbols in data sections that may refer to any init/exit sections */
 	if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
 	    match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
-	    match(fromsym, PATTERNS("*_template", // scsi uses *_template a lot
-				    "*_timer", // arm uses ops structures named _timer a lot
-				    "*_sht", // scsi also used *_sht to some extent
-				    "*_ops",
-				    "*_probe",
-				    "*_probe_one",
-				    "*_console")))
+	    match(fromsym, PATTERNS("*_ops", "*_console")))
 		return 0;
 
 	/*
Signature · 1 line
2.40.1
#5 lore raw

Re: [PATCH 04/10] modpost: remove more symbol patterns from the section check whitelist

Quoted 21 lines · Masahiro Yamada

These symbol patterns were whitelisted to allow them to reference to functions with the old __devinit and __devexit annotations.

We stopped doing this a long time ago, for example, commit 6f039790510f ("Drivers: scsi: remove __dev* attributes.") remove those annotations from the scsi drivers.

Keep *_ops and *_console, otherwise they will really cause section mismatch warnings.

---

 scripts/mod/modpost.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
scripts/mod/modpost.c +0 -0
index 792ba9da0f27..19b138664f75 100644

scripts/mod/modpost.c static int secref_whitelist(const char *fromsec, const char *fromsym, · line 1004

Quoted 8 lines
scripts/mod/modpost.c +0 -5
@@ -997,13 +997,7 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
 	/* symbols in data sections that may refer to any init/exit sections */
 	if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
 	    match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
-	    match(fromsym, PATTERNS("*_template", // scsi uses *_template a lot
-				    "*_timer", // arm uses ops structures named _timer a lot
-				    "*_sht", // scsi also used *_sht to some extent
-				    "*_ops",
-				    "*_probe",

It seems like this one might still be needed. I see this when building certain arm64 configurations with clang.

WARNING: modpost: vmlinux: section mismatch in reference: qcom_irq_combiner_probe+0x0 (section: .data) -> combiner_probe (section: .init.text)

Quoted 9 lines
scripts/mod/modpost.c +1 -2
-				    "*_probe_one",
-				    "*_console")))
+	    match(fromsym, PATTERNS("*_ops", "*_console")))
 		return 0;
 
 	/*
Signature · 1 line
2.40.1
#6 lore raw

Re: [PATCH 04/10] modpost: remove more symbol patterns from the section check whitelist

Quoted 35 lines · Nathan Chancellor
Quoted 21 lines · Masahiro Yamada

These symbol patterns were whitelisted to allow them to reference to functions with the old __devinit and __devexit annotations.

We stopped doing this a long time ago, for example, commit 6f039790510f ("Drivers: scsi: remove __dev* attributes.") remove those annotations from the scsi drivers.

Keep *_ops and *_console, otherwise they will really cause section mismatch warnings.

---

 scripts/mod/modpost.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
scripts/mod/modpost.c +0 -0
index 792ba9da0f27..19b138664f75 100644

scripts/mod/modpost.c static int secref_whitelist(const char *fromsec, const char *fromsym, · line 1004

Quoted 8 lines
scripts/mod/modpost.c +0 -5
@@ -997,13 +997,7 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
      /* symbols in data sections that may refer to any init/exit sections */
      if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
          match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
-         match(fromsym, PATTERNS("*_template", // scsi uses *_template a lot
-                                 "*_timer", // arm uses ops structures named _timer a lot
-                                 "*_sht", // scsi also used *_sht to some extent
-                                 "*_ops",
-                                 "*_probe",

It seems like this one might still be needed. I see this when building certain arm64 configurations with clang.

Quoted 1 line

WARNING: modpost: vmlinux: section mismatch in reference: qcom_irq_combiner_probe+0x0 (section: .data) -> combiner_probe (section: .init.text)

Thanks for comprehensive compile-testing.

I will keep "*_probe", but I believe __ref is better if this is only the instance that happens to have _ops suffix.

Quoted 9 lines
Quoted 9 lines
scripts/mod/modpost.c +1 -3
-                                 "*_probe_one",
-                                 "*_console")))
+         match(fromsym, PATTERNS("*_ops", "*_console")))
              return 0;
 
      /*
--

2.40.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#7 lore raw

PATCH 5/10 modpost: remove MEM_INIT_SECTIONS macro

In reply to Masahiro Yamada

ALL_XXXINIT_SECTIONS and MEM_INIT_SECTIONS are the same. Remove the latter.

---

 scripts/mod/modpost.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/mod/modpost.c +1 -2
index 19b138664f75..626ab599eea2 100644
@@ -805,7 +805,7 @@ static void check_section(const char *modname, struct elf_info *elf,
 	".pci_fixup_enable", ".pci_fixup_resume", \
 	".pci_fixup_resume_early", ".pci_fixup_suspend"
 
-#define ALL_XXXINIT_SECTIONS MEM_INIT_SECTIONS
+#define ALL_XXXINIT_SECTIONS ".meminit.*"
 
 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
 #define ALL_EXIT_SECTIONS EXIT_SECTIONS
@@ -818,7 +818,6 @@ static void check_section(const char *modname, struct elf_info *elf,
 		".coldtext", ".softirqentry.text"
 
 #define INIT_SECTIONS      ".init.*"
-#define MEM_INIT_SECTIONS  ".meminit.*"
 
 #define EXIT_SECTIONS      ".exit.*"
 
Signature · 1 line
2.40.1
#8 lore raw

PATCH 6/10 modpost: remove EXIT_SECTIONS macro

In reply to Masahiro Yamada

ALL_EXIT_SECTIONS and EXIT_SECTIONS are the same. Remove the latter.

---

 scripts/mod/modpost.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/mod/modpost.c +3 -5
index 626ab599eea2..f73835b8f1f9 100644
@@ -808,7 +808,7 @@ static void check_section(const char *modname, struct elf_info *elf,
 #define ALL_XXXINIT_SECTIONS ".meminit.*"
 
 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
-#define ALL_EXIT_SECTIONS EXIT_SECTIONS
+#define ALL_EXIT_SECTIONS ".exit.*"
 
 #define DATA_SECTIONS ".data", ".data.rel"
 #define TEXT_SECTIONS ".text", ".text.*", ".sched.text", \
@@ -819,8 +819,6 @@ static void check_section(const char *modname, struct elf_info *elf,
 
 #define INIT_SECTIONS      ".init.*"
 
-#define EXIT_SECTIONS      ".exit.*"
-
 #define ALL_TEXT_SECTIONS  ALL_INIT_TEXT_SECTIONS, ALL_EXIT_TEXT_SECTIONS, \
 		TEXT_SECTIONS, OTHER_TEXT_SECTIONS
 
@@ -1006,7 +1004,7 @@ static int secref_whitelist(const char *fromsec, const char *fromsym,
 	 */
 	if (!extra_warn &&
 	    match(fromsec, PATTERNS(DATA_SECTIONS)) &&
-	    match(tosec, PATTERNS(EXIT_SECTIONS)) &&
+	    match(tosec, PATTERNS(ALL_EXIT_SECTIONS)) &&
 	    match(fromsym, PATTERNS("*driver")))
 		return 0;
 
@@ -1169,7 +1167,7 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf,
 	if (match(secname, PATTERNS(INIT_SECTIONS)))
 		warn("%s: %s: EXPORT_SYMBOL used for init symbol. Remove __init or EXPORT_SYMBOL.\n",
 		     mod->name, name);
-	else if (match(secname, PATTERNS(EXIT_SECTIONS)))
+	else if (match(secname, PATTERNS(ALL_EXIT_SECTIONS)))
 		warn("%s: %s: EXPORT_SYMBOL used for exit symbol. Remove __exit or EXPORT_SYMBOL.\n",
 		     mod->name, name);
 }
Signature · 1 line
2.40.1
#9 lore raw

PATCH 7/10 modpost: disallow the combination of EXPORT_SYMBOL and __meminit*

In reply to Masahiro Yamada

Theoretically, we could export conditionally-discarded code sections, such as .meminit*, if all the users can become modular under a certain condition. However, that would be difficult to control and such a tricky case has never occurred.

---

 scripts/mod/modpost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mod/modpost.c +1 -1
index f73835b8f1f9..8f4bddbbc52b 100644
@@ -1164,7 +1164,7 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf,
 	    ELF_ST_TYPE(sym->st_info) == STT_LOPROC)
 		s->is_func = true;
 
-	if (match(secname, PATTERNS(INIT_SECTIONS)))
+	if (match(secname, PATTERNS(ALL_INIT_SECTIONS)))
 		warn("%s: %s: EXPORT_SYMBOL used for init symbol. Remove __init or EXPORT_SYMBOL.\n",
 		     mod->name, name);
 	else if (match(secname, PATTERNS(ALL_EXIT_SECTIONS)))
Signature · 1 line
2.40.1
#10 lore raw

PATCH 8/10 modpost: use ALL_INIT_SECTIONS for the section check from DATA_SECTIONS

In reply to Masahiro Yamada

ALL_INIT_SECTIONS is defined as follows:

  #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS

---

 scripts/mod/modpost.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/mod/modpost.c +1 -1
index 8f4bddbbc52b..c726383c1909 100644
@@ -863,7 +863,7 @@ static const struct sectioncheck sectioncheck[] = {
 },
 {
 	.fromsec = { DATA_SECTIONS, NULL },
-	.bad_tosec = { ALL_XXXINIT_SECTIONS, INIT_SECTIONS, NULL },
+	.bad_tosec = { ALL_INIT_SECTIONS, NULL },
 	.mismatch = DATA_TO_ANY_INIT,
 },
 {
Signature · 1 line
2.40.1
#11 lore raw

PATCH 9/10 modpost: merge sectioncheck table entries regarding init/exit sections

In reply to Masahiro Yamada

Check symbol references from normal sections to init/exit sections in a single entry.

---

 scripts/mod/modpost.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
scripts/mod/modpost.c +3 -15
index c726383c1909..e4eb989dc764 100644
@@ -823,9 +823,7 @@ static void check_section(const char *modname, struct elf_info *elf,
 		TEXT_SECTIONS, OTHER_TEXT_SECTIONS
 
 enum mismatch {
-	TEXT_TO_ANY_INIT,
-	DATA_TO_ANY_INIT,
-	TEXTDATA_TO_ANY_EXIT,
+	TEXTDATA_TO_ANY_INIT_EXIT,
 	XXXINIT_TO_SOME_INIT,
 	ANY_INIT_TO_ANY_EXIT,
 	ANY_EXIT_TO_ANY_INIT,
@@ -856,20 +854,10 @@ static const struct sectioncheck sectioncheck[] = {
 /* Do not reference init/exit code/data from
  * normal code and data
  */
-{
-	.fromsec = { TEXT_SECTIONS, NULL },
-	.bad_tosec = { ALL_INIT_SECTIONS, NULL },
-	.mismatch = TEXT_TO_ANY_INIT,
-},
-{
-	.fromsec = { DATA_SECTIONS, NULL },
-	.bad_tosec = { ALL_INIT_SECTIONS, NULL },
-	.mismatch = DATA_TO_ANY_INIT,
-},
 {
 	.fromsec = { TEXT_SECTIONS, DATA_SECTIONS, NULL },
-	.bad_tosec = { ALL_EXIT_SECTIONS, NULL },
-	.mismatch = TEXTDATA_TO_ANY_EXIT,
+	.bad_tosec = { ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL },
+	.mismatch = TEXTDATA_TO_ANY_INIT_EXIT,
 },
 /* Do not reference init code/data from meminit code/data */
 {
Signature · 1 line
2.40.1
#12 lore raw

PATCH 10/10 modpost: squash ALL_{INIT,EXIT}_TEXT_SECTIONS to ALL_TEXT_SECTIONS

In reply to Masahiro Yamada

ALL_INIT_TEXT_SECTIONS and ALL_EXIT_TEXT_SECTIONS are only used in the macro definition of ALL_TEXT_SECTIONS.

---

 scripts/mod/modpost.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
scripts/mod/modpost.c +1 -6
index e4eb989dc764..f27ea0b8531d 100644
@@ -795,11 +795,6 @@ static void check_section(const char *modname, struct elf_info *elf,
 	".init.setup", ".init.rodata", ".meminit.rodata", \
 	".init.data", ".meminit.data"
 
-#define ALL_INIT_TEXT_SECTIONS \
-	".init.text", ".meminit.text"
-#define ALL_EXIT_TEXT_SECTIONS \
-	".exit.text"
-
 #define ALL_PCI_INIT_SECTIONS	\
 	".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \
 	".pci_fixup_enable", ".pci_fixup_resume", \
@@ -819,7 +814,7 @@ static void check_section(const char *modname, struct elf_info *elf,
 
 #define INIT_SECTIONS      ".init.*"
 
-#define ALL_TEXT_SECTIONS  ALL_INIT_TEXT_SECTIONS, ALL_EXIT_TEXT_SECTIONS, \
+#define ALL_TEXT_SECTIONS  ".init.text", ".meminit.text", ".exit.text", \
 		TEXT_SECTIONS, OTHER_TEXT_SECTIONS
 
 enum mismatch {
Signature · 1 line
2.40.1