This is an archive of the discontinued LLVM Phabricator instance.

[HWASan] Allow to linkify symbolizer output.
ClosedPublic

Authored by fmayer on May 4 2022, 11:27 AM.

Diff Detail

Event Timeline

fmayer created this revision.May 4 2022, 11:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2022, 11:27 AM
fmayer published this revision for review.May 4 2022, 2:39 PM
fmayer added a reviewer: eugenis.
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2022, 2:40 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

This script is starting to get complex. Perhaps we should write tests?

fmayer added a comment.May 4 2022, 3:54 PM

This script is starting to get complex. Perhaps we should write tests?

Yes, that is on my TODO list. Happy to do that before submission, but wanted to make sure this approach is fine before doing so.

The approach looks fine. Should we also put a <html></html> pair around the output, or do you want to treat it as a snippet?

fmayer added a comment.May 4 2022, 4:00 PM

The approach looks fine. Should we also put a <html></html> pair around the output, or do you want to treat it as a snippet?

Generally I don't think this would be used a standalone input, so maybe a snippet is better and the consumer can add whatever they want around. For my use-case this gets piped into pandoc to be converted to Markdown.

fmayer updated this revision to Diff 427193.May 4 2022, 9:42 PM

Add test

fmayer added a comment.May 4 2022, 9:43 PM

This script is starting to get complex. Perhaps we should write tests?

done. added a test for general symbolization and for linkifying

eugenis added inline comments.May 5 2022, 2:46 PM
compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
3

trying to think if this will run correctly on android, when the test binary runs on the device, but FileCheck runs on the host. Also, I think we push llvm-symbolizer to the device for online symbolization, you may need to disable it through HWASAN_OPTIONS.

fmayer added inline comments.May 5 2022, 2:48 PM
compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
3

It does. What happens is that %t becomes the wrapper script (and the real binary becomes %t.real) that runs on the device. The whole pipeline specified here happens on the host.

I ran this on Android.

fmayer added inline comments.May 5 2022, 2:49 PM
compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
3

Good point on the HWASAN_OPTIONS. That makes it more resilient.

eugenis accepted this revision.May 5 2022, 2:55 PM

LGTM

This revision is now accepted and ready to land.May 5 2022, 2:55 PM
fmayer updated this revision to Diff 427466.May 5 2022, 2:56 PM

address comment

This revision was automatically updated to reflect the committed changes.
dyung added a subscriber: dyung.May 6 2022, 12:41 AM

