[2/2] Avoid infinite recursion in get_msymbol_address

Message ID 20200403165838.9255-3-tromey@adacore.com
State New
Headers show
Series
  • Avoid infinite recursion in get_msymbol_address
Related show

Commit Message

Tom Tromey April 3, 2020, 4:58 p.m.
Sometimes, get_msymbol_address can cause infinite recursion, leading
to a crash.  This was reported previously here:

https://sourceware.org/pipermail/gdb-patches/2019-November/162154.html

A user on irc reported this as well, and with his help and the help of
a friend of his, we found that the problem occurred because, when
reloading a separate debug objfile, the objfile would lose the
OBJF_MAINLINE flag.  This would cause some symbols from this separate
debug objfile to be marked "maybe_copied" -- but then
get_msymbol_address could find the same symbol and fail as reported.

This patch fixes the bug by preserving OBJF_MAINLINE.

No test case, unfortunately, because I could not successfully make
one.

gdb/ChangeLog
2020-04-03  Tom Tromey  <tromey@adacore.com>

	* symfile.c (symbol_file_add_separate): Preserve OBJF_MAINLINE.
---
 gdb/ChangeLog | 4 ++++
 gdb/symfile.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

-- 
2.21.1

Comments

Joel Brobecker May 17, 2020, 4:39 p.m. | #1
Hello,

Just a quick message to let everyone know that I pushed this patch
to gdb-9-branch. For that, I created PR symtab/26003.

The patch was re-tested on x86_64-linux in gdb-9-branch prior to pushing.

On Fri, Apr 03, 2020 at 10:58:38AM -0600, Tom Tromey wrote:
> Sometimes, get_msymbol_address can cause infinite recursion, leading

> to a crash.  This was reported previously here:

> 

> https://sourceware.org/pipermail/gdb-patches/2019-November/162154.html

> 

> A user on irc reported this as well, and with his help and the help of

> a friend of his, we found that the problem occurred because, when

> reloading a separate debug objfile, the objfile would lose the

> OBJF_MAINLINE flag.  This would cause some symbols from this separate

> debug objfile to be marked "maybe_copied" -- but then

> get_msymbol_address could find the same symbol and fail as reported.

> 

> This patch fixes the bug by preserving OBJF_MAINLINE.

> 

> No test case, unfortunately, because I could not successfully make

> one.

> 

> gdb/ChangeLog

> 2020-04-03  Tom Tromey  <tromey@adacore.com>

> 

> 	* symfile.c (symbol_file_add_separate): Preserve OBJF_MAINLINE.

> ---

>  gdb/ChangeLog | 4 ++++

>  gdb/symfile.c | 2 +-

>  2 files changed, 5 insertions(+), 1 deletion(-)

> 

> diff --git a/gdb/symfile.c b/gdb/symfile.c

> index bd27a1fefef..61053298a89 100644

> --- a/gdb/symfile.c

> +++ b/gdb/symfile.c

> @@ -1163,7 +1163,7 @@ symbol_file_add_separate (bfd *bfd, const char *name,

>    symbol_file_add_with_addrs

>      (bfd, name, symfile_flags, &sap,

>       objfile->flags & (OBJF_REORDERED | OBJF_SHARED | OBJF_READNOW

> -		       | OBJF_USERLOADED),

> +		       | OBJF_USERLOADED | OBJF_MAINLINE),

>       objfile);

>  }

>  

> -- 

> 2.21.1


-- 
Joel

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index bd27a1fefef..61053298a89 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1163,7 +1163,7 @@  symbol_file_add_separate (bfd *bfd, const char *name,
   symbol_file_add_with_addrs
     (bfd, name, symfile_flags, &sap,
      objfile->flags & (OBJF_REORDERED | OBJF_SHARED | OBJF_READNOW
-		       | OBJF_USERLOADED),
+		       | OBJF_USERLOADED | OBJF_MAINLINE),
      objfile);
 }