All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masaki Kimura <masaki.kimura.kz@hitachi.com>
To: linux-kernel@vger.kernel.org
Cc: Rusty Russell <rusty@rustcorp.com.au>
Subject: [RESEND PATCH] module: Fix kallsyms to show the last symbol properly
Date: Wed, 24 Oct 2012 14:50:37 +0900	[thread overview]
Message-ID: <508781AD.80902@hitachi.com> (raw)

This patch fixes a bug that the last symbol in the .symtab section of
kernel modules is not displayed with /proc/kallsyms. This happens
because the first symbol is processed twice before and inside the loop
without incrementing "src".

This bug exists since the following commit was introduced.
   module: reduce symbol table for loaded modules (v2)
   commit: 4a4962263f07d14660849ec134ee42b63e95ea9a

This patch is tested on 3.7-rc2 kernel with the simple test module by the
below steps, to check if all the core symbols appear in /proc/kallsyms.

[Test steps]
1. Compile the test module, like below.
   (My compiler tends to put a function named with 18 charactors, 
    like zzzzzzzzzzzzzzzzzz, at the end of .symtab section. 
    I don't know why, though.)

# cat tp.c
#include <linux/module.h>
#include <linux/kernel.h>

void zzzzzzzzzzzzzzzzzz(void) {}

static int init_tp(void)
{
        return 0;
}

static void exit_tp(void) {}

module_init(init_tp);
module_exit(exit_tp);
MODULE_LICENSE("GPL");

# cat Makefile
KERNEL_RELEASE=$(shell uname -r)
BUILDDIR := /lib/modules/$(KERNEL_RELEASE)/source

obj-m := tp.o

all:
        $(MAKE) -C $(BUILDDIR) M=$(PWD) V=1 modules
clean:
        $(MAKE) -C $(BUILDDIR) M=$(PWD) V=1 clean

# make

2. Check if the target symbol, zzzzzzzzzzzzzzzzzz in this case, 
   is located at the last entry.

# readelf -s tp.ko | tail
    18: 0000000000000020    11 FUNC    LOCAL  DEFAULT    2 exit_tp
    19: 0000000000000000    12 OBJECT  LOCAL  DEFAULT    4 __mod_license15
    20: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS tp.mod.c
    21: 000000000000000c     9 OBJECT  LOCAL  DEFAULT    4 __module_depends
    22: 0000000000000015    45 OBJECT  LOCAL  DEFAULT    4 __mod_vermagic5
    23: 0000000000000000   600 OBJECT  GLOBAL DEFAULT    8 __this_module
    24: 0000000000000020    11 FUNC    GLOBAL DEFAULT    2 cleanup_module
    25: 0000000000000010    13 FUNC    GLOBAL DEFAULT    2 init_module
    26: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND mcount
    27: 0000000000000000    11 FUNC    GLOBAL DEFAULT    2 zzzzzzzzzzzzzzzzzz

3. Load the module.
# insmod tp.ko

4. Check if all the core symbols are shown /proc/kallsyms properly.

[Before my patch applied]
# grep "\[tp\]" /proc/kallsyms
ffffffffa0135010 t init_tp      [tp]
ffffffffa0135020 t exit_tp      [tp]
ffffffffa0137000 d __this_module        [tp]
ffffffffa0135020 t cleanup_module       [tp]
ffffffffa0135010 t init_module  [tp]

(The last entry, or zzzzzzzzzzzzzzzzzz, is not shown.)

[After my patch applied]
# grep "\[tp\]" /proc/kallsyms
ffffffffa0135010 t init_tp      [tp]
ffffffffa0135020 t exit_tp      [tp]
ffffffffa0137000 d __this_module        [tp]
ffffffffa0135020 t cleanup_module       [tp]
ffffffffa0135010 t init_module  [tp]
ffffffffa0135000 t zzzzzzzzzzzzzzzzzz   [tp]

(The last entry, or zzzzzzzzzzzzzzzzzz, is shown properly.)


Signed-off-by: Masaki Kimura <masaki.kimura.kz@hitachi.com>
---
 kernel/module.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/module.c b/kernel/module.c
index 6085f5e..1a48ffe 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2293,7 +2293,11 @@ static void layout_symtab(struct module *mod, struct load_info *info)
 	src = (void *)info->hdr + symsect->sh_offset;
 	nsrc = symsect->sh_size / sizeof(*src);
 
-	/* Compute total space required for the core symbols' strtab. */
+	/* 
+ 	 * Compute total space required for the core symbols' strtab.
+	 * We start searching core symbols from the second entry.
+	 */
+	src++;
 	for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
 		if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
 			strtab_size += strlen(&info->strtab[src->st_name]) + 1;
@@ -2334,6 +2338,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
 	src = mod->symtab;
 	*dst = *src;
 	*s++ = 0;
+	/* We start searching core symbols from the second entry. */
+	src++;
 	for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
 		if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum))
 			continue;
-- 
1.7.10.1

             reply	other threads:[~2012-10-24  5:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24  5:50 Masaki Kimura [this message]
2012-10-25  0:20 ` [RESEND PATCH] module: Fix kallsyms to show the last symbol properly Rusty Russell
2012-10-25  2:49   ` Re[2]:[RESEND " Masaki Kimura

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=508781AD.80902@hitachi.com \
    --to=masaki.kimura.kz@hitachi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.