public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: Pedro Alves <pedro@palves.net>
Cc: Tom Tromey <tromey@adacore.com>,  gdb-patches@sourceware.org
Subject: Re: [PATCH 0/4] Minor cleanups in coff-pe-read.c
Date: Fri, 22 Apr 2022 09:19:57 -0600	[thread overview]
Message-ID: <87mtgdqh5u.fsf@tromey.com> (raw)
In-Reply-To: <ef11fa5e-0221-8792-8827-6733fe7abcf5@palves.net> (Pedro Alves's message of "Fri, 22 Apr 2022 15:55:59 +0100")

Pedro> The series looks fine to me, but now I'm curious on what you mean
Pedro> by "reuse minimal symbols without re-reading".

Minimal symbols are normally stored on the per-BFD object.  So, a savvy
symbol reader can simply reuse them without doing any additional work.
For less savvy symbol readers, the minimal_symbol_reader object itself
knows how to do this -- it simply discards symbols when they are being
re-read.  Only elfread.c was ever converted to do this sharing the best
way:

  /* If we already have minsyms, then we can skip some work here.
     However, if there were stabs or mdebug sections, we go ahead and
     redo all the work anyway, because the psym readers for those
     kinds of debuginfo need extra information found here.  This can
     go away once all types of symbols are in the per-BFD object.  */
  if (objfile->per_bfd->minsyms_read
      && ei->stabsect == NULL
      && ei->mdebugsect == NULL
      && ei->ctfsect == NULL)
    {
      if (symtab_create_debug)
	gdb_printf (gdb_stdlog,
		    "... minimal symbols previously read\n");
      return;
    }

The problem for other readers is that they tend not to be "pure", in the
sense that they mix minimal symbol reading with other kinds of
reading -- and the other kinds may not be shared or even shareable.

That's why the elfread.c change has so many conditions.  For coffread.c,
coff_symfile_read may create full symbols, and it wasn't immediately
obvious to me that this could easily be skipped for PE.

Making everything be shared would be great.  Then we could hoist this
check into generic code and re-using a BFD would be simple.  However,
this is the objfile splitting project, which I've attempted and failed
at several times now.  (It's still a good project but it needs a
strategy other than one giant patch series.)


Now that I look at this again, though, maybe it's easier than I thought.

  if ((nsyms == 0) && (pe_file))
    {
      /* We've got no debugging symbols, but it's a portable
	 executable, so try to read the export table.  */
      read_pe_exported_syms (reader, objfile);
    }

Maybe this can be checked earlier.  I'll look at it more.  I had thought
that coff_symtab_read installing minsyms would be a problem, but that
seems to happen in a loop that's checking nsyms.


The symbol readers are all headache-inducing.  For example just glancing
at coffread.c makes me think there are memory leaks:

		sym->type ()->set_name (xstrdup (sym->linkage_name ()));

... type names must be allocated on an obstack.  Here there's probably
just no need to copy at all.  No idea how to test this though.

They also tend to be a mess of global variables and other bad practices.

Tom

      reply	other threads:[~2022-04-22 15:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 13:56 Tom Tromey
2022-04-22 13:56 ` [PATCH 1/4] Simplify BFD section iteration " Tom Tromey
2022-04-22 13:56 ` [PATCH 2/4] Remove a const-removing cast from coff-pe-read.c Tom Tromey
2022-04-22 13:56 ` [PATCH 3/4] Use std::string in coff-pe-read.c Tom Tromey
2022-04-22 13:56 ` [PATCH 4/4] More const use and alloca avoidance " Tom Tromey
2022-04-22 14:55 ` [PATCH 0/4] Minor cleanups " Pedro Alves
2022-04-22 15:19   ` Tom Tromey [this message]

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=87mtgdqh5u.fsf@tromey.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).