静态函数在ELF二进制文件中的位置

时间:2015-11-25 11:31:17

标签: gcc linux-kernel elf

我制作了一个简单的linux内核模块,它具有静态功能。当我在.ko文件上使用objdump或nm时,我看不到静态函数的条目。它去了哪里?

感谢。

编辑:添加代码

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

int p;
int q;

module_param(p, int, S_IRUGO);
module_param(q, int, S_IRUGO);

static int add(int x, int y)
{
        return x + y;
}

static int __init hello_init(void)
{
        int res;

        res = add(p, q);
        return res;
}

static void __exit hello_cleanup(void)
{
}

module_init(hello_init);
module_exit(hello_cleanup);

MODULE_VERSION("dev");
MODULE_LICENSE("Proprietary");

带有非静态函数的objdump输出:

Disassembly of section .text:

0000000000000000 <add>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   e8 00 00 00 00          callq  9 <add+0x9>
   9:   c9                      leaveq
   a:   8d 04 3e                lea    (%rsi,%rdi,1),%eax
   d:   c3                      retq
   e:   90                      nop
   f:   90                      nop

Disassembly of section .init.text:

0000000000000000 <init_module>:
   0:   55                      push   %rbp
   1:   8b 05 00 00 00 00       mov    0x0(%rip),%eax        # 7 <init_module+0x7>
   7:   03 05 00 00 00 00       add    0x0(%rip),%eax        # d <init_module+0xd>
   d:   48 89 e5                mov    %rsp,%rbp
  10:   c9                      leaveq
  11:   c3                      retq

Disassembly of section .exit.text:

0000000000000000 <cleanup_module>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   e8 00 00 00 00          callq  9 <cleanup_module+0x9>
   9:   c9                      leaveq
   a:   c3                      retq

带静态函数的objdump输出:

Disassembly of section .init.text:

0000000000000000 <init_module>:
   0:   55                      push   %rbp
   1:   8b 05 00 00 00 00       mov    0x0(%rip),%eax        # 7 <init_module+0x7>
   7:   03 05 00 00 00 00       add    0x0(%rip),%eax        # d <init_module+0xd>
   d:   48 89 e5                mov    %rsp,%rbp
  10:   c9                      leaveq
  11:   c3                      retq

Disassembly of section .exit.text:

0000000000000000 <cleanup_module>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   e8 00 00 00 00          callq  9 <cleanup_module+0x9>
   9:   c9                      leaveq
   a:   c3                      retq

0 个答案:

没有答案