Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perf can find symbol in the kernel ,but can not find symbol in my program. How to fix it?

you may have read this question: how can i get perf to find symbols in my program

1)my question is:

when I use perf report , it gives a result like this:

    # Overhead  Command      Shared Object                    Symbol
    #   .  .  
    #
        99.59%     test  test               [.] 0x000003d4          
         0.21%     test  [kernel.kallsyms]  [k] __do_fault          
         0.10%     test  [kernel.kallsyms]  [k] run_timer_softirq   
         0.10%     test  [kernel.kallsyms]  [k] __update_cpu_load   
         0.01%     test  [kernel.kallsyms]  [k] set_task_comm       
         0.00%     test  [kernel.kallsyms]  [k] intel_pmu_enable_all

That is: the perf can find symbol in kernel but cannot find symbol in my program.

my program is here:

     void longa() 
      { 
         int i,j; 
         for(i = 0; i < 1000000; i++) 
        j=i; //am I silly or crazy? I feel boring and desperate. 
      } 


     void foo2() 
     { 
       int i; 
       for(i=0 ; i < 10; i++) 
        longa(); 
     } 

     void foo1() 
     { 
       int i; 
       for(i = 0; i< 100; i++) 
          longa(); 
     } 

    int main(void) 
     { 
       foo1(); 
       foo2(); 
     } 

2)I have compile the program like:

gcc test.c -g -o test

My env: os:ubuntu kernel:3.10.9

like image 242
yzark Avatar asked Feb 15 '23 10:02

yzark


2 Answers

Today, when I run perf test, I got a message saying vmlinux symtab matches kallsyms: Failed.

When I was looking for the reason, I found that the reason is that the value of /proc/sys/kernel/kptr_restrict is 1. When we set it to 0, we will get the symbol in our program.

like image 57
yzark Avatar answered Feb 17 '23 23:02

yzark


There are 2 possible sources of the problem:

  • Your perf tool was compiled without elfutils support.
  • Your perf tool cannot find libelf.so library on your target.
like image 43
jms Avatar answered Feb 17 '23 22:02

jms