[PATCH] D147740: [llvm-profdata] Refactoring Sample Profile Reader to increase FDO build speed using MD5 as key to Sample Profile map

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 20:56:34 PDT 2023


huangjd added a comment.

@MatzeB

After some investigation it looks like it's an independent bug in Transforms/IPO/SampleProfile.cpp that has never been discovered.

In SampleProfile.cpp, non-inlined callees are added to the Profiles as new functions, which can trigger a rehashing and invalidates all iterator, including SampleProfileLoader::SampleProfileLoaderBaseImpl::Samples which is a pointer to the current function's FunctionSamples inside the profile. This pointer is later used so it is already undefined behavior.

LLVM's standard library implementation was able to expand the profile (originaly unordered_map) in place without relocating objects, so the code would work. In my patch I changed the container to llvm::DenseMap, which will always relocate objects on rehashing, causing the pointer to be invalid and crashing the program. Since std::unordered_map does not guarantee that either, this function is UB and needs to be rewritten

I am going to submit a patch to that first, although I am not able to create a small test case for that bug since std::unordered_map is doing well to avoid relocating objects as long as there is enough memory, so it would require more careful code review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147740/new/

https://reviews.llvm.org/D147740



More information about the llvm-commits mailing list