mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arend van Spriel <arend.vanspriel@broadcom.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: arm: global variables in kernel module not loaded correctly in gdb
Date: Tue, 16 Apr 2024 11:13:15 +0200	[thread overview]
Message-ID: <8762456c-a0b0-41dc-91ea-c0c89e99d5d1@broadcom.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 7563 bytes --]

This issue should probably be reported to GDB bugzilla, but wanted to 
put it out here as well. Maybe someone else stumbled upon this or simply 
knows what is going on. Google searches did not provide much clues nor 
searching GDB bugzilla.

So what is my issue? When I load a .ko file into GDB using 
add-symbol-file the (static) global variables do not have the correct 
memory address. When I use the .o file iso the .ko file things work as 
expected.

I created a dummy kernel module and compiled it against 6.9-rc4. I did 
have my suspicion about PLTS which is enabled in my kernel config. When 
CONFIG_ARM_MODULE_PLTS is disabled the symbol address is correct. From 
my limited understanding this involves an additional link table. AFAICT 
the BFD library which is used by GDB supports this, but can not rule out 
there is a bug in there. I rebuild GDB and added some debug print and 
also changed a debug variable which makes symbol loading a bit more verbose.

Attached are the two kernel config files and the dummy module source 
file. Any help would be appreciated.

Regards,
Arend

with CONFIG_ARM_MODULE_PLTS
---------------------------
Reading symbols from vmlinux...
(gdb) add-symbol-file dummy.ko -s .text 0xbf607000  -s .bss 0xbf6091c0
add symbol table from file "dummy.ko" at
	.text_addr = 0xbf607000
	.bss_addr = 0xbf6091c0
(y or n) y
Reading symbols from dummy.ko...
using ABFD: name=.text idx=2 addr=0 lower=0
addrs[0]: name=.text idx=2 addr=bf607000
using ABFD: name=.bss idx=19 addr=0 lower=bf607000
addrs[1]: name=.bss idx=19 addr=bf6091c0
Reading minimal symbols of objfile 
/home/av935118/sandbox/mod_dummy/dummy.ko ...
Recording minsym:  mst_file_data                        0x45    12 
__UNIQUE_ID_depends126
Recording minsym:  mst_file_data                        0x4e    12 
__UNIQUE_ID_name125
Recording minsym:  mst_file_data                        0x59    12 
__UNIQUE_ID_vermagic124
Recording minsym:  mst_file_data                         0x0     1  _note_15
Recording minsym:  mst_file_data                        0x18     1  _note_14
Recording minsym:  mst_file_data                         0x0     5  .LC0
Recording minsym:  mst_file_text                         0x0     3 
dummy_exit
Recording minsym:  mst_file_data                         0xc     5  .LC1
Recording minsym:  mst_file_data                        0x20     5  .LC2
Recording minsym:  mst_file_text                         0x0     4 
dummy_init
Recording minsym:  mst_file_bss                          0x0    19 .LANCHOR0
Recording minsym:  mst_file_bss                         *0x0*   19 
dummy_value
Recording minsym:  mst_file_data                         0x0    15 
__UNIQUE_ID___addressable_cleanup_module125
Recording minsym:  mst_file_data                         0x0    16 
__UNIQUE_ID___addressable_init_module124
Recording minsym:  mst_file_data                         0x0    12 
__UNIQUE_ID_license127
Recording minsym:  mst_file_data                         0xe    12 
__UNIQUE_ID_author126
Recording minsym:  mst_data                              0x0    17 
__this_module
Recording minsym:  mst_text                              0x0     3 
cleanup_module
Recording minsym:  mst_text                              0x0     4 
init_module
Recording minsym:  mst_text                              0x0     2 
dummy_set_value
Recording minsym:  mst_text                             0x10     2 
dummy_get_value

(gdb) add-symbol-file dummy.o -s .text 0xbf607000  -s .bss 0xbf6091c0
add symbol table from file "dummy.o" at
	.text_addr = 0xbf607000
	.bss_addr = 0xbf6091c0
