[llvm-dev] how to monitor read operation to special memory blocks?
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 13 09:20:53 PDT 2015
On 13 October 2015 at 01:28, 慕冬亮 via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> In LLVM, is there any way to monitor read operation to some special blocks?
> For example, I have a memory block from A1 to A2 to protect. Any read
> operation to the address between A1 and A2 will be caught.
You could write a pass that instruments any LLVM IR to check the
address of any operation that's going to load and change the behaviour
(much like Clang's sanitizers, but on existing IR rather than when
creating it). E.g. rewrite
%val = load i32* %addr
%val = call i32 @checked_load_i32(i32* %addr)
where you write an appropriate "checked_load_i32" function to do what
you want. You'll obviously have to handle other types (maybe by always
loading to an iN and then bitcasting the result), and intrinsics like
But if you also want to check library calls, you'll have to recompile
those libraries with this pass too, which may or may not be easy.
You'd also miss inline assembly, and loads inserted by the compiler
(possibly to materialize constants, or virtually anything that
implicitly happens to the stack like
To get 100% coverage, either a VM (possibly like valgrind) or a
friendly OS-kernel is probably the only option.
More information about the llvm-dev