Posts Tagged ‘linux kernel’

Identifying Symbols

Posted: June 24, 2008 in Tools
Tags: , , ,

These symbols are as esoteric to me as they might be for many of you. But
it’s just an image to decorate the context below!

The Symbol I am going to talk about is related to Symbols of objects. This
is a very less documented topic, so just digging about it in any search engine
didn’t help much.

I remember I had asked about it to Ramkrsna and Ashok couple of months
back who have a good knowledge about Linux System as a whole. They
helped me in some way which had given me some basic idea about it until
I found an article to read about compiling Linux kernel.

So in short, a symbol can be a variable name or function name. You an
simple try using “nm” command in an Unix system to list the symbol of any
object file.

So when you try running a simple C file it generally creates an object file called
a.out in the same directory.

If you want to name the file something else you can just try executing this

cc -o file.o file.c

The above line will create an object file with the name file.o. So to list the symbol
of these files just execute the command below:

nm file.o

It will give some output like this:
08049618 W data_start
08048360 t frame_dummy
08048384 T main
0804961c d p.5756
U printf@@GLIBC_2.0
U scanf@@GLIBC_2.0

Where the 1st column gives the address of the symbol, 2nd column gives the
type of the symbol and the 3rd tells the name of the symbol. In the last two lines
you can note that “printf” and “scanf” are being extracted from GLIBC and these
are Undefined symbols.

Kernel generally refers to a symbol by it’s address. So the kernel symbol table is
nothing but a mapping of symbol names with their addresses.

Last week I digged more about Oprofile. I had heard about it before and have gone
through some sample outputs of it but had not tried it myself!

After getting a good hand on Systemtap. I can say stap can do anything magical in
Kernel Space. So I just wanted to check the “Can be” and “Can’t be” bits of Oprofile.

In one word I can say, Oprofile is a system-wide performance monitoring tool. And
it’s capable of profiling all parts of the running system, from the kernel to shared
libraries to libraries.

Here’s a quick low down of the syntaxes to start profiling:

1: Complie and install oprofile.

Note: The minimum setup required for this is to
tell Oprofile where the vmlinux file corresponding
to the running kernel is available.

opcontrol –vmlinux=/path/to/vmlinux

[opcontrol is used to control Oprofile profiling]

If for any reason you don’t want to profile kernel. You can write:

opcontrol –no-vmlinux

2: Start the oprofiled daemon to collect profile data.

opcontrol –start

3: To stop profiling.

opcontrol –shutdown

4: Getting reports.

For systemwide data:


[opreport is used to produce symbol or binary image summaries]

or, to get more detailed summary of a particular image:

opreport -l /path/to/vmlinux

Example: To get system-wide binary image summary

Syntax: opreport –exclude-dependent


CPU: PIII, speed 1867 MHz (estimated)
Counted CPU_CLK_UNHALTED events (clocks processor is not halted) with a unit mask of 0x00 (No unit mask) count 100000
samples| %|
7101696 72.5786 vmlinux
388399 3.9694
289055 2.9541
249139 2.5462 oprofile
217805 2.2259 oprofiled
150175 1.5348
140984 1.4408
126140 1.2891
104014 1.0630
100046 1.0225 mplayer
61752 0.6311 unrar

It has been couple of busy weeks for me while I was digging more
about Linux Kernel subsystem. I went through so many tutorials,
books, on line docs — but I didn’t find any of them as interesting
as the book of Robert Love.

When I started I thought it might be very tough to get into something
as low level as Kernel. But from my college days I had made it a practise
to read the Preface of any book and it wasn’t an exception this time. 🙂

If you roll down few paragraphs you will hit one sentence of Robert
which will take away all your fear. “Developing code in the kernel does
not require genius, magic, or a bushy Unix-Hacker beard. >>> There is
much to learn – as with any big project – but there is not too much about
the kernel that is more scared or confusing than anything else”.

That kept me going on and on with the subject. Now I am no more a
kernel newbie, able to solve smaller problems, can browse through the
10 million lines of Kernel Code and can tell which data structure is
available where!