[PATCH] D54337: [ASan] Make AddressSanitizer a ModulePass

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 15 11:00:35 PST 2018


leonardchan added a comment.

Sorry for the delayed response. So the main problem is that `AddressSantizer` needs to perform some initialization involving reading stuff from global metadata and getting some target specific information. More specifically, just these 6 things which are all initialized in `doInitialization`:

  GlobalsMD.init(M);
  C = &(M.getContext());
  LongSize = M.getDataLayout().getPointerSizeInBits();
  IntptrTy = Type::getIntNTy(*C, LongSize);
  TargetTriple = Triple(M.getTargetTriple());
  Mapping = getShadowMapping(TargetTriple, LongSize, CompileKernel);

which are all accessible from the `Module`. (I think) this doesn't require adding any function definitions or changes to the module other than adding the declarations for functions used for the ASan runtime, and `AddressSanitizerModule` I think is the only ASan related pass that calls `createSanitizerCtorAndInitFunctions` for making these function definitions.

To me it seems that there just needs to be an equivalent `doInitialization` that accepts modules for function passes in the new PM, but it seems that given the way runs are performed in the new PM, there's no inherit way to access the "parent" IRUnit of a given IRUnit. Was this what you were suggesting with the `function outside of the pass pipeline` @philip.pfaffe ? An alternative idea that @tamur suggested was putting the global metadata and other initialized data into a lazy data structure that can be accessed by the `AddressSanitizers`.

Would having this as a ModulePass also make that much of an impact in instrumentation speed? From what I could determine, with AddressSanitizer as a FunctionPass, control of this is delegated to the FunctionPassManager whose 'runOnModule` method just iterates through every function in the module, and it seems that the only actions done between the FunctionPass's `doInitialization` and FunctionPassManager's `runOnModule` is counting the size of the module and initializing some analyses, but I could also be overlooking something big here.


Repository:
  rL LLVM

https://reviews.llvm.org/D54337





More information about the llvm-commits mailing list