[2/3] Don't use virtual destructor in addrmap

Message ID 20240227-obstac-alloc-v1-2-bd079aad35cd@adacore.com
State New
Headers
Series Make allocate_on_obstack a bit safer |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom Tromey Feb. 27, 2024, 9:42 p.m. UTC
  The addrmap polymorphism is sort of "phony" in that there isn't really
code in the tree that can be presented with either type.  I haven't
tried to fix this (though perhaps I may); but meanwhile it's handy for
the next patch if addrmap_fixed has a trivial destructor.  This patch
achieves this by making the addrmap destructor non-virtual, and also
making it protected so that objects of any of these types cannot be
destroyed when only the base class is known.
---
 gdb/addrmap.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Alexandra Petlanova Hajkova Feb. 28, 2024, 3:16 p.m. UTC | #1
On Tue, Feb 27, 2024 at 10:43 PM Tom Tromey <tromey@adacore.com> wrote:

> The addrmap polymorphism is sort of "phony" in that there isn't really
> code in the tree that can be presented with either type.  I haven't
> tried to fix this (though perhaps I may); but meanwhile it's handy for
> the next patch if addrmap_fixed has a trivial destructor.  This patch
> achieves this by making the addrmap destructor non-virtual, and also
> making it protected so that objects of any of these types cannot be
> destroyed when only the base class is known.
> ---
>
I think it's a reasonable change and I can confirm this change does not
introduce any regressions on aarch64 with Fedora Rawhide.
  

Patch

diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index ba83607ad8c..0d61046cebd 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -44,8 +44,6 @@  using addrmap_foreach_const_fn
 /* The base class for addrmaps.  */
 struct addrmap
 {
-  virtual ~addrmap () = default;
-
   /* Return the object associated with ADDR in MAP.  */
   const void *find (CORE_ADDR addr) const
   { return this->do_find (addr); }
@@ -68,6 +66,9 @@  struct addrmap
   { return this->do_foreach (fn); }
 
 
+protected:
+  ~addrmap () = default;
+
 private:
   /* Worker for find, implemented by sub-classes.  */
   virtual void *do_find (CORE_ADDR addr) const = 0;