Linux内核的符号有两个地址?

huangapple go评论49阅读模式
英文:

Linux kernel's symbol has two addresses?

问题

发现内核符号在调试核心转储进程的一些问题时具有2个地址。

(gdb) info line binfmt_elf.c:2385
"fs/binfmt_elf.c"的第2385行从地址0xffff00000830dd84 <elf_core_dump+3460>开始,结束于0xffff00000830dd88 <elf_core_dump+3464>。
"fs/binfmt_elf.c"的第2385行从地址0xffff00000831083c <elf_core_dump+3460>开始,结束于0xffff000008310840 <elf_core_dump+3464>。

(gdb) info line binfmt_elf.c:2345
"fs/binfmt_elf.c"的第2345行从地址0xffff0000083106b8 <elf_core_dump+3072>开始,结束于0xffff0000083106c0 <elf_core_dump+3080>。
"fs/binfmt_elf.c"的第2345行从地址0xffff00000830dbfc <elf_core_dump+3068>开始,结束于0xffff00000830dc04 <elf_core_dump+3076>。

nm 告诉相同的结果:

nm vmlinux | grep elf_core_dump
ffff00000830d000 t elf_core_dump
ffff00000830fab8 t elf_core_dump

平台信息:aarch64,内核(4.20)由我自己构建,配置从 alpine virt aarch64 复制而来。

为什么?

英文:

Found out kernel symbol has 2 address when debuging some problem of coredump process.

    (gdb) info line binfmt_elf.c:2385
    Line 2385 of &quot;fs/binfmt_elf.c&quot; starts at address 0xffff00000830dd84 &lt;elf_core_dump+3460&gt; and ends at 0xffff00000830dd88 &lt;elf_core_dump+3464&gt;.
    Line 2385 of &quot;fs/binfmt_elf.c&quot; starts at address 0xffff00000831083c &lt;elf_core_dump+3460&gt; and ends at 0xffff000008310840 &lt;elf_core_dump+3464&gt;.
    (gdb) info line binfmt_elf.c:2345
    Line 2345 of &quot;fs/binfmt_elf.c&quot; starts at address 0xffff0000083106b8 &lt;elf_core_dump+3072&gt; and ends at 0xffff0000083106c0 &lt;elf_core_dump+3080&gt;.
    Line 2345 of &quot;fs/binfmt_elf.c&quot; starts at address 0xffff00000830dbfc &lt;elf_core_dump+3068&gt; and ends at 0xffff00000830dc04 &lt;elf_core_dump+3076&gt;.

nm tell the same result:

    nm vmlinux | grep elf_core_dump
    ffff00000830d000 t elf_core_dump
    ffff00000830fab8 t elf_core_dump

plat infomation:aarch64,kernel(4.20) was build by my self,config was copied from alpine virt aarch64

why?

答案1

得分: 2

The function elf_core_dump is a static one, so it can be defined in the several source files.

As for funny output of gdb, in which the line

Line 2385 of "fs/binfmt_elf.c"

appears twice, then it is because the source file fs/binfmt_elf.c is included into other source file, fs/compat_binfmt_elf.c by using

/*
 * We share all the actual code with the native (64-bit) version.
 */
#include "binfmt_elf.c"

(https://elixir.bootlin.com/linux/v4.20.17/source/fs/compat_binfmt_elf.c#L131).

So every function in the binfmt_elf.c is actually defined twice in the resulted kernel image:

  • the first definition is created when compile the file binfmt_elf.c
  • the second definition is created when compile the file compat_binfmt_elf.c.
英文:

The function elf_core_dump is a static one, so it can be defined in the several source files.

As for funny output of gdb, in which the line

Line 2385 of &quot;fs/binfmt_elf.c&quot;

appears twice, then it is because the source file fs/binfmt_elf.c is included into other source file, fs/compat_binfmt_elf.c by using

/*
 * We share all the actual code with the native (64-bit) version.
 */
#include &quot;binfmt_elf.c&quot;

(https://elixir.bootlin.com/linux/v4.20.17/source/fs/compat_binfmt_elf.c#L131).

So every function in the binfmt_elf.c is actually defined twice in the resulted kernel image:

  • the first definition is created when compile the file binfmt_elf.c
  • the second definition is created when compile the file compat_binfmt_elf.c.

huangapple
  • 本文由 发表于 2023年6月29日 16:18:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76579249.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定