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 19/46] kbuild: include symbol names in section mismatch warnings
Date: Tue, 21 Mar 2006 17:20:55 +0100 [thread overview]
Message-ID: <1142958055125-git-send-email-sam@ravnborg.org> (raw)
In-Reply-To: <11429580551265-git-send-email-sam@ravnborg.org>
Try to look up the symbol that is referenced. Include the symbol
name in the warning message.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
scripts/mod/modpost.c | 64 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 47 insertions(+), 17 deletions(-)
93684d3b8062d1cebdeaed398ec6d1f354cb41a9
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index eeaf574..844f84b 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -451,6 +451,29 @@ static char *get_modinfo(void *modinfo,
return NULL;
}
+/**
+ * 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.
+ * In other cases the symbol needs to be looked up in the symbol table
+ * based on section and address.
+ * **/
+static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf_Addr addr,
+ Elf_Sym *relsym)
+{
+ Elf_Sym *sym;
+
+ if (relsym->st_name != 0)
+ return relsym;
+ for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
+ if (sym->st_shndx != relsym->st_shndx)
+ continue;
+ if (sym->st_value == addr)
+ return sym;
+ }
+ return NULL;
+}
+
/*
* Find symbols before or equal addr and after addr - in the section sec
**/
@@ -499,8 +522,9 @@ static void find_symbols_between(struct
static void warn_sec_mismatch(const char *modname, const char *fromsec,
struct elf_info *elf, Elf_Sym *sym, Elf_Rela r)
{
- Elf_Sym *before;
- Elf_Sym *after;
+ const char *refsymname = "";
+ Elf_Sym *before, *after;
+ Elf_Sym *refsym;
Elf_Ehdr *hdr = elf->hdr;
Elf_Shdr *sechdrs = elf->sechdrs;
const char *secstrings = (void *)hdr +
@@ -509,29 +533,34 @@ static void warn_sec_mismatch(const char
find_symbols_between(elf, r.r_offset, fromsec, &before, &after);
+ refsym = find_elf_symbol(elf, r.r_addend, sym);
+ if (refsym && strlen(elf->strtab + refsym->st_name))
+ refsymname = elf->strtab + refsym->st_name;
+
if (before && after) {
- warn("%s - Section mismatch: reference to %s from %s "
- "between '%s' (at offset 0x%lx) and '%s'\n",
- modname, secname, fromsec,
+ warn("%s - Section mismatch: reference to %s:%s from %s "
+ "between '%s' (at offset 0x%llx) and '%s'\n",
+ modname, secname, refsymname, fromsec,
elf->strtab + before->st_name,
- (long)(r.r_offset - before->st_value),
+ (long long)r.r_offset,
elf->strtab + after->st_name);
} else if (before) {
- warn("%s - Section mismatch: reference to %s from %s "
- "after '%s' (at offset 0x%lx)\n",
- modname, secname, fromsec,
+ warn("%s - Section mismatch: reference to %s:%s from %s "
+ "after '%s' (at offset 0x%llx)\n",
+ modname, secname, refsymname, fromsec,
elf->strtab + before->st_name,
- (long)(r.r_offset - before->st_value));
+ (long long)r.r_offset);
} else if (after) {
- warn("%s - Section mismatch: reference to %s from %s "
- "before '%s' (at offset -0x%lx)\n",
- modname, secname, fromsec,
+ warn("%s - Section mismatch: reference to %s:%s from %s "
+ "before '%s' (at offset -0x%llx)\n",
+ modname, secname, refsymname, fromsec,
elf->strtab + before->st_name,
- (long)(before->st_value - r.r_offset));
+ (long long)r.r_offset);
} else {
- warn("%s - Section mismatch: reference to %s from %s "
- "(offset 0x%lx)\n",
- modname, secname, fromsec, (long)r.r_offset);
+ warn("%s - Section mismatch: reference to %s:%s from %s "
+ "(offset 0x%llx)\n",
+ modname, secname, fromsec, refsymname,
+ (long long)r.r_offset);
}
}
@@ -575,6 +604,7 @@ static void check_sec_ref(struct module
const char *secname;
r.r_offset = TO_NATIVE(rela->r_offset);
r.r_info = TO_NATIVE(rela->r_info);
+ r.r_addend = TO_NATIVE(rela->r_addend);
sym = elf->symtab_start + ELF_R_SYM(r.r_info);
/* Skip special sections */
if (sym->st_shndx >= SHN_LORESERVE)
--
1.0.GIT
next prev parent reply other threads:[~2006-03-21 16:24 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-21 16:17 [GIT PATCH] kbuild updates Sam Ravnborg
2006-03-21 16:20 ` [PATCH 01/46] kbuild: support building individual files for external modules Sam Ravnborg
2006-03-21 16:20 ` [PATCH 02/46] kbuild: use warn()/fatal() consistent in modpost Sam Ravnborg
2006-03-21 16:20 ` [PATCH 03/46] kbuild: apply CodingStyle to modpost.c Sam Ravnborg
2006-03-21 16:20 ` [PATCH 04/46] kbuild: improved modversioning support for external modules Sam Ravnborg
2006-03-21 16:20 ` [PATCH 05/46] kbuild: warn about duplicate exported symbols Sam Ravnborg
2006-03-21 16:20 ` [PATCH 06/46] x86: align per-cpu section to configured cache bytes Sam Ravnborg
2006-03-21 16:20 ` [PATCH 07/46] kbuild: Accept various mips sub-types in SUBARCH Sam Ravnborg
2006-03-21 16:20 ` [PATCH 08/46] kbuild: avoid stale modules in $(MODVERDIR) for external modules Sam Ravnborg
2006-03-21 16:20 ` [PATCH 09/46] kbuild: run depmod when installing " Sam Ravnborg
2006-03-21 16:20 ` [PATCH 10/46] kbuild: check for section mismatch during modpost stage Sam Ravnborg
2006-03-21 16:20 ` [PATCH 11/46] kbuild: make cc-version available in kbuild files Sam Ravnborg
2006-03-21 16:20 ` [PATCH 12/46] kbuild: consolidate command line escaping Sam Ravnborg
2006-03-21 16:20 ` [PATCH 13/46] kbuild: fix mkmakefile Sam Ravnborg
2006-03-21 16:20 ` [PATCH 14/46] kbuild: remove a tab from an empty line Sam Ravnborg
2006-03-21 16:20 ` [PATCH 15/46] kbuild: remove checkconfig.pl Sam Ravnborg
2006-03-21 16:20 ` [PATCH 16/46] kbuild: fix comment in Kbuild.include Sam Ravnborg
2006-03-21 16:20 ` [PATCH 17/46] kbuild: do not segfault in modpost if MODVERDIR is not defined Sam Ravnborg
2006-03-21 16:20 ` [PATCH 18/46] kbuild: fix segfault in modpost Sam Ravnborg
2006-03-21 16:20 ` Sam Ravnborg [this message]
2006-03-21 16:20 ` [PATCH 20/46] kbuild: fix a cscope bug (make cscope segfaults) 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=1142958055125-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