linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts/gdb: fix debugging modules compiled with hot/cold partitioning
@ 2019-10-28 15:27 Ilya Leoshkevich
  2019-10-30 18:29 ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Ilya Leoshkevich @ 2019-10-28 15:27 UTC (permalink / raw)
  To: Jan Kiszka, Kieran Bingham, linux-kernel, linux-s390
  Cc: Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich

gcc's -freorder-blocks-and-partition option makes it group frequently
and infrequently used code in .text.hot and .text.unlikely sections
respectively. At least when building modules on s390, this option is
used by default.

gdb assumes that all code is located in .text section, and that .text
section is located at module load address. With such modules this is no
longer the case: there is code in .text.hot and .text.unlikely, and
either of them might precede .text.

Fix by explicitly telling gdb the addresses of code sections.

It might be tempting to do this for all sections, not only the ones in
the white list. Unfortunately, gdb appears to have an issue, when telling
it about e.g. loadable .note.gnu.build-id section causes it to think that
non-loadable .note.Linux section is loaded at address 0, which in turn
causes NULL pointers to be resolved to bogus symbols. So keep using the
white list approach for the time being.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 scripts/gdb/linux/symbols.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index 7b7c2fafbc68..be984aa29b75 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -99,7 +99,8 @@ lx-symbols command."""
             attrs[n]['name'].string(): attrs[n]['address']
             for n in range(int(sect_attrs['nsections']))}
         args = []
-        for section_name in [".data", ".data..read_mostly", ".rodata", ".bss"]:
+        for section_name in [".data", ".data..read_mostly", ".rodata", ".bss",
+                             ".text", ".text.hot", ".text.unlikely"]:
             address = section_name_to_address.get(section_name)
             if address:
                 args.append(" -s {name} {addr}".format(
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts/gdb: fix debugging modules compiled with hot/cold partitioning
  2019-10-28 15:27 [PATCH] scripts/gdb: fix debugging modules compiled with hot/cold partitioning Ilya Leoshkevich
@ 2019-10-30 18:29 ` Jan Kiszka
  2019-10-31  9:56   ` Ilya Leoshkevich
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2019-10-30 18:29 UTC (permalink / raw)
  To: Ilya Leoshkevich, Kieran Bingham, linux-kernel, linux-s390,
	Andrew Morton
  Cc: Heiko Carstens, Vasily Gorbik

On 28.10.19 16:27, Ilya Leoshkevich wrote:
> gcc's -freorder-blocks-and-partition option makes it group frequently
> and infrequently used code in .text.hot and .text.unlikely sections
> respectively. At least when building modules on s390, this option is
> used by default.
> 
> gdb assumes that all code is located in .text section, and that .text
> section is located at module load address. With such modules this is no
> longer the case: there is code in .text.hot and .text.unlikely, and
> either of them might precede .text.
> 
> Fix by explicitly telling gdb the addresses of code sections.
> 
> It might be tempting to do this for all sections, not only the ones in
> the white list. Unfortunately, gdb appears to have an issue, when telling
> it about e.g. loadable .note.gnu.build-id section causes it to think that
> non-loadable .note.Linux section is loaded at address 0, which in turn
> causes NULL pointers to be resolved to bogus symbols. So keep using the
> white list approach for the time being.

Did you report this to gdb?

> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  scripts/gdb/linux/symbols.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
> index 7b7c2fafbc68..be984aa29b75 100644
> --- a/scripts/gdb/linux/symbols.py
> +++ b/scripts/gdb/linux/symbols.py
> @@ -99,7 +99,8 @@ lx-symbols command."""
>              attrs[n]['name'].string(): attrs[n]['address']
>              for n in range(int(sect_attrs['nsections']))}
>          args = []
> -        for section_name in [".data", ".data..read_mostly", ".rodata", ".bss"]:
> +        for section_name in [".data", ".data..read_mostly", ".rodata", ".bss",
> +                             ".text", ".text.hot", ".text.unlikely"]:
>              address = section_name_to_address.get(section_name)
>              if address:
>                  args.append(" -s {name} {addr}".format(
> 

Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts/gdb: fix debugging modules compiled with hot/cold partitioning
  2019-10-30 18:29 ` Jan Kiszka
@ 2019-10-31  9:56   ` Ilya Leoshkevich
  0 siblings, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2019-10-31  9:56 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Kieran Bingham, linux-kernel, linux-s390, Andrew Morton,
	Heiko Carstens, Vasily Gorbik

> Am 30.10.2019 um 19:29 schrieb Jan Kiszka <jan.kiszka@siemens.com>:
> 
> On 28.10.19 16:27, Ilya Leoshkevich wrote:
>> gcc's -freorder-blocks-and-partition option makes it group frequently
>> and infrequently used code in .text.hot and .text.unlikely sections
>> respectively. At least when building modules on s390, this option is
>> used by default.
>> 
>> gdb assumes that all code is located in .text section, and that .text
>> section is located at module load address. With such modules this is no
>> longer the case: there is code in .text.hot and .text.unlikely, and
>> either of them might precede .text.
>> 
>> Fix by explicitly telling gdb the addresses of code sections.
>> 
>> It might be tempting to do this for all sections, not only the ones in
>> the white list. Unfortunately, gdb appears to have an issue, when telling
>> it about e.g. loadable .note.gnu.build-id section causes it to think that
>> non-loadable .note.Linux section is loaded at address 0, which in turn
>> causes NULL pointers to be resolved to bogus symbols. So keep using the
>> white list approach for the time being.
> 
> Did you report this to gdb?

Yes: https://sourceware.org/bugzilla/show_bug.cgi?id=25152

Best regards,
Ilya


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-31  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-28 15:27 [PATCH] scripts/gdb: fix debugging modules compiled with hot/cold partitioning Ilya Leoshkevich
2019-10-30 18:29 ` Jan Kiszka
2019-10-31  9:56   ` Ilya Leoshkevich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).