Skip to content

Commit 47490ec

Browse files
drinkcatrustyrussell
authored andcommitted
modpost: Add flag -E for making section mismatches fatal
The section mismatch warning can be easy to miss during the kernel build process. Allow it to be marked as fatal to be easily caught and prevent bugs from slipping in. Setting CONFIG_SECTION_MISMATCH_WARN_ONLY=y causes these warnings to be non-fatal, since there are a number of section mismatches when using allmodconfig on some architectures, and we do not want to break these builds by default. Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Change-Id: Ic346706e3297c9f0d790e3552aa94e5cff9897a6 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 74b22c4 commit 47490ec

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

‎lib/Kconfig.debug‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ config DEBUG_SECTION_MISMATCH
311311
- Enable verbose reporting from modpost in order to help resolve
312312
the section mismatches that are reported.
313313

314+
config SECTION_MISMATCH_WARN_ONLY
315+
bool "Make section mismatch errors non-fatal"
316+
default y
317+
help
318+
If you say N here, the build process will fail if there are any
319+
section mismatch, instead of just throwing warnings.
320+
321+
If unsure, say Y.
322+
314323
#
315324
# Select this config option from the architecture Kconfig, if it
316325
# is preferred to always offer frame pointers as a config

‎scripts/Makefile.modpost‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ modpost = scripts/mod/modpost \
7777
$(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \
7878
$(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
7979
$(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
80+
$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
8081
$(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
8182

8283
MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS)))

‎scripts/mod/modpost.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static int warn_unresolved = 0;
3838
/* How a symbol is exported */
3939
static int sec_mismatch_count = 0;
4040
static int sec_mismatch_verbose = 1;
41+
static int sec_mismatch_fatal = 0;
4142
/* ignore missing files */
4243
static int ignore_missing_files;
4344

@@ -2385,7 +2386,7 @@ int main(int argc, char **argv)
23852386
struct ext_sym_list *extsym_iter;
23862387
struct ext_sym_list *extsym_start = NULL;
23872388

2388-
while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:")) != -1) {
2389+
while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
23892390
switch (opt) {
23902391
case 'i':
23912392
kernel_read = optarg;
@@ -2426,6 +2427,9 @@ int main(int argc, char **argv)
24262427
case 'w':
24272428
warn_unresolved = 1;
24282429
break;
2430+
case 'E':
2431+
sec_mismatch_fatal = 1;
2432+
break;
24292433
default:
24302434
exit(1);
24312435
}
@@ -2475,14 +2479,20 @@ int main(int argc, char **argv)
24752479
sprintf(fname, "%s.mod.c", mod->name);
24762480
write_if_changed(&buf, fname);
24772481
}
2478-
24792482
if (dump_write)
24802483
write_dump(dump_write);
2481-
if (sec_mismatch_count && !sec_mismatch_verbose)
2482-
warn("modpost: Found %d section mismatch(es).\n"
2483-
"To see full details build your kernel with:\n"
2484-
"'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n",
2485-
sec_mismatch_count);
2484+
if (sec_mismatch_count) {
2485+
if (!sec_mismatch_verbose) {
2486+
warn("modpost: Found %d section mismatch(es).\n"
2487+
"To see full details build your kernel with:\n"
2488+
"'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n",
2489+
sec_mismatch_count);
2490+
}
2491+
if (sec_mismatch_fatal) {
2492+
fatal("modpost: Section mismatches detected.\n"
2493+
"Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
2494+
}
2495+
}
24862496

24872497
return err;
24882498
}

0 commit comments

Comments
 (0)