[PATCH] D89959: UBSAN: emit distinctive traps in trapping mode

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 22 06:44:11 PDT 2020


t.p.northover created this revision.
Herald added subscribers: pengfei, hiraditya, kristof.beyls, mcrosier.
Herald added a project: LLVM.
t.p.northover requested review of this revision.
Herald added a subscriber: jdoerfert.

When a trapping sanitizer is deployed in release configurations, you might have limited ability to get information back from crashes. This patch makes Clang emit a different kind of trap, firstly for UBSAN compared to any other reason we might trap, but also for its different failure modes.

A crash-dumping program can then inspect the opcode and give you, if not a truly specific diagnosis, at least a function and what kind of thing to look for which is often enough to diagnose the problem.

Because of the extra traps there is a small code-size penalty, but it's pretty small compared to what we accept just for the sanitization so probably not a big concern (57.0% overhead as opposed to 55.7% currently on SPEC, for AArch64),

For now I've implemented the new kind of trap for AArch64 and X86, with fallback to a default trap elsewhere.


https://reviews.llvm.org/D89959

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/bounds-checking.c
  clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-lvalue.cpp
  clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-paramvar.cpp
  clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function-variable.cpp
  clang/test/CodeGen/catch-alignment-assumption-attribute-alloc_align-on-function.cpp
  clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function-two-params.cpp
  clang/test/CodeGen/catch-alignment-assumption-attribute-assume_aligned-on-function.cpp
  clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params-variable.cpp
  clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-three-params.cpp
  clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-two-params.cpp
  clang/test/CodeGen/catch-alignment-assumption-openmp.cpp
  clang/test/CodeGen/catch-implicit-integer-sign-changes-CompoundAssignOperator.c
  clang/test/CodeGen/catch-implicit-integer-sign-changes-incdec.c
  clang/test/CodeGen/catch-implicit-integer-sign-changes.c
  clang/test/CodeGen/catch-implicit-integer-truncations-CompoundAssignOperator.c
  clang/test/CodeGen/catch-implicit-integer-truncations.c
  clang/test/CodeGen/catch-implicit-signed-integer-truncation-or-sign-change-CompoundAssignOperator.c
  clang/test/CodeGen/catch-implicit-signed-integer-truncation-or-sign-change.c
  clang/test/CodeGen/catch-implicit-signed-integer-truncations-incdec.c
  clang/test/CodeGen/catch-nullptr-and-nonzero-offset-when-nullptr-is-defined.c
  clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
  clang/test/CodeGen/catch-pointer-overflow-volatile.c
  clang/test/CodeGen/catch-pointer-overflow.c
  clang/test/CodeGen/catch-undef-behavior.c
  clang/test/CodeGen/cfi-check-fail.c
  clang/test/CodeGen/cfi-check-fail2.c
  clang/test/CodeGen/sanitize-trap.c
  clang/test/CodeGen/trapv.c
  clang/test/CodeGen/unsigned-trapv.c
  clang/test/CodeGenCXX/cfi-cast.cpp
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/trap-fnattr.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Target/TargetSelectionDAG.td
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrSystem.td
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/test/CodeGen/AArch64/ubsantrap.ll
  llvm/test/CodeGen/X86/ubsantrap.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89959.299952.patch
Type: text/x-patch
Size: 304466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201022/7ea58fd5/attachment-0001.bin>


More information about the llvm-commits mailing list