Skip to contentSkip to conversation

2.6.7: kallsyms --all-symbols shows a shift in the symbol addreses

PATCH Xavier Bru 3 participants 3 messages Jun 21, 2004

lore
Share & tools
lore

Xavier Bru

author
#0 lore raw

Hi all!

There is a problem with the all kallsyms support in 2.6.7 scripts/kallsyms.c.
Building the table reserves the adresses for all the kernel symbols in first step, then generates the effective addresses of the symbols in step 2. The problem is that the symbols used to build the symbol table are not taken in account for the size calculation, but are included in the table in step 2.
This makes the table "bigger" than was allocated, and the symbols that come behind are shifted.
This makes kallsyms (and KDB) give wrong addresses for these symbols.

One solution is to exclude from the symbol table the symbols used for building it (As was provided in KDB patch :-)

scripts/kallsyms.c Mon Jun 21 15:26:57 2004 renamed from scripts/kallsyms.c Wed Jun 16 07:20:26 2004 +6 -0
@@ -74,6 +74,12 @@ symbol_valid(struct sym_entry *s)
 
     if (strstr(s->sym, "_compiled."))
         return 0;
+    if (!strcmp(s->sym, "kallsyms_addresses"))
+        return 0;
+    if (!strcmp(s->sym, "kallsyms_num_syms"))
+        return 0;
+    if (!strcmp(s->sym, "kallsyms_names"))
+        return 0;
 
     return 1;
 }

herafter the traces of the problem:
----------------------------------

$ grep numnode System.map
a000000100930740 G numnodes
# grep kallsyms_addresses /proc/kallsyms
a000000100894470 d kallsyms_addresses
# grep numnodes  /proc/kallsyms
a000000100930700 d numnodes

Entering kdb (current=0xa000000100724000, pid 0) on processor 0 due to Keyboard Entry
[0]kdb> md numnodes

0xa000000100930700 00000000 00000000 00008000 00000000   ................
0xa000000100930710 00799470 a0000001 5f757063 00007075   p.y.... cpu_up..
0xa000000100930720 00799628 a0000001 00000000 00000000   (.y.... ........
0xa000000100930730 00000003 0000000a 000015de 00000000   ........Þ.......
0xa000000100930740 00000004 00000000 00001feb 00001860   ........ë...`...
                   XXXXXXXX here it is !!!!
0xa000000100930750 00000100 00000000 0000000a 00000028   ............(...
0xa000000100930760 000001f4 00000bb8 00000002 0000003c   ô...¸.......<...
0xa000000100930770 00000000 00000032 00010000 00000eb8   ....2.......¸...

[0]kdb>

With the fix:
------------

$ grep numnodes System.map
a000000100930700 G numnodes
# grep kallsyms_addresses /proc/kallsyms
# grep numnodes  /proc/kallsyms
a000000100930700 d numnodes

Entering kdb (current=0xa000000100724000, pid 0) on processor 0 due to Keyboard Entry
[0]kdb> md numnodes
0xa000000100930700 00000004 00000000 00001feb 0000181f ........ë.......
XXXXXXXX OK
0xa000000100930710 00000100 00000000 0000000a 00000028 ............(...
0xa000000100930720 000001f4 00000bb8 00000002 0000003c ô...¸.......<...

Signature · 8 lines
 Sincères salutations.
_____________________________________________________________________
 
Xavier BRU                 BULL ISD/R&D/INTEL office:     FREC B1-422
tel : +33 (0)4 76 29 77 45                    http://www-frec.bull.fr
fax : +33 (0)4 76 29 77 70                 mailto:[email protected]
addr: BULL, 1 rue de Provence, BP 208, 38432 Echirolles Cedex, FRANCE
_____________________________________________________________________
#1 lore raw

Re: 2.6.7: kallsyms --all-symbols shows a shift in the symbol

On Mon, 21 Jun 2004 18:19:56 +0200 Xavier Bru wrote:

| Hi all!
| 
| There is a problem with the all kallsyms support in 2.6.7 
| scripts/kallsyms.c.
| Building the table reserves the adresses for all the kernel symbols in 
| first step, then generates the effective addresses of the symbols in step 2.
| The problem is that the symbols used to build the symbol table are not 
| taken in account for the size calculation, but are included in the table 
| in step 2.
| This makes the table "bigger" than was allocated, and the symbols that 
| come behind are shifted.
| This makes kallsyms (and KDB) give wrong addresses for these symbols.
| 
| One solution is to exclude from the symbol table the symbols used for 
| building it (As was provided in KDB patch :-)

Is this the same problem that Keith Owens made a patch for against 2.6.7-rc3 on 2004-june-15?
Subject: [patch 2.6.7-rc3] When two kallsyms passes are not enough

http://marc.theaimsgroup.com/?l=linux-kernel&m8728234402407&w=2

--
~Randy

#2 lore raw
In reply to Xavier Bru
Quoted 11 lines · Randy.Dunlap

On Mon, 21 Jun 2004 18:19:56 +0200 Xavier Bru wrote:

| There is a problem with the all kallsyms support in 2.6.7 
| scripts/kallsyms.c.
| One solution is to exclude from the symbol table the symbols used for 
| building it (As was provided in KDB patch :-)

Is this the same problem that Keith Owens made a patch for against 2.6.7-rc3 on 2004-june-15?
Subject: [patch 2.6.7-rc3] When two kallsyms passes are not enough

http://marc.theaimsgroup.com/?l=linux-kernel&m8728234402407&w=2

Yes. That patch has been refined and sent to Andrew Morton, it should be in 2.6.8-*. The critical fix is -

Index: 2.6.7-kallsyms/scripts/kallsyms.c
=================================--- 2.6.7-kallsyms.orig/scripts/kallsyms.c 2004-06-20 20:12:08.000000000 +1000
+++ 2.6.7-kallsyms/scripts/kallsyms.c 2004-06-20 23:38:46.000000000 +1000
@@ -72,7 +72,15 @@ symbol_valid(struct sym_entry *s)
return 0;
}

- if (strstr(s->sym, "_compiled."))
+ /* Exclude symbols which vary between passes. Passes 1 and 2 must have
+ * identical symbol lists. The kallsyms_* symbols below are only added
+ * after pass 1, they would be included in pass 2 when --all-symbols is
+ * specified so exclude them to get a stable symbol list.
+ */
+ if (strstr(s->sym, "_compiled.") ||

+	    strcmp(s->sym, "kallsyms_addresses") = 0 || 
+	    strcmp(s->sym, "kallsyms_num_syms") = 0 || 
+	    strcmp(s->sym, "kallsyms_names") = 0)

return 0;

return 1;