From 5cfb203a304deaaa8c7c5368722b214d24583137 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sat, 8 Aug 2015 15:16:20 +0930 Subject: modpost: abort if a module symbol is too long Module symbols have a limited length, but currently the build system allows the build finishing even if the driver code contains a too long symbol name, which eventually overflows the modversion_info[] item. The compiler may catch at compiling *.mod.c like CC xxx.mod.o xxx.mod.c:18:16: warning: initializer-string for array of chars is too long but it's merely a warning. This patch adds the check of the symbol length in modpost and stops the build properly. Currently MODULE_NAME_LEN is defined in modpost.c instead of referring to the definition in kernel header because including linux/module.h is messy and we must cover cross-compilation. Signed-off-by: Takashi Iwai Signed-off-by: Rusty Russell --- scripts/mod/modpost.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 12d3db3bd46b..d583c98fde31 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2133,6 +2133,11 @@ static void add_staging_flag(struct buffer *b, const char *name) buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); } +/* In kernel, this size is defined in linux/module.h; + * here we use Elf_Addr instead of long for covering cross-compile + */ +#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr)) + /** * Record CRCs for unresolved symbols **/ @@ -2177,6 +2182,12 @@ static int add_versions(struct buffer *b, struct module *mod) s->name, mod->name); continue; } + if (strlen(s->name) >= MODULE_NAME_LEN) { + merror("too long symbol \"%s\" [%s.ko]\n", + s->name, mod->name); + err = 1; + break; + } buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n", s->crc, s->name); } -- cgit v1.2.3 From 47490ec141b9944a8a7cbe3bec8b8f4fdaaa700b Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Tue, 6 Oct 2015 09:44:42 +1030 Subject: 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 Change-Id: Ic346706e3297c9f0d790e3552aa94e5cff9897a6 Signed-off-by: Rusty Russell --- lib/Kconfig.debug | 9 +++++++++ scripts/Makefile.modpost | 1 + scripts/mod/modpost.c | 24 +++++++++++++++++------- 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'scripts/mod') diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index e2894b23efb6..ebe51a34cf48 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -311,6 +311,15 @@ config DEBUG_SECTION_MISMATCH - Enable verbose reporting from modpost in order to help resolve the section mismatches that are reported. +config SECTION_MISMATCH_WARN_ONLY + bool "Make section mismatch errors non-fatal" + default y + help + If you say N here, the build process will fail if there are any + section mismatch, instead of just throwing warnings. + + If unsure, say Y. + # # Select this config option from the architecture Kconfig, if it # is preferred to always offer frame pointers as a config diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 69f0a1417e9a..1366a94b6c39 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -77,6 +77,7 @@ modpost = scripts/mod/modpost \ $(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ + $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS))) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index d583c98fde31..b2ae8afc1ab1 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -38,6 +38,7 @@ static int warn_unresolved = 0; /* How a symbol is exported */ static int sec_mismatch_count = 0; static int sec_mismatch_verbose = 1; +static int sec_mismatch_fatal = 0; /* ignore missing files */ static int ignore_missing_files; @@ -2385,7 +2386,7 @@ int main(int argc, char **argv) struct ext_sym_list *extsym_iter; struct ext_sym_list *extsym_start = NULL; - while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:")) != -1) { + while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) { switch (opt) { case 'i': kernel_read = optarg; @@ -2426,6 +2427,9 @@ int main(int argc, char **argv) case 'w': warn_unresolved = 1; break; + case 'E': + sec_mismatch_fatal = 1; + break; default: exit(1); } @@ -2475,14 +2479,20 @@ int main(int argc, char **argv) sprintf(fname, "%s.mod.c", mod->name); write_if_changed(&buf, fname); } - if (dump_write) write_dump(dump_write); - if (sec_mismatch_count && !sec_mismatch_verbose) - warn("modpost: Found %d section mismatch(es).\n" - "To see full details build your kernel with:\n" - "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", - sec_mismatch_count); + if (sec_mismatch_count) { + if (!sec_mismatch_verbose) { + warn("modpost: Found %d section mismatch(es).\n" + "To see full details build your kernel with:\n" + "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", + sec_mismatch_count); + } + if (sec_mismatch_fatal) { + fatal("modpost: Section mismatches detected.\n" + "Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n"); + } + } return err; } -- cgit v1.2.3 From d1189c63ea5e3272dc390a83e1235f142b739eb4 Mon Sep 17 00:00:00 2001 From: Noam Camus Date: Mon, 26 Oct 2015 19:51:46 +1030 Subject: scripts: [modpost] add new sections to white list In our ARC toolchain the default linker script includes special sections used for code and data located in special fast memory. To avoid warnings we add these sections i.e. .cmem* and .fmt_slot* to white list. Signed-off-by: Noam Camus Cc: Rusty Russell Cc: Quentin Casasnovas Signed-off-by: Rusty Russell --- scripts/mod/modpost.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts/mod') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index b2ae8afc1ab1..e080746e1a6b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -834,6 +834,8 @@ static const char *const section_white_list[] = ".xt.lit", /* xtensa */ ".arcextmap*", /* arc */ ".gnu.linkonce.arcext*", /* arc : modules */ + ".cmem*", /* EZchip */ + ".fmt_slot*", /* EZchip */ ".gnu.lto*", NULL }; -- cgit v1.2.3