From 02bc45a59185e5fc6092dbe966c5164af8662430 Mon Sep 17 00:00:00 2001 From: Tom Rollet Date: Fri, 24 Feb 2023 16:29:37 +0100 Subject: [PATCH] cpu-o3: fix false positive in AddressSanitizer AddressSanitizer found a new-delete-type-mismatch because of the custom new operator for DynInst. Adding a custom delete operator for DynInstPtr fixes this issue. It has been fixed the same way in Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=1391500 Change-Id: I0ab4cb6d79cac88069cc2374a1deb499cdb15f02 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/68357 Maintainer: Jason Lowe-Power Reviewed-by: Jason Lowe-Power Tested-by: kokoro --- src/cpu/o3/dyn_inst.cc | 9 +++++++++ src/cpu/o3/dyn_inst.hh | 1 + 2 files changed, 10 insertions(+) diff --git a/src/cpu/o3/dyn_inst.cc b/src/cpu/o3/dyn_inst.cc index c5e54f1886..c0ace7cdae 100644 --- a/src/cpu/o3/dyn_inst.cc +++ b/src/cpu/o3/dyn_inst.cc @@ -191,6 +191,15 @@ DynInst::operator new(size_t count, Arrays &arrays) return buf; } +// Because of the custom "new" operator that allocates more bytes than the +// size of the DynInst object, AddressSanitizer throw new-delete-type-mismatch. +// Adding a custom delete function is enough to shut down this false positive +void +DynInst::operator delete(void *ptr) +{ + ::operator delete(ptr); +} + DynInst::~DynInst() { /* diff --git a/src/cpu/o3/dyn_inst.hh b/src/cpu/o3/dyn_inst.hh index 3dae156eb1..9b46431b2d 100644 --- a/src/cpu/o3/dyn_inst.hh +++ b/src/cpu/o3/dyn_inst.hh @@ -104,6 +104,7 @@ class DynInst : public ExecContext, public RefCounted }; static void *operator new(size_t count, Arrays &arrays); + static void operator delete(void* ptr); /** BaseDynInst constructor given a binary instruction. */ DynInst(const Arrays &arrays, const StaticInstPtr &staticInst,