modpost: Don't let "driver"s reference .exit.*

Drivers must not reference functions marked with __exit as these likely
are not available when the code is built-in.

There are few creative offenders uncovered for example in ARCH=amd64
allmodconfig builds. So only trigger the section mismatch warning for
W=1 builds.

The dual rule that drivers must not reference .init.* is implemented
since commit 0db252452378 ("modpost: don't allow *driver to reference
.init.*") which however missed that .exit.* should be handled in the
same way.

Thanks to Masahiro Yamada and Arnd Bergmann who gave valuable hints to
find this improvement.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by Uwe Kleine-König and committed by Masahiro Yamada f177cd0c 15e86643

+13 -2
+13 -2
scripts/mod/modpost.c
··· 1015 1015 "*_console"))) 1016 1016 return 0; 1017 1017 1018 - /* symbols in data sections that may refer to meminit/exit sections */ 1018 + /* symbols in data sections that may refer to meminit sections */ 1019 1019 if (match(fromsec, PATTERNS(DATA_SECTIONS)) && 1020 - match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS, ALL_EXIT_SECTIONS)) && 1020 + match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS, ALL_XXXEXIT_SECTIONS)) && 1021 + match(fromsym, PATTERNS("*driver"))) 1022 + return 0; 1023 + 1024 + /* 1025 + * symbols in data sections must not refer to .exit.*, but there are 1026 + * quite a few offenders, so hide these unless for W=1 builds until 1027 + * these are fixed. 1028 + */ 1029 + if (!extra_warn && 1030 + match(fromsec, PATTERNS(DATA_SECTIONS)) && 1031 + match(tosec, PATTERNS(EXIT_SECTIONS)) && 1021 1032 match(fromsym, PATTERNS("*driver"))) 1022 1033 return 0; 1023 1034