public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] debugedit: Skip relocations with missing symbol/section offset.
@ 2021-07-01 10:05 Mark Wielaard
  2021-07-01 20:12 ` Tom Stellard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2021-07-01 10:05 UTC (permalink / raw)
  To: debugedit; +Cc: Tom Stellard, Mark Wielaard

We tried to handle relocations that didn't have a symbol associated
with any section.  The would cause a message like: "Unhandled
relocation 1 in .debug_info section".  Which wasn't that helpful
either. So skip relocations without an associated symbol section index
and improve the error message a little.

    * debugedit.c (setup_relbuf): Continue when sym.st_shndx == 0.
    Add relocation index to error message.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tools/debugedit.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/debugedit.c b/tools/debugedit.c
index c6975b2..d0c6371 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -561,10 +561,11 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
 	continue;
       /* Only consider relocations against .debug_str, .debug_line,
 	 .debug_line_str, and .debug_abbrev.  */
-      if (sym.st_shndx != debug_sections[DEBUG_STR].sec
-	  && sym.st_shndx != debug_sections[DEBUG_LINE].sec
-	  && sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec
-	  && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec)
+      if (sym.st_shndx == 0 ||
+	  (sym.st_shndx != debug_sections[DEBUG_STR].sec
+	   && sym.st_shndx != debug_sections[DEBUG_LINE].sec
+	   && sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec
+	   && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec))
 	continue;
       rela.r_addend += sym.st_value;
       rtype = ELF64_R_TYPE (rela.r_info);
@@ -625,8 +626,8 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
 #endif
 	default:
 	fail:
-	  error (1, 0, "%s: Unhandled relocation %d in %s section",
-		 dso->filename, rtype, sec->name);
+	  error (1, 0, "%s: Unhandled relocation %d at [%d] for %s section",
+		 dso->filename, rtype, ndx, sec->name);
 	}
       relend->ptr = sec->data
 	+ (rela.r_offset - base);
-- 
2.32.0


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

* Re: [PATCH] debugedit: Skip relocations with missing symbol/section offset.
  2021-07-01 10:05 [PATCH] debugedit: Skip relocations with missing symbol/section offset Mark Wielaard
@ 2021-07-01 20:12 ` Tom Stellard
  2021-07-05 14:38   ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Stellard @ 2021-07-01 20:12 UTC (permalink / raw)
  To: Mark Wielaard, debugedit

On 7/1/21 3:05 AM, Mark Wielaard wrote:
> We tried to handle relocations that didn't have a symbol associated
> with any section.  The would cause a message like: "Unhandled
> relocation 1 in .debug_info section".  Which wasn't that helpful
> either. So skip relocations without an associated symbol section index
> and improve the error message a little.
> 
>      * debugedit.c (setup_relbuf): Continue when sym.st_shndx == 0.
>      Add relocation index to error message.
> 

I tested this and can confirm that it fixes my issue with the
Fedora kernel builds with clang and LTO.

-Tom

> Signed-off-by: Mark Wielaard <mark@klomp.org>
> ---
>   tools/debugedit.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/debugedit.c b/tools/debugedit.c
> index c6975b2..d0c6371 100644
> --- a/tools/debugedit.c
> +++ b/tools/debugedit.c
> @@ -561,10 +561,11 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
>   	continue;
>         /* Only consider relocations against .debug_str, .debug_line,
>   	 .debug_line_str, and .debug_abbrev.  */
> -      if (sym.st_shndx != debug_sections[DEBUG_STR].sec
> -	  && sym.st_shndx != debug_sections[DEBUG_LINE].sec
> -	  && sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec
> -	  && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec)
> +      if (sym.st_shndx == 0 ||
> +	  (sym.st_shndx != debug_sections[DEBUG_STR].sec
> +	   && sym.st_shndx != debug_sections[DEBUG_LINE].sec
> +	   && sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec
> +	   && sym.st_shndx != debug_sections[DEBUG_ABBREV].sec))
>   	continue;
>         rela.r_addend += sym.st_value;
>         rtype = ELF64_R_TYPE (rela.r_info);
> @@ -625,8 +626,8 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
>   #endif
>   	default:
>   	fail:
> -	  error (1, 0, "%s: Unhandled relocation %d in %s section",
> -		 dso->filename, rtype, sec->name);
> +	  error (1, 0, "%s: Unhandled relocation %d at [%d] for %s section",
> +		 dso->filename, rtype, ndx, sec->name);
>   	}
>         relend->ptr = sec->data
>   	+ (rela.r_offset - base);
> 


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

* Re: [PATCH] debugedit: Skip relocations with missing symbol/section offset.
  2021-07-01 20:12 ` Tom Stellard
@ 2021-07-05 14:38   ` Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2021-07-05 14:38 UTC (permalink / raw)
  To: Tom Stellard, debugedit

Hi Tom,

On Thu, 2021-07-01 at 13:12 -0700, Tom Stellard wrote:
> On 7/1/21 3:05 AM, Mark Wielaard wrote:
> > We tried to handle relocations that didn't have a symbol associated
> > with any section.  The would cause a message like: "Unhandled
> > relocation 1 in .debug_info section".  Which wasn't that helpful
> > either. So skip relocations without an associated symbol section
> > index
> > and improve the error message a little.
> > 
> >      * debugedit.c (setup_relbuf): Continue when sym.st_shndx == 0.
> >      Add relocation index to error message.
> > 
> 
> I tested this and can confirm that it fixes my issue with the
> Fedora kernel builds with clang and LTO.

Thanks for testing, pushed to main.

Note that although debugedit now silently ignores these noop
relocations they do still produce useless/broken DWARF.

Cheers,

Mark

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

end of thread, other threads:[~2021-07-05 14:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 10:05 [PATCH] debugedit: Skip relocations with missing symbol/section offset Mark Wielaard
2021-07-01 20:12 ` Tom Stellard
2021-07-05 14:38   ` Mark Wielaard

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 read-only IMAP folder(s) and NNTP newsgroup(s).