Skip to content

Commit

Permalink
symbols: skip load .init.* sections if module was successfully initia…
Browse files Browse the repository at this point in the history
…lized

There might be address overlap of one modules .init.text symbols and
another modules .text symbols. As a result, gdb fails to translate the
address to symbol name correctly:

  crash> sym -m virtio_blk | grep MODULE
  ffffffffc00a4000 MODULE START: virtio_blk
  ffffffffc00a86ec MODULE END: virtio_blk
  crash> gdb info address floppy_module_init
  Symbol "floppy_module_init" is a function at address 0xffffffffc00a4131.

Since the .init.* sections of a module had been freed by kernel if the
module was initialized successfully, there is no need to load the .init.*
sections data from "*.ko.debug" in gdb to create such an overlap.
lm->mod_init_module_ptr is used as a flag of whether module is freed.

Without the patch:
  crash> mod -S
  crash> struct blk_mq_ops 0xffffffffc00a7160
  struct blk_mq_ops {
    queue_rq = 0xffffffffc00a45b0 <floppy_module_init+1151>, <-- translated from module floppy
    map_queue = 0xffffffff813015c0 <blk_mq_map_queue>,
    ...snip...
    complete = 0xffffffffc00a4370 <floppy_module_init+575>,
    init_request = 0xffffffffc00a4260 <floppy_module_init+303>,
    ...snip...
  }

With the patch:
  crash> mod -S
  crash> struct blk_mq_ops 0xffffffffc00a7160
  struct blk_mq_ops {
    queue_rq = 0xffffffffc00a45b0 <virtio_queue_rq>, <-- translated from module virtio_blk
    map_queue = 0xffffffff813015c0 <blk_mq_map_queue>,
    ...snip...
    complete = 0xffffffffc00a4370 <virtblk_request_done>,
    init_request = 0xffffffffc00a4260 <virtblk_init_request>,
    ...snip...
  }

Signed-off-by: Tao Liu <[email protected]>
  • Loading branch information
liutgnu committed Nov 30, 2023
1 parent fbac40c commit 5c5a7f3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -13295,7 +13295,7 @@ add_symbol_file_kallsyms(struct load_module *lm, struct gnu_request *req)
shift_string_right(req->buf, strlen(buf));
BCOPY(buf, req->buf, strlen(buf));
retval = TRUE;
} else {
} else if (lm->mod_init_module_ptr || !STRNEQ(section_name, ".init.")) {
sprintf(buf, " -s %s 0x%lx", section_name, section_vaddr);
while ((len + strlen(buf)) >= buflen) {
RESIZEBUF(req->buf, buflen, buflen * 2);
Expand Down

0 comments on commit 5c5a7f3

Please sign in to comment.