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

kbuild: introduce __init_refok/__initdata_refok to supress section mismatch warnings

Throughout the kernel there are a few legitimite references
to init or exit sections. Most of these are covered by the
patterns included in modpost but a few nees special attention.
To avoid hardcoding a lot of function names in modpost introduce
a marker so relevant function/data can be marked.
When modpost see a reference to a init/exit function from
a function/data marked no warning will be issued.

Idea from: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>

+28 -2
+4 -2
include/asm-generic/vmlinux.lds.h
··· 11 11 12 12 /* .data section */ 13 13 #define DATA_DATA \ 14 - *(.data) 14 + *(.data) \ 15 + *(.data.init.refok) 15 16 16 17 #define RODATA \ 17 18 . = ALIGN(4096); \ ··· 148 147 * during second ld run in second ld pass when generating System.map */ 149 148 #define TEXT_TEXT \ 150 149 ALIGN_FUNCTION(); \ 151 - *(.text) 150 + *(.text) \ 151 + *(.text.init.refok) 152 152 153 153 /* sched.text is aling to function alignment to secure we have same 154 154 * address even at second ld pass when generating System.map */
+13
include/linux/init.h
··· 45 45 #define __exitdata __attribute__ ((__section__(".exit.data"))) 46 46 #define __exit_call __attribute_used__ __attribute__ ((__section__ (".exitcall.exit"))) 47 47 48 + /* modpost check for section mismatches during the kernel build. 49 + * A section mismatch happens when there are references from a 50 + * code or data section to an init section (both code or data). 51 + * The init sections are (for most archs) discarded by the kernel 52 + * when early init has completed so all such references are potential bugs. 53 + * For exit sections the same issue exists. 54 + * 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. 57 + * The markers follow same syntax rules as __init / __initdata. */ 58 + #define __init_refok noinline __attribute__ ((__section__ (".text.init.refok"))) 59 + #define __initdata_refok __attribute__ ((__section__ (".data.init.refok"))) 60 + 48 61 #ifdef MODULE 49 62 #define __exit __attribute__ ((__section__(".exit.text"))) 50 63 #else
+11
scripts/mod/modpost.c
··· 583 583 584 584 /** 585 585 * Whitelist to allow certain references to pass with no warning. 586 + * 587 + * Pattern 0: 588 + * Do not warn if funtion/data are marked with __init_refok/__initdata_refok. 589 + * The pattern is identified by: 590 + * fromsec = .text.init.refok | .data.init.refok 591 + * 586 592 * Pattern 1: 587 593 * If a module parameter is declared __initdata and permissions=0 588 594 * then this is legal despite the warning generated. ··· 691 685 "zone_wait_table_init", 692 686 NULL 693 687 }; 688 + 689 + /* Check for pattern 0 */ 690 + if ((strcmp(fromsec, ".text.init.refok") == 0) || 691 + (strcmp(fromsec, ".data.init.refok") == 0)) 692 + return 1; 694 693 695 694 /* Check for pattern 1 */ 696 695 if (strcmp(tosec, ".init.data") != 0)