[PATCH] D76416: [ASan] Apply -ffile-prefix-map mappings to ASan instrumentation

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 18 23:57:36 PDT 2020


leonardchan created this revision.
leonardchan added reviewers: phosek, rnk, MaskRay, Lekensteyn, rsmith, echristo.
leonardchan added a project: LLVM.
Herald added subscribers: cfe-commits, ormris, hiraditya.
Herald added a project: clang.
leonardchan updated this revision to Diff 251289.

Some asan-instrumented binaries that are distributed as part of a clang toolchain result in different sizes depending on the length of the build path. This is because ASan is including the path to the source file from the module ID and sanitizer metadata. To have a deterministic build independent of the source file's location, we can extend the usage of `-ffile-prefix-map` to also apply to sanitizers.

In this patch:

- Add a StringMap that can be used by anyone with access to `CodeGenOptions` that holds all mappings passed to `-ffile-prefix-map`.
- Replace path prefixes for module IDs on module creation.
- Replace path prefixes for sanitizer metadata source locations when creating a `GlobalsMetadata` object.

Design considerations:

- We avoid adding a new flag for sanitizers to prevent adding an extra knob. We would also expect that `-ffile-prefix-map` generally apply to all instances of paths we would see emitted into a stripped object file.
- I applied the mapping on `GlobalsMetadata` creation when the `ASanGlobalsMetadataWrapperPass` runs because I couldn't think of a better place to apply the prefix mapping. The path was originally passed down as a StringRef all the way from a `PresumedLoc` in `SanitizerMetadata::getLocationMetadata()`, which cannot be edited with `replace_path_prefix`.
- I added the mapping as metadata (`llvm.asan.file.prefix.map`) to prevent having to pass the original StringMap from clang all the way down to ASan and iterating over the map whenever ASan creates a private string. Adding it to metadata that `ASanGlobalsMetadataWrapperPass` can read should allow us to do this once when that pass is created.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76416

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/asan-globals-file-prefix-map.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/asan_file_prefix_map.ll
  llvm/test/Instrumentation/AddressSanitizer/asan_no_file_prefix_map.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76416.251289.patch
Type: text/x-patch
Size: 11899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200319/e0b96b68/attachment.bin>


More information about the llvm-commits mailing list