Hi, the test you added, hwasan_symbolize.cpp seems to be causing a failure on the sanitizer buildbot (https://lab.llvm.org/buildbot/#/builders/37/builds/13022):

FAIL: HWAddressSanitizer-x86_64 :: TestCases/hwasan_symbolize.cpp (71 of 86)
******************** TEST 'HWAddressSanitizer-x86_64 :: TestCases/hwasan_symbolize.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /b/sanitizer-x86_64-linux/build/clang_build/./bin/clang   -m64  -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -fsanitize-hwaddress-experimental-aliasing -mllvm -hwasan-generate-tags-with-calls=1 -mllvm -hwasan-globals -mllvm -hwasan-use-short-granules -mllvm -hwasan-instrument-landing-pads=0 -mllvm -hwasan-instrument-personality-functions -Wl,--build-id -g /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp -o /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp
: 'RUN: at line 2';   echo '[{"prefix": "'"$(realpath $(dirname /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp)/../../../../../../)"'/", "link": "http://test.invalid/{file}:{line}"}]' > /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp.linkify
: 'RUN: at line 3';   env HWASAN_OPTIONS=disable_allocator_tagging=1:random_tags=0:fail_without_syscall_abi=0:symbolize=0 not  /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp 2>&1 | hwasan_symbolize --html --symbols $(dirname /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp) --index | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
: 'RUN: at line 4';   env HWASAN_OPTIONS=disable_allocator_tagging=1:random_tags=0:fail_without_syscall_abi=0:symbolize=0 not  /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp 2>&1 | hwasan_symbolize --html --linkify /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp.linkify --symbols $(dirname /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp) --index | FileCheck --check-prefixes=CHECK,LINKIFY /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
: 'RUN: at line 5';   env HWASAN_OPTIONS=disable_allocator_tagging=1:random_tags=0:fail_without_syscall_abi=0:symbolize=0 not  /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp 2>&1 | hwasan_symbolize --symbols $(dirname /b/sanitizer-x86_64-linux/build/clang_build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/hwasan_symbolize.cpp.tmp) --index | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
--
Exit Code: 2
Command Output (stderr):
--
Traceback (most recent call last):
  File "/b/sanitizer-x86_64-linux/build/clang_build/./bin/hwasan_symbolize", line 19, in <module>
    import html
ImportError: No module named html
FileCheck error: '<stdin>' is empty.
FileCheck command line:  FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
--

And also our internal linux buildbot is reporting a failure after this commit:

/home/siadmin/jenkins/w/opensource/opensource_build/working_dir/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp:17:14: error: LINKIFY: expected string not found in input
 // LINKIFY: <a href="http://test.invalid/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp:[[@LINE-1]]">
             ^
<stdin>:1:1: note: scanning from here
==27214==ERROR: HWAddressSanitizer: tag-mismatch on address 0x680400000064 at pc 0x55d1c8f6e76b<br/>
^
<stdin>:1:1: note: with "@LINE-1" equal to "16"
==27214==ERROR: HWAddressSanitizer: tag-mismatch on address 0x680400000064 at pc 0x55d1c8f6e76b<br/>
^
<stdin>:6:68: note: possible intended match here
&nbsp;&nbsp;&nbsp;&nbsp;#1 main in /home/siadmin/jenkins/w/opensource/opensource_build/working_dir/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp:16:10<br/>
                                                                   ^

Input file: <stdin>
Check file: /home/siadmin/jenkins/w/opensource/opensource_build/working_dir/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: ==27214==ERROR: HWAddressSanitizer: tag-mismatch on address 0x680400000064 at pc 0x55d1c8f6e76b<br/> 
check:17'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
check:17'1                                                                                                           with "@LINE-1" equal to "16"
            2: READ of size 1 at 0x680400000064 tags: 03/00 (ptr/mem) in thread T0<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            3: &nbsp;&nbsp;&nbsp;&nbsp;#0 SigTrap&lt;0&gt; in [hwasan_rtl]:0<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            4: &nbsp;&nbsp;&nbsp;&nbsp;-&gt; CheckAddress&lt;(__hwasan::ErrorAction)0, (__hwasan::AccessType)0, 0&gt; in [hwasan_rtl]:0<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5: &nbsp;&nbsp;&nbsp;&nbsp;-&gt; __hwasan_load1 in /home/siadmin/jenkins/w/opensource/opensource_build/working_dir/compiler-rt/lib/hwasan/hwasan.cpp:445:0<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            6: &nbsp;&nbsp;&nbsp;&nbsp;#1 main in /home/siadmin/jenkins/w/opensource/opensource_build/working_dir/compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp:16:10<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:17'2                                                                        ?                                                                                                  possible intended match
            7: &nbsp;&nbsp;&nbsp;&nbsp;#2 0x7fbc32907bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) (BuildId: ce450eb01a5e5acc7ce7b8c2633b02cc1093339e)<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            8: &nbsp;&nbsp;&nbsp;&nbsp;#3 _start in ??:0:0<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            9: <br/> 
check:17'0     ~~~~~~
           10: [0x680400000060,0x680400000080) is a small unallocated heap chunk; size: 32 offset: 4<br/> 
check:17'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           11: <br/> 
check:17'0     ~~~~~~
            .
            .
            .
>>>>>>

Can you please take a look and revert if it will take some time to fix?

thakis added a subscriber: thakis.May 6 2022, 6:51 AM

And also our internal linux buildbot is reporting a failure after this commit:

*snip*

I'm seeing this same failure when I run ninja check-hwasan in my local, fairly vanilla, cmake build.

I'm also seeing it on http://45.33.8.238/linux/75461/step_10.txt . Given the other report of breakage, I'll revert this for now until things are sorted out.

compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
6

Do you know why this works? Normally (in clang and lld and llvm), you have to call llvm_config.add_tool_substitutions() for the binaries that you want lit to find in the build dir. compiler-rt doesn't seem to do this, and hwasan_symbolize seems to be found fine so it works somehow, but I don't know how. Could you explain it to me?

fmayer added a comment.EditedMay 6 2022, 8:31 AM

And also our internal linux buildbot is reporting a failure after this commit:

*snip*

I'm seeing this same failure when I run ninja check-hwasan in my local, fairly vanilla, cmake build.

I'm also seeing it on http://45.33.8.238/linux/75461/step_10.txt . Given the other report of breakage, I'll revert this for now until things are sorted out.

Which version of Python are you running? html is apparently around since 3.2.

EDIT: oh, I misunderstood. "this error" being the FileCheck, not the import. Correct?

thakis added a comment.May 6 2022, 8:34 AM

I'm running python 3.9.10.

As far as I can tell, there are 2 distinct errors:

  1. the import html error on https://lab.llvm.org/buildbot/#/builders/37/builds/13022
  2. FileCheck error seen on @dyung's internal bot, on my machine, and on my bot
fmayer added a comment.May 6 2022, 8:36 AM

I'm running python 3.9.10.

As far as I can tell, there are 2 distinct errors:

  1. the import html error on https://lab.llvm.org/buildbot/#/builders/37/builds/13022
  2. FileCheck error seen on @dyung's internal bot, on my machine, and on my bot

Thanks. Sorry about that, thanks for reverting.

fmayer reopened this revision.May 6 2022, 11:14 AM
This revision is now accepted and ready to land.May 6 2022, 11:14 AM
fmayer planned changes to this revision.May 6 2022, 11:14 AM
fmayer updated this revision to Diff 427768.May 6 2022, 3:13 PM
fmayer marked 2 inline comments as done.

fix test.

This revision is now accepted and ready to land.May 6 2022, 3:13 PM
fmayer added inline comments.May 6 2022, 3:16 PM
compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
6

When I run env in the test, build/bin is the first entry in path, so it makes sense that this works.

fmayer added inline comments.May 6 2022, 3:43 PM
compiler-rt/test/hwasan/TestCases/hwasan_symbolize.cpp
6

That seems to be due to this in our lit cfg

# Tweak PATH to include llvm tools dir.
if (not config.llvm_tools_dir) or (not os.path.exists(config.llvm_tools_dir)):
  lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % config.llvm_tools_dir)
path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
config.environment['PATH'] = path
This revision was automatically updated to reflect the committed changes.