Search code examples
linuxkernelsymbols

Linux kernel's symbol has two addresses?


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

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

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?


Solution

  • 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.