Skip to content

[hwasan] Flush stderr/stdout in tests #114083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

thurstond
Copy link
Contributor

The x86_64_lam_qemu buildbots started failing (https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio). Based on the logs, it appears the HWASan check is correct but it did not match the stderr/stdout output. This patch attempts to fix the issue by flushing stderr/stdout as appropriate.

The x86_64_lam_qemu buildbots started failing (https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio). Based on the logs, it appears the HWASan check is correct but it did not match the stderr/stdout output. This patch attempts to fix the issue by flushing stderr/stdout as appropriate.
@llvmbot
Copy link
Member

llvmbot commented Oct 29, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Thurston Dang (thurstond)

Changes

The x86_64_lam_qemu buildbots started failing (https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio). Based on the logs, it appears the HWASan check is correct but it did not match the stderr/stdout output. This patch attempts to fix the issue by flushing stderr/stdout as appropriate.


Full diff: https://github.com/llvm/llvm-project/pull/114083.diff

3 Files Affected:

  • (modified) compiler-rt/test/hwasan/TestCases/many-threads-uaf.c (+1)
  • (modified) compiler-rt/test/hwasan/TestCases/mem-intrinsics.c (+1)
  • (modified) compiler-rt/test/hwasan/TestCases/use-after-free.c (+1)
diff --git a/compiler-rt/test/hwasan/TestCases/many-threads-uaf.c b/compiler-rt/test/hwasan/TestCases/many-threads-uaf.c
index 8fa07861371d56..e02ab5b28ce046 100644
--- a/compiler-rt/test/hwasan/TestCases/many-threads-uaf.c
+++ b/compiler-rt/test/hwasan/TestCases/many-threads-uaf.c
@@ -23,6 +23,7 @@ void *BoringThread(void *arg) {
 void *UAFThread(void *arg) {
   char * volatile x = (char*)malloc(10);
   fprintf(stderr, "ZZZ %p\n", x);
+  fflush(stderr);
   free(x);
   x[5] = 42;
   // CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address
diff --git a/compiler-rt/test/hwasan/TestCases/mem-intrinsics.c b/compiler-rt/test/hwasan/TestCases/mem-intrinsics.c
index 78bef538af1161..da1cb686969206 100644
--- a/compiler-rt/test/hwasan/TestCases/mem-intrinsics.c
+++ b/compiler-rt/test/hwasan/TestCases/mem-intrinsics.c
@@ -21,6 +21,7 @@ int main() {
   memcpy(Q, P, 32);
 #endif
   write(STDOUT_FILENO, "recovered\n", 10);
+  fflush(stdout);
   // WRITE: ERROR: HWAddressSanitizer: tag-mismatch on address
   // WRITE: WRITE of size 32 at {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem)
   // WRITE: Invalid access starting at offset 16
diff --git a/compiler-rt/test/hwasan/TestCases/use-after-free.c b/compiler-rt/test/hwasan/TestCases/use-after-free.c
index 070622f560a225..b4b79875e8111e 100644
--- a/compiler-rt/test/hwasan/TestCases/use-after-free.c
+++ b/compiler-rt/test/hwasan/TestCases/use-after-free.c
@@ -15,6 +15,7 @@ int main() {
   free(x);
   __hwasan_disable_allocator_tagging();
   fprintf(stderr, ISREAD ? "Going to do a READ\n" : "Going to do a WRITE\n");
+  fflush(stderr);
   // CHECK: Going to do a [[TYPE:[A-Z]*]]
   int r = 0;
   if (ISREAD) r = x[5]; else x[5] = 42;  // should be on the same line.

thurstond added a commit to thurstond/llvm-project that referenced this pull request Oct 29, 2024
This is the ASan equivalent of llvm#114083.

The x86_64_lam_qemu buildbots started failing
(https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio).
Based on the logs, it appears the HWASan check is correct but it did not
match the stderr/stdout output. This patch attempts to fix the issue by
flushing stderr/stdout as appropriate.
@thurstond thurstond merged commit 3754fc1 into llvm:main Oct 29, 2024
9 of 11 checks passed
thurstond added a commit that referenced this pull request Oct 29, 2024
This is the ASan equivalent of
#114083.

The x86_64_lam_qemu buildbots started failing

(https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio).
Based on the logs, it appears the ASan check is correct but it did not
match the stderr/stdout output. This patch attempts to fix the issue by
flushing stderr as appropriate.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 29, 2024

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building compiler-rt at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/13080

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'HWAddressSanitizer-x86_64 :: TestCases/use-after-free.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /build/buildbot/premerge-monolithic-linux/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 -O0 -DISREAD=1 /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c -o /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins/compiler-rt/test/hwasan/X86_64/TestCases/Output/use-after-free.c.tmp && not  /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins/compiler-rt/test/hwasan/X86_64/TestCases/Output/use-after-free.c.tmp 2>&1 | FileCheck /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c --check-prefixes=CHECK
+ /build/buildbot/premerge-monolithic-linux/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 -O0 -DISREAD=1 /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c -o /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins/compiler-rt/test/hwasan/X86_64/TestCases/Output/use-after-free.c.tmp
+ not /build/buildbot/premerge-monolithic-linux/build/runtimes/runtimes-bins/compiler-rt/test/hwasan/X86_64/TestCases/Output/use-after-free.c.tmp
+ FileCheck /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c --check-prefixes=CHECK
/build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c:35:12: error: CHECK: expected string not found in input
 // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-19]]
           ^
<stdin>:16:137: note: scanning from here
 #0 0x5cf467175927 in free /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:85:3
                                                                                                                                        ^
<stdin>:16:137: note: with "@LINE-19" equal to "16"
 #0 0x5cf467175927 in free /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:85:3
                                                                                                                                        ^
<stdin>:17:100: note: possible intended match here
 #1 0x5cf4671bb29a in main /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c:15:3
                                                                                                   ^

Input file: <stdin>
Check file: /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c

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

Input was:
<<<<<<
            .
            .
            .
           11: [0x480200000000,0x480200000010) is a small unallocated heap chunk; size: 16 offset: 5 
           12:  
           13: Cause: use-after-free 
           14: 0x480200000005 is located 5 bytes inside a 10-byte region [0x480200000000,0x48020000000a) 
           15: freed by thread T0 here: 
           16:  #0 0x5cf467175927 in free /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:85:3 
check:35'0                                                                                                                                             X~~~~~ error: no match found
check:35'1                                                                                                                                                    with "@LINE-19" equal to "16"
           17:  #1 0x5cf4671bb29a in main /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/test/hwasan/TestCases/use-after-free.c:15:3 
check:35'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:35'2                                                                                                        ?                                       possible intended match
           18:  #2 0x7ace92df3d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: a43bfc8428df6623cd498c9c0caeb91aec9be4f9) 
check:35'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           19:  
check:35'0     ~
           20: previously allocated by thread T0 here: 
check:35'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           21:  #0 0x5cf467176004 in malloc /build/buildbot/premerge-monolithic-linux/llvm-project/compiler-rt/lib/hwasan/hwasan_allocation_functions.cpp:147:3 
...

NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
The x86_64_lam_qemu buildbots started failing
(https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio).
Based on the logs, it appears the HWASan check is correct but it did not
match the stderr/stdout output. This patch attempts to fix the issue by
flushing stderr/stdout as appropriate.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
This is the ASan equivalent of
llvm#114083.

The x86_64_lam_qemu buildbots started failing

(https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio).
Based on the logs, it appears the ASan check is correct but it did not
match the stderr/stdout output. This patch attempts to fix the issue by
flushing stderr as appropriate.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants