This is an archive of the discontinued LLVM Phabricator instance.

[ubsan-minimal] Report the address of an error
ClosedPublic

Authored by ikudrin on Aug 15 2022, 11:57 AM.

Details

Summary

This implements a FIXME in the runtime library and adds printing the address at the end of the message as "by 0x123abc". The buffer for the message is allocated on the stack in a handler, so the stack memory consumption is slightly increased. No additional external dependencies are added.

Diff Detail

Event Timeline

ikudrin created this revision.Aug 15 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2022, 11:57 AM
Herald added a subscriber: Enna1. · View Herald Transcript
ikudrin requested review of this revision.Aug 15 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2022, 11:57 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Unfortunately, I have no idea how to check the new output. Will be grateful for any suggestions.

Can you add/update few tests?

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
23–26

looks unrelated, can you land it separately, no review is needed

54

why do we need noinline here?

59

please don't skip them and match %p style
sanitizers usually don't skip 0s

65

you can avoid updating mask with:
unsigned int nibble = (caller >> shift) & 0xf;

97

Can we have "@" -> "at 0x"?

vitalybuka added a comment.EditedAug 22 2022, 2:05 PM

Unfortunately, I have no idea how to check the new output. Will be grateful for any suggestions.

Sorry, didn't notice on the first pass.
my favorite way for find test on unknown code is to brake code around and run all tests: check-all

something like this and "ninja check-ubsan-minimal"

diff --git a/compiler-rt/test/ubsan_minimal/TestCases/alignment-assumption.c b/compiler-rt/test/ubsan_minimal/TestCases/alignment-assumption.c
index 08696c81e573..763261dda1d5 100644
--- a/compiler-rt/test/ubsan_minimal/TestCases/alignment-assumption.c
+++ b/compiler-rt/test/ubsan_minimal/TestCases/alignment-assumption.c
@@ -8,7 +8,7 @@ int main(int argc, char *argv[]) {
 
   void *t = __builtin_assume_aligned(ptr + 1, 0x8000);
   (void)t;
-  // CHECK: ubsan: alignment-assumption
+  // CHECK: ubsan: alignment-assumption at 0x{{[0-9af]}}
   // CHECK-NOT: alignment-assumption
 
   free(ptr);

maybe update all these few test cases in the dir

vitalybuka added inline comments.Aug 22 2022, 2:14 PM
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
97

Can we have "@" -> "at 0x"?

Looks like we mostly use "at" for load/store location
maybe "@" -> "by 0x", then it would be clear that this is the code

ikudrin updated this revision to Diff 454957.Aug 23 2022, 2:09 PM
ikudrin marked 4 inline comments as done.
ikudrin edited the summary of this revision. (Show Details)

Thanks for the review!

  • An NFC part is committed as https://reviews.llvm.org/rG1959a55591da
  • Print leading zeroes,
  • "@..." -> "by 0x...",
  • Update tests, except recover-dedup-limit.cpp, because that change would only add some noise and not any value to it.
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
54

report_this_error() has the attribute, so I decided to follow that here. It seems to correspond to the intention to make the library as small as possible.

97

Changed to "by 0x".

vitalybuka accepted this revision.Sep 2 2022, 10:56 PM
This revision is now accepted and ready to land.Sep 2 2022, 10:56 PM
MaskRay added inline comments.
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
56

s/unsigned int/unsigned/ everywhere

56

You may change the loop to do shift -= 4 first, then the declaration can omit - 4.

MaskRay accepted this revision.Sep 3 2022, 10:16 AM
MaskRay added inline comments.
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
96

constexpr unsigned kAddrBuf = ...

static is redundant for const. But when constexpr works, prefer constexpr instead.

compiler-rt/test/ubsan_minimal/TestCases/alignment-assumption.c
11

Note: [[#%x,]] can replace {{[[:xdigit:]]+}} but here we match $ too which requires {{$}}, I think xdigit is fine, too.

ikudrin marked 4 inline comments as done.Sep 5 2022, 3:20 AM

Thanks!

This revision was landed with ongoing or failed builds.Sep 5 2022, 3:20 AM
This revision was automatically updated to reflect the committed changes.