Skip to content

Commit

Permalink
cpu-o3: fix false positive in AddressSanitizer
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
  • Loading branch information
Tom Rollet authored and cyyself committed Sep 13, 2024
1 parent 08e6f66 commit 02bc45a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/cpu/o3/dyn_inst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
/*
Expand Down
1 change: 1 addition & 0 deletions src/cpu/o3/dyn_inst.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 02bc45a

Please sign in to comment.