From: Sam Ravnborg <sam@ravnborg.org>
To: linux-kernel@vger.kernel.org
Cc: Atsushi Nemoto <anemo@mba.ocn.ne.jp>, Sam Ravnborg <sam@ravnborg.org>
Subject: [PATCH 11/33] kbuild: make better section mismatch reports on i386 and mips
Date: Tue, 17 Jul 2007 16:08:40 +0200 [thread overview]
Message-ID: <11846813432231-git-send-email-sam@ravnborg.org> (raw)
In-Reply-To: <1184681343297-git-send-email-sam@ravnborg.org>
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
On i386 and MIPS, warn_sec_mismatch() sometimes fails to show
usefull symbol name. This is because empty 'refsym' due to 0 r_addend
value. This patch is to adjust r_addend value, consulting with
apply_relocate() routine in kernel code.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---
scripts/mod/modpost.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
scripts/mod/modpost.h | 3 ++
2 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 3645e98..b83cddb 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -374,6 +374,7 @@ static int parse_elf(struct elf_info *info, const char *filename)
hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
hdr->e_machine = TO_NATIVE(hdr->e_machine);
+ hdr->e_type = TO_NATIVE(hdr->e_type);
sechdrs = (void *)hdr + hdr->e_shoff;
info->sechdrs = sechdrs;
@@ -384,6 +385,8 @@ static int parse_elf(struct elf_info *info, const char *filename)
sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size);
sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link);
sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
+ sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info);
+ sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr);
}
/* Find symbol table. */
for (i = 1; i < hdr->e_shnum; i++) {
@@ -753,6 +756,8 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf_Addr addr,
for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
if (sym->st_shndx != relsym->st_shndx)
continue;
+ if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
+ continue;
if (sym->st_value == addr)
return sym;
}
@@ -895,6 +900,58 @@ static void warn_sec_mismatch(const char *modname, const char *fromsec,
}
}
+static unsigned int *reloc_location(struct elf_info *elf,
+ int rsection, Elf_Rela *r)
+{
+ Elf_Shdr *sechdrs = elf->sechdrs;
+ int section = sechdrs[rsection].sh_info;
+
+ return (void *)elf->hdr + sechdrs[section].sh_offset +
+ (r->r_offset - sechdrs[section].sh_addr);
+}
+
+static int addend_386_rel(struct elf_info *elf, int rsection, Elf_Rela *r)
+{
+ unsigned int r_typ = ELF_R_TYPE(r->r_info);
+ unsigned int *location = reloc_location(elf, rsection, r);
+
+ switch (r_typ) {
+ case R_386_32:
+ r->r_addend = TO_NATIVE(*location);
+ break;
+ case R_386_PC32:
+ r->r_addend = TO_NATIVE(*location) + 4;
+ /* For CONFIG_RELOCATABLE=y */
+ if (elf->hdr->e_type == ET_EXEC)
+ r->r_addend += r->r_offset;
+ break;
+ }
+ return 0;
+}
+
+static int addend_mips_rel(struct elf_info *elf, int rsection, Elf_Rela *r)
+{
+ unsigned int r_typ = ELF_R_TYPE(r->r_info);
+ unsigned int *location = reloc_location(elf, rsection, r);
+ unsigned int inst;
+
+ if (r_typ == R_MIPS_HI16)
+ return 1; /* skip this */
+ inst = TO_NATIVE(*location);
+ switch (r_typ) {
+ case R_MIPS_LO16:
+ r->r_addend = inst & 0xffff;
+ break;
+ case R_MIPS_26:
+ r->r_addend = (inst & 0x03ffffff) << 2;
+ break;
+ case R_MIPS_32:
+ r->r_addend = inst;
+ break;
+ }
+ return 0;
+}
+
/**
* A module includes a number of sections that are discarded
* either when loaded or when used as built-in.
@@ -938,8 +995,11 @@ static void check_sec_ref(struct module *mod, const char *modname,
r.r_offset = TO_NATIVE(rela->r_offset);
#if KERNEL_ELFCLASS == ELFCLASS64
if (hdr->e_machine == EM_MIPS) {
+ unsigned int r_typ;
r_sym = ELF64_MIPS_R_SYM(rela->r_info);
r_sym = TO_NATIVE(r_sym);
+ r_typ = ELF64_MIPS_R_TYPE(rela->r_info);
+ r.r_info = ELF64_R_INFO(r_sym, r_typ);
} else {
r.r_info = TO_NATIVE(rela->r_info);
r_sym = ELF_R_SYM(r.r_info);
@@ -972,8 +1032,11 @@ static void check_sec_ref(struct module *mod, const char *modname,
r.r_offset = TO_NATIVE(rel->r_offset);
#if KERNEL_ELFCLASS == ELFCLASS64
if (hdr->e_machine == EM_MIPS) {
+ unsigned int r_typ;
r_sym = ELF64_MIPS_R_SYM(rel->r_info);
r_sym = TO_NATIVE(r_sym);
+ r_typ = ELF64_MIPS_R_TYPE(rel->r_info);
+ r.r_info = ELF64_R_INFO(r_sym, r_typ);
} else {
r.r_info = TO_NATIVE(rel->r_info);
r_sym = ELF_R_SYM(r.r_info);
@@ -983,6 +1046,16 @@ static void check_sec_ref(struct module *mod, const char *modname,
r_sym = ELF_R_SYM(r.r_info);
#endif
r.r_addend = 0;
+ switch (hdr->e_machine) {
+ case EM_386:
+ if (addend_386_rel(elf, i, &r))
+ continue;
+ break;
+ case EM_MIPS:
+ if (addend_mips_rel(elf, i, &r))
+ continue;
+ break;
+ }
sym = elf->symtab_start + r_sym;
/* Skip special sections */
if (sym->st_shndx >= SHN_LORESERVE)
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 0858caa..4156dd3 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -60,6 +60,9 @@ typedef union
#define ELF64_MIPS_R_SYM(i) \
((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym)
+#define ELF64_MIPS_R_TYPE(i) \
+ ((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1)
+
#if KERNEL_ELFDATA != HOST_ELFDATA
static inline void __endian(const void *src, void *dest, unsigned int size)
--
1.5.0.6
next prev parent reply other threads:[~2007-07-17 14:18 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-17 14:08 [PATCH 01/33] kbuild: asm-offsets.h is now cleaned with O=.. builds Sam Ravnborg
2007-07-17 14:08 ` [PATCH 02/33] kbuild: New 'cc-fullversion' macro Sam Ravnborg
2007-07-17 14:08 ` [PATCH 03/33] powerpc: Refuse to build 64-bit with GCC-4.2.0 and CONFIG_MODULES Sam Ravnborg
2007-07-17 14:08 ` [PATCH 04/33] kbuild: document cc-fullversion Sam Ravnborg
2007-07-17 14:08 ` [PATCH 05/33] kbuild: avoid environment to set variables used by kbuild Sam Ravnborg
[not found] ` <11846813432072-git-send-email-sam@ravnborg.org>
2007-07-17 14:08 ` [PATCH 07/33] kconfig: use POSIX equality test in check-lxdialog.sh Sam Ravnborg
2007-07-17 14:08 ` [PATCH 08/33] kbuild: add support for reading stdin with gen_init_cpio Sam Ravnborg
2007-07-17 14:08 ` [PATCH 09/33] kbuild: add support for squashing uid/gid in gen_initramfs_list.sh Sam Ravnborg
2007-07-17 14:08 ` [PATCH 10/33] kconfig: fix update-po-config Sam Ravnborg
2007-07-17 14:08 ` Sam Ravnborg [this message]
2007-07-17 14:08 ` [PATCH 12/33] kbuild: make better section mismatch reports on arm Sam Ravnborg
2007-07-17 14:08 ` [PATCH 13/33] kbuild: suppress modpost warnings for references from the .toc section as used by powerpc Sam Ravnborg
2007-07-17 14:08 ` [PATCH 14/33] kbuild: .paravirtprobe section is obsolete, so modpost doesn't need to handle it Sam Ravnborg
2007-07-17 14:08 ` [PATCH 15/33] kbuild: ignore section mismatch warnings originating from .note section Sam Ravnborg
2007-07-17 14:08 ` [PATCH 16/33] kbuild: refactor code in modpost to improve maintainability Sam Ravnborg
2007-07-17 14:08 ` [PATCH 17/33] kbuild: consolidate section checks Sam Ravnborg
2007-07-17 14:08 ` [PATCH 18/33] kbuild: warn about references from .init.text to .exit.text Sam Ravnborg
2007-07-17 14:08 ` [PATCH 19/33] kbuild: remove hardcoded apic_es7000 from modpost Sam Ravnborg
2007-07-17 14:08 ` [PATCH 20/33] kbuild: remove hardcoded _logo names " Sam Ravnborg
2007-07-17 14:08 ` [PATCH 21/33] kbuild: whitelist references from variables named _timer to .init.text Sam Ravnborg
2007-07-17 14:08 ` [PATCH 22/33] kbuild: do section mismatch check on full vmlinux Sam Ravnborg
2007-07-17 14:08 ` [PATCH 23/33] modpost white list pattern adjustment Sam Ravnborg
2007-07-17 14:08 ` [PATCH 24/33] Whitelist references from __dbe_table to .init Sam Ravnborg
2007-07-17 14:08 ` [PATCH 25/33] kbuild: use POSIX BRE in headers install target Sam Ravnborg
2007-07-17 14:08 ` [PATCH 26/33] kconfig: strip 'CONFIG_' automatically in kernel configuration search Sam Ravnborg
[not found] ` <11846813443988-git-send-email-sam@ravnborg.org>
2007-07-17 14:08 ` [PATCH 28/33] kconfig: reset generated values only if Kconfig and .config agree Sam Ravnborg
2007-07-17 14:08 ` [PATCH 29/33] kbuild: use -fno-optimize-sibling-calls unconditionally Sam Ravnborg
2007-07-17 14:08 ` [PATCH 30/33] kallsyms: remove usage of memmem and _GNU_SOURCE from scripts/kallsyms.c Sam Ravnborg
2007-07-17 14:09 ` [PATCH 31/33] cris: use DATA_DATA in cris Sam Ravnborg
2007-07-17 14:09 ` [PATCH 32/33] powerpc: add missing DATA_DATA to powerpc Sam Ravnborg
2007-07-17 14:09 ` [PATCH 33/33] xtensa: use DATA_DATA in xtensa Sam Ravnborg
2007-07-21 8:22 ` [PATCH 25/33] kbuild: use POSIX BRE in headers install target Oleg Verych
2007-07-21 8:23 ` Andreas Schwab
2007-07-21 8:39 ` Jan Engelhardt
2007-07-21 9:03 ` Andreas Schwab
2007-07-21 9:43 ` Oleg Verych
2007-07-21 8:27 ` [kbuild-devel] " Mike Frysinger
2007-07-21 10:04 ` Oleg Verych
2007-07-21 19:21 ` Mike Frysinger
2007-07-21 20:39 ` Sam Ravnborg
2007-07-21 22:03 ` Mike Frysinger
2007-07-21 22:11 ` Sam Ravnborg
2007-07-21 22:12 ` Mike Frysinger
2007-07-21 22:15 ` Robert P. J. Day
2007-07-21 22:16 ` More effective processing (Re: [PATCH 25/33] kbuild: use POSIX BRE in headers install target) Oleg Verych
2007-07-21 22:13 ` Sam Ravnborg
2007-07-21 22:39 ` Oleg Verych
2007-07-21 22:15 ` Mike Frysinger
2007-07-18 10:03 ` [PATCH 03/33] powerpc: Refuse to build 64-bit with GCC-4.2.0 and CONFIG_MODULES Clemens Koller
2007-07-19 15:55 ` Segher Boessenkool
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=11846813432231-git-send-email-sam@ravnborg.org \
--to=sam@ravnborg.org \
--cc=anemo@mba.ocn.ne.jp \
--cc=linux-kernel@vger.kernel.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