Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts/gdb: fix lx-symbols command for arm64 LLVM

lx-symbols assumes that module's .text sections is located at
`module->mem[MOD_TEXT].base` and passes it to add-symbol-file command.
However, .text section follows after .plt section in modules built by LLVM
toolchain for arm64 target. Symbol addresses are skewed in GDB.

Fix this issue by using the address of .text section stored in
`module->sect_attrs`.

Link: https://lkml.kernel.org/r/20230801121052.2475183-1-koudai@google.com
Signed-off-by: Koudai Iwahori <koudai@google.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Kieran Bingham <kbingham@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Koudai Iwahori and committed by
Andrew Morton
1677bf76 29665c1e

+10 -7
+10 -7
scripts/gdb/linux/symbols.py
··· 89 89 return name 90 90 return None 91 91 92 - def _section_arguments(self, module): 92 + def _section_arguments(self, module, module_addr): 93 93 try: 94 94 sect_attrs = module['sect_attrs'].dereference() 95 95 except gdb.error: 96 - return "" 96 + return str(module_addr) 97 + 97 98 attrs = sect_attrs['attrs'] 98 99 section_name_to_address = { 99 100 attrs[n]['battr']['attr']['name'].string(): attrs[n]['address'] 100 101 for n in range(int(sect_attrs['nsections']))} 102 + 103 + textaddr = section_name_to_address.get(".text", module_addr) 101 104 args = [] 102 105 for section_name in [".data", ".data..read_mostly", ".rodata", ".bss", 103 - ".text", ".text.hot", ".text.unlikely"]: 106 + ".text.hot", ".text.unlikely"]: 104 107 address = section_name_to_address.get(section_name) 105 108 if address: 106 109 args.append(" -s {name} {addr}".format( 107 110 name=section_name, addr=str(address))) 108 - return "".join(args) 111 + return "{textaddr} {sections}".format( 112 + textaddr=textaddr, sections="".join(args)) 109 113 110 114 def load_module_symbols(self, module): 111 115 module_name = module['name'].string() ··· 129 125 module_addr = hex(int(module_addr, 0) + plt_offset + plt_size) 130 126 gdb.write("loading @{addr}: {filename}\n".format( 131 127 addr=module_addr, filename=module_file)) 132 - cmdline = "add-symbol-file {filename} {addr}{sections}".format( 128 + cmdline = "add-symbol-file {filename} {sections}".format( 133 129 filename=module_file, 134 - addr=module_addr, 135 - sections=self._section_arguments(module)) 130 + sections=self._section_arguments(module, module_addr)) 136 131 gdb.execute(cmdline, to_string=True) 137 132 if module_name not in self.loaded_modules: 138 133 self.loaded_modules.append(module_name)