(y or n) y
Reading symbols from dummy.o...
using ABFD: name=.text idx=0 addr=0 lower=0
addrs[0]: name=.text idx=0 addr=bf607000
using ABFD: name=.bss idx=2 addr=0 lower=bf607000
addrs[1]: name=.bss idx=2 addr=bf6091c0
Reading minimal symbols of objfile 
/home/av935118/sandbox/mod_dummy/dummy.o ...
Recording minsym:  mst_file_data                         0x0     3  .LC0
Recording minsym:  mst_file_text                        0x38     4 
dummy_exit
Recording minsym:  mst_file_data                         0xc     3  .LC1
Recording minsym:  mst_file_data                        0x20     3  .LC2
Recording minsym:  mst_file_text                        0x4c     7 
dummy_init
Recording minsym:  mst_file_bss                   0xbf6091c0     2 .LANCHOR0
Recording minsym:  mst_file_bss                  *0xbf6091c0*    2 
dummy_value
Recording minsym:  mst_file_data                        0xa8    12 
__UNIQUE_ID___addressable_cleanup_module125
Recording minsym:  mst_file_data                        0xac    13 
__UNIQUE_ID___addressable_init_module124
Recording minsym:  mst_file_data                        0xb0    14 
__UNIQUE_ID_license127
Recording minsym:  mst_file_data                        0xbe    14 
__UNIQUE_ID_author126
Recording minsym:  mst_text                             0x38     4 
cleanup_module
Recording minsym:  mst_text                             0x4c     7 
init_module
Recording minsym:  mst_text                       0xbf607000     0 
dummy_set_value
Recording minsym:  mst_text                       0xbf607010     0 
dummy_get_value

without CONFIG_ARM_MODULE_PLTS
------------------------------
Reading symbols from vmlinux...
(gdb) add-symbol-file ~/sandbox/mod_dummy/dummy.ko -s .text 0xbf607000 
-s .bss 0xbf6091c0
add symbol table from file "/home/av935118/sandbox/mod_dummy/dummy.ko" at
	.text_addr = 0xbf607000
	.bss_addr = 0xbf6091c0
(y or n) y
Reading symbols from /home/av935118/sandbox/mod_dummy/dummy.ko...
using ABFD: name=.text idx=2 addr=0 lower=0
addrs[0]: name=.text idx=2 addr=bf607000
using ABFD: name=.bss idx=17 addr=0 lower=bf607000
addrs[1]: name=.bss idx=17 addr=bf6091c0
Reading minimal symbols of objfile 
/home/av935118/sandbox/mod_dummy/dummy.ko ...
Recording minsym:  mst_file_data                       0x141    12 
__UNIQUE_ID_depends126
Recording minsym:  mst_file_data                       0x14a    12 
__UNIQUE_ID_name125
Recording minsym:  mst_file_data                       0x155    12 
__UNIQUE_ID_vermagic124
Recording minsym:  mst_file_data                        0x24     1  _note_15
Recording minsym:  mst_file_data                        0x3c     1  _note_14
Recording minsym:  mst_file_data                        0xa4     5  .LC0
Recording minsym:  mst_file_text                        0x54     3 
dummy_exit
Recording minsym:  mst_file_data                        0xb0     5  .LC1
Recording minsym:  mst_file_data                        0xc4     5  .LC2
Recording minsym:  mst_file_text                        0x60     4 
dummy_init
Recording minsym:  mst_file_bss                   0xbf6091c0    17 .LANCHOR0
Recording minsym:  mst_file_bss                  *0xbf6091c0*   17 
dummy_value
Recording minsym:  mst_file_data                       0x184    14 
__UNIQUE_ID___addressable_cleanup_module125
Recording minsym:  mst_file_data                       0x188    15 
__UNIQUE_ID___addressable_init_module124
Recording minsym:  mst_file_data                        0xfc    12 
__UNIQUE_ID_license127
Recording minsym:  mst_file_data                       0x10a    12 
__UNIQUE_ID_author126
Recording minsym:  mst_data                            0x1c0    16 
__this_module
Recording minsym:  mst_text                             0x54     3 
cleanup_module
Recording minsym:  mst_text                             0x60     4 
init_module
Recording minsym:  mst_text                       0xbf607000     2 
dummy_set_value
Recording minsym:  mst_text                       0xbf607010     2 
dummy_get_value

[-- Attachment #1.2: dummy.c --]
[-- Type: text/plain, Size: 538 bytes --]


#include <linux/module.h>

static int dummy_value;

void dummy_set_value(int v)
{
	dummy_value = v;
}

int dummy_get_value(void)
{
	return dummy_value;
}

static int __init dummy_init(void)
{
	pr_err("initializing..\n");
	dummy_set_value(0xdeadbeef);
	pr_err("  module_addr = %px\n", THIS_MODULE->mem[MOD_TEXT].base);
	return 0;
}

static void __exit dummy_exit(void)
{
	pr_err("leaving\n");
}

module_init(dummy_init);
module_exit(dummy_exit);

MODULE_AUTHOR("Arend van Spriel <arend.vanspriel@broadcom.com>");
MODULE_LICENSE("GPLv2");

[-- Attachment #1.3: configs.tar.gz --]
[-- Type: application/gzip, Size: 44376 bytes --]

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4219 bytes --]

             reply	other threads:[~2024-04-16  9:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16  9:13 Arend van Spriel [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-04-16  9:03 Arend van Spriel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8762456c-a0b0-41dc-91ea-c0c89e99d5d1@broadcom.com \
    --to=arend.vanspriel@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®