From: Sam Ravnborg <sam@ravnborg.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Sam Ravnborg <sam@mars.ravnborg.org>, Sam Ravnborg <sam@ravnborg.org>
Subject: [PATCH 26/46] kbuild: whitelist false section mismatch warnings
Date: Tue, 21 Mar 2006 17:20:56 +0100 [thread overview]
Message-ID: <11429580563456-git-send-email-sam@ravnborg.org> (raw)
In-Reply-To: <11429580561151-git-send-email-sam@ravnborg.org>
In several cases the section mismatch check triggered false warnings.
Following patch introduce a whitelist to 'false positives' are not warned of.
Two types of patterns are recognised:
1) Typical case when a module parameter is _initdata
2) When a function pointer is assigned to a driver structure
In both patterns we rely on the actual name of the variable assigned
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
scripts/mod/modpost.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 89 insertions(+), 0 deletions(-)
4c8fbca5836aaafd165aa8732d92ab5d4f3a6841
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index de0a9ee..663b1ef 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -452,6 +452,89 @@ static char *get_modinfo(void *modinfo,
}
/**
+ * Test if string s ends in string sub
+ * return 0 if match
+ **/
+static int strrcmp(const char *s, const char *sub)
+{
+ int slen, sublen;
+
+ if (!s || !sub)
+ return 1;
+
+ slen = strlen(s);
+ sublen = strlen(sub);
+
+ if ((slen == 0) || (sublen == 0))
+ return 1;
+
+ if (sublen > slen)
+ return 1;
+
+ return memcmp(s + slen - sublen, sub, sublen);
+}
+
+/**
+ * Whitelist to allow certain references to pass with no warning.
+ * Pattern 1:
+ * If a module parameter is declared __initdata and permissions=0
+ * then this is legal despite the warning generated.
+ * We cannot see value of permissions here, so just ignore
+ * this pattern.
+ * The pattern is identified by:
+ * tosec = .init.data
+ * fromsec = .data
+ * atsym =__param*
+ *
+ * Pattern 2:
+ * Many drivers utilise a *_driver container with references to
+ * add, remove, probe functions etc.
+ * These functions may often be marked __init and we do not want to
+ * warn here.
+ * the pattern is identified by:
+ * tosec = .init.text | .exit.text
+ * fromsec = .data
+ * atsym = *_driver, *_ops, *_probe, *probe_one
+ **/
+static int secref_whitelist(const char *tosec, const char *fromsec,
+ const char *atsym)
+{
+ int f1 = 1, f2 = 1;
+ const char **s;
+ const char *pat2sym[] = {
+ "_driver",
+ "_ops",
+ "_probe",
+ "_probe_one",
+ NULL
+ };
+
+ /* Check for pattern 1 */
+ if (strcmp(tosec, ".init.data") != 0)
+ f1 = 0;
+ if (strcmp(fromsec, ".data") != 0)
+ f1 = 0;
+ if (strncmp(atsym, "__param", strlen("__param")) != 0)
+ f1 = 0;
+
+ if (f1)
+ return f1;
+
+ /* Check for pattern 2 */
+ if ((strcmp(tosec, ".init.text") != 0) &&
+ (strcmp(tosec, ".exit.text") != 0))
+ f2 = 0;
+ if (strcmp(fromsec, ".data") != 0)
+ f2 = 0;
+
+ for (s = pat2sym; *s; s++)
+ if (strrcmp(atsym, *s) == 0)
+ f1 = 1;
+
+ return f1 && f2;
+}
+
+/**
* Find symbol based on relocation record info.
* In some cases the symbol supplied is a valid symbol so
* return refsym. If st_name != 0 we assume this is a valid symbol.
@@ -518,6 +601,7 @@ static void find_symbols_between(struct
/**
* Print a warning about a section mismatch.
* Try to find symbols near it so user can find it.
+ * Check whitelist before warning - it may be a false positive.
**/
static void warn_sec_mismatch(const char *modname, const char *fromsec,
struct elf_info *elf, Elf_Sym *sym, Elf_Rela r)
@@ -536,6 +620,11 @@ static void warn_sec_mismatch(const char
refsym = find_elf_symbol(elf, r.r_addend, sym);
if (refsym && strlen(elf->strtab + refsym->st_name))
refsymname = elf->strtab + refsym->st_name;
+
+ /* check whitelist - we may ignore it */
+ if (before &&
+ secref_whitelist(secname, fromsec, elf->strtab + before->st_name))
+ return;
if (before && after) {
warn("%s - Section mismatch: reference to %s:%s from %s "
--
1.0.GIT
next prev parent reply other threads:[~2006-03-21 16:24 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <11429580554104-git-send-email-sam@ravnborg.org>
2006-03-21 16:20 ` [PATCH 22/46] kbuild: do not warn when unwind sections references .init/.exit sections Sam Ravnborg
2006-03-21 16:20 ` [PATCH 23/46] kbuild: version.h should depend on .kernelrelease Sam Ravnborg
2006-03-21 16:20 ` [PATCH 24/46] kbuild: Add copyright to modpost.c Sam Ravnborg
2006-03-21 16:20 ` [PATCH 25/46] kbuild: ignore all generated files for make allmodconfig (x86_64) Sam Ravnborg
2006-03-21 16:20 ` Sam Ravnborg [this message]
2006-03-21 16:20 ` [PATCH 27/46] kbuild: make namespace.pl CROSS_COMPILE happy Sam Ravnborg
2006-03-21 16:20 ` [PATCH 28/46] kbuild: small update of allnoconfig description Sam Ravnborg
2006-03-21 16:20 ` [PATCH 29/46] kbuild: kill trailing whitespace in modpost & friends Sam Ravnborg
2006-03-21 16:20 ` [PATCH 30/46] kbuild: kill false positives from section mismatch warnings for powerpc Sam Ravnborg
2006-03-21 16:20 ` [PATCH 31/46] kbuild: fix section mismatch check for unwind on IA64 Sam Ravnborg
2006-03-21 16:20 ` [PATCH 32/46] kbuild: in the section mismatch check try harder to find symbols Sam Ravnborg
2006-03-21 16:20 ` [PATCH 33/46] kbuild: fix make dir/file.xx when asm symlink is missing Sam Ravnborg
2006-03-21 16:20 ` [PATCH 34/46] kbuild: when warning symbols exported twice now tell user this is the problem Sam Ravnborg
2006-03-21 16:20 ` [PATCH 35/46] kbuild: change kbuild to not rely on incorrect GNU make behavior Sam Ravnborg
2006-03-21 16:20 ` [PATCH 36/46] kbuild: Fix bug in crc symbol generating of kernel and modules Sam Ravnborg
2006-03-21 16:20 ` [PATCH 37/46] kbuild: replace PHONY with FORCE Sam Ravnborg
2006-03-21 16:20 ` [PATCH 38/46] kbuild: in makefile.txt note that Makefile is preferred name for kbuild files Sam Ravnborg
2006-03-21 16:20 ` [PATCH 39/46] kbuild: fix genksyms build error Sam Ravnborg
2006-03-21 16:20 ` [PATCH 40/46] kbuild: Lindent genksyms.c Sam Ravnborg
2006-03-21 16:20 ` [PATCH 41/46] kbuild: clean-up genksyms Sam Ravnborg
2006-03-21 16:20 ` [PATCH 42/46] kbuild: add -fverbose-asm to i386 Makefile Sam Ravnborg
2006-03-21 16:20 ` [PATCH 43/46] Kconfig: remove the CONFIG_CC_ALIGN_* options Sam Ravnborg
2006-03-21 16:20 ` [PATCH 44/46] kconfig: fix time ordering of writes to .kconfig.d and include/linux/autoconf.h Sam Ravnborg
2006-03-21 16:20 ` [PATCH 45/46] kbuild: fix make help & make *pkg Sam Ravnborg
2006-03-21 16:20 ` [PATCH 46/46] kbuild: remove obsoleted scripts/reference_* files Sam Ravnborg
2006-03-21 17:28 ` [PATCH 35/46] kbuild: change kbuild to not rely on incorrect GNU make behavior Jan-Benedict Glaw
2006-03-21 17:37 ` Paul D. Smith
2006-03-21 17:53 ` Sam Ravnborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11429580563456-git-send-email-sam@ravnborg.org \
--to=sam@ravnborg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sam@mars.ravnborg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox