Skip to content

Commit 672fb67

Browse files
committed
modpost: remove .symbol_white_list field entirely
It is not so useful to have symbol whitelists in arrays. With this over-engineering, the code is difficult to follow. Let's do it more directly, and collect the relevant code to one place. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 1560cb0 commit 672fb67

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

scripts/mod/modpost.c

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -845,28 +845,12 @@ static const char *const init_data_sections[] =
845845
/* all init sections */
846846
static const char *const init_sections[] = { ALL_INIT_SECTIONS, NULL };
847847

848-
/* All init and exit sections (code + data) */
849-
static const char *const init_exit_sections[] =
850-
{ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL };
851-
852848
/* all text sections */
853849
static const char *const text_sections[] = { ALL_TEXT_SECTIONS, NULL };
854850

855851
/* data section */
856852
static const char *const data_sections[] = { DATA_SECTIONS, NULL };
857853

858-
859-
/* symbols in .data that may refer to init/exit sections */
860-
#define DEFAULT_SYMBOL_WHITE_LIST \
861-
"*driver", \
862-
"*_template", /* scsi uses *_template a lot */ \
863-
"*_timer", /* arm uses ops structures named _timer a lot */ \
864-
"*_sht", /* scsi also used *_sht to some extent */ \
865-
"*_ops", \
866-
"*_probe", \
867-
"*_probe_one", \
868-
"*_console"
869-
870854
static const char *const head_sections[] = { ".head.text*", NULL };
871855
static const char *const linker_symbols[] =
872856
{ "__init_begin", "_sinittext", "_einittext", NULL };
@@ -898,9 +882,6 @@ enum mismatch {
898882
*
899883
* @mismatch: Type of mismatch.
900884
*
901-
* @symbol_white_list: Do not match a relocation to a symbol in this list
902-
* even if it is targeting a section in @bad_to_sec.
903-
*
904885
* @handler: Specific handler to call when a match is found. If NULL,
905886
* default_mismatch_handler() will be called.
906887
*
@@ -910,7 +891,6 @@ struct sectioncheck {
910891
const char *bad_tosec[20];
911892
const char *good_tosec[20];
912893
enum mismatch mismatch;
913-
const char *symbol_white_list[20];
914894
void (*handler)(const char *modname, struct elf_info *elf,
915895
const struct sectioncheck* const mismatch,
916896
Elf_Rela *r, Elf_Sym *sym, const char *fromsec);
@@ -935,16 +915,11 @@ static const struct sectioncheck sectioncheck[] = {
935915
.fromsec = { DATA_SECTIONS, NULL },
936916
.bad_tosec = { ALL_XXXINIT_SECTIONS, NULL },
937917
.mismatch = DATA_TO_ANY_INIT,
938-
.symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
939918
},
940919
{
941920
.fromsec = { DATA_SECTIONS, NULL },
942921
.bad_tosec = { INIT_SECTIONS, NULL },
943922
.mismatch = DATA_TO_ANY_INIT,
944-
.symbol_white_list = {
945-
"*_template", "*_timer", "*_sht", "*_ops",
946-
"*_probe", "*_probe_one", "*_console", NULL
947-
},
948923
},
949924
{
950925
.fromsec = { TEXT_SECTIONS, NULL },
@@ -955,7 +930,6 @@ static const struct sectioncheck sectioncheck[] = {
955930
.fromsec = { DATA_SECTIONS, NULL },
956931
.bad_tosec = { ALL_EXIT_SECTIONS, NULL },
957932
.mismatch = DATA_TO_ANY_EXIT,
958-
.symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
959933
},
960934
/* Do not reference init code/data from meminit code/data */
961935
{
@@ -1051,15 +1025,6 @@ static const struct sectioncheck *section_mismatch(
10511025
* fromsec = .data*
10521026
* atsym = __param_ops_*
10531027
*
1054-
* Pattern 2:
1055-
* Many drivers utilise a *driver container with references to
1056-
* add, remove, probe functions etc.
1057-
* the pattern is identified by:
1058-
* tosec = init or exit section
1059-
* fromsec = data section
1060-
* atsym = *driver, *_template, *_sht, *_ops, *_probe,
1061-
* *probe_one, *_console, *_timer
1062-
*
10631028
* Pattern 3:
10641029
* Whitelist all references from .head.text to any init section
10651030
*
@@ -1108,10 +1073,22 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
11081073
strstarts(fromsym, "__param_ops_"))
11091074
return 0;
11101075

1111-
/* Check for pattern 2 */
1112-
if (match(tosec, init_exit_sections) &&
1113-
match(fromsec, data_sections) &&
1114-
match(fromsym, mismatch->symbol_white_list))
1076+
/* symbols in data sections that may refer to any init/exit sections */
1077+
if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
1078+
match(tosec, PATTERNS(ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
1079+
match(fromsym, PATTERNS("*_template", // scsi uses *_template a lot
1080+
"*_timer", // arm uses ops structures named _timer a lot
1081+
"*_sht", // scsi also used *_sht to some extent
1082+
"*_ops",
1083+
"*_probe",
1084+
"*_probe_one",
1085+
"*_console")))
1086+
return 0;
1087+
1088+
/* symbols in data sections that may refer to meminit/exit sections */
1089+
if (match(fromsec, PATTERNS(DATA_SECTIONS)) &&
1090+
match(tosec, PATTERNS(ALL_XXXINIT_SECTIONS, ALL_EXIT_SECTIONS)) &&
1091+
match(fromsym, PATTERNS("*driver")))
11151092
return 0;
11161093

11171094
/* Check for pattern 3 */

0 commit comments

Comments
 (0)