Reliably mapping memcpy intrinsic

Similar to how operator new(size) can be overridden during linking, to capture and customize all memory allocation operations, I’d like to be able to capture all scenarios where memory is copied or moved. I’ve tried to use --wrap memcpy with some success, however I’ve noticed that in some instances (e.g. copying a small struct) the memcpy instruction in the IR is replaced with a sequence of movq instructions, and the wrap function is not able to hook into that piece of the code.

Is there a way to ensure all llvm.memcpy intrinsics in the IR are always lowered to call the memcpy symbol?

Failing that approach, can you suggest other ways to plug into the desired memory options? I’d like to hook into every memory operation that has a source and a destination address (copy, move, etc) so I can trace the passage of symbols through an executing program.


I think setting MaxStoresPerMemcpy to zero (eg. lib/Target/X86/X86ISelLowering.cpp) may do the trick. As it does not seem to be a flag, it would require a source edit.

Cool, - thanks Hiroshi! I gave it a try, however I’m finding that after setting to zero, it fails when trying to build a particular file (locale.cpp from libc++):

Any ideas why that might be?

Thanks again,

Matt, sorry, no idea.