7

After I loaded linux kernel module with

user@c4:$ insmod mmaptest.ko

I can verify that it is loaded via

user@c4:$ cat /proc/modules 
mmaptest 12727 0 - Live 0x0000000000000000 (OF)

but all segments are listed with 0x00 addresses.

user@c4$:$ systool -vm mmaptest
  Module = "mmaptest"

  Attributes:
    coresize            = "12727"
    initsize            = "0"
    initstate           = "live"
    refcnt              = "0"
    srcversion          = "EABEF6F90BEAAD0D15B576A"
    taint               = "OF"
    uevent              = <store method only>

  Parameters:
    count               = "0"

  Sections:
    .bss                = "0x0000000000000000"
    .data               = "0x0000000000000000"
    .exit.text          = "0x0000000000000000"
    .gnu.linkonce.this_module= "0x0000000000000000"
    .init.text          = "0x0000000000000000"
    .note.gnu.build-id  = "0x0000000000000000"
    .rodata             = "0x0000000000000000"
    .rodata.str1.1      = "0x0000000000000000"
    .rodata.str1.8      = "0x0000000000000000"
    .smp_locks          = "0x0000000000000000"
    .strtab             = "0x0000000000000000"
    .symtab             = "0x0000000000000000"
    .text               = "0x0000000000000000"
    __mcount_loc        = "0x0000000000000000"
    __param             = "0x0000000000000000"

Thus when I try to load symbols from module text segment at incorrect (?) addresses I get:

(gdb) add-symbol-file /home/mmaptest/mmaptest.ko 0x00
add symbol table from file "/home/mmaptest/mmaptest.ko" at
    .text_addr = 0x0
(y or n) y
Reading symbols from /home/mmaptest/mmaptest.ko...(**no debugging symbols found**)...done.

Is this the case about module itself or loading into kernel code? Why all addresses are 0x000000000000?

4pie0
  • 29,204
  • 9
  • 82
  • 118

1 Answers1

13

My flags were incorrect. Debugging symbol table is built with this makefile:

obj-m += mmaptest.o
MY_CFLAGS += -g -DDEBUG
ccflags-y += ${MY_CFLAGS}
CC += ${MY_CFLAGS}


all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

debug:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 
        EXTRA_CFLAGS="$(MY_CFLAGS)"
clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 

This can be verified now with:

peter@c4:$ readelf -S mmaptest.ko | grep debug

  [24] .debug_info       PROGBITS         0000000000000000  00000d40
  [25] .rela.debug_info  RELA             0000000000000000  00018260
  [26] .debug_abbrev     PROGBITS         0000000000000000  0000d577
  [27] .debug_loc        PROGBITS         0000000000000000  0000dd54
  [28] .rela.debug_loc   RELA             0000000000000000  00029510
  [29] .debug_aranges    PROGBITS         0000000000000000  0000e5d5
  [30] .rela.debug_arang RELA             0000000000000000  0002a3e0
  [31] .debug_ranges     PROGBITS         0000000000000000  0000e645
  [32] .rela.debug_range RELA             0000000000000000  0002a458
  [33] .debug_line       PROGBITS         0000000000000000  0000e815
  [34] .rela.debug_line  RELA             0000000000000000  0002a878
  [35] .debug_str        PROGBITS         0000000000000000  0000f4cd
  [38] .debug_frame      PROGBITS         0000000000000000  00016e80
  [39] .rela.debug_frame RELA             0000000000000000  0002a8c0



add symbol table from file "/home/peter/projects/svn/linux_kernel/mmaptest/mmaptest.ko"
at .text_addr = 0x0
(y or n) y
Reading symbols from /home/peter/projects/svn/linux_kernel/mmaptest/mmaptest.ko...done.
(gdb) 
4pie0
  • 29,204
  • 9
  • 82
  • 118
  • but why all addresses are still 0x000000000000? – 4pie0 Feb 03 '15 at 13:11
  • If the section will appear in the memory image of a process then the address member will give the address at which the section's first byte should reside. Otherwise, the member will contain 0's. you can follow the link for more info http://www.skyfree.org/linux/references/ELF_Format.pdf – Sridhar Nagarajan Feb 03 '15 at 15:02
  • @Sridhar sure, it is .o file (.ko) thus addresses are relative, given by the offset. Thank you for a nice introduction to the 7f454c46 anyway. – 4pie0 Feb 03 '15 at 17:52
  • But i still can't see my symbols. When i do "whatis mysym_1", i get the type as int but when i do "p mysym_1", i get an error - cannot access memory at 0x0. what might be the problem? – DTdev Dec 29 '15 at 07:01
  • 2
    Why did you had to add `CC += ${MY_CFLAGS}` after having added `ccflags-y += ${MY_CFLAGS}`?? – AjB Jul 08 '19 at 08:23
  • I cannot tell you all the details now, but what really matters is -g -DDEBUG flags added to compiler flags. – 4pie0 Jul 11 '19 at 18:46