This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix tests after defaulting to -fno-common. NFC.
ClosedPublic

Authored by SjoerdMeijer on Mar 3 2020, 6:35 AM.

Details

Summary

After committing D75056, which I've reverted now, these compiler-rt tests failed:

    
FAIL: AddressSanitizer-aarch64-linux::odr_c_test.c
FAIL: AddressSanitizer-aarch64-linux::set_shadow_test.c

and the same tests in a different configuration:

FAIL: AddressSanitizer-aarch64-linux-dynamic::odr_c_test.c
FAIL: AddressSanitizer-aarch64-linux-dynamic::set_shadow_test.c

I don't want to hold up this commit for these tests, so I intend to recommit D75056 soon'ish with these test changes included. I am posting this for review so that we can (post-commit) further address this.

It looks like these tests are not very robust and rely on -fcommon behaviour. But both tests are not really in my area, so a second opinion would be good to confirm if adding -fcommon to the run lines is good enough, or if the tests need to be rewritten.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Mar 3 2020, 6:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2020, 6:35 AM

I probably forgot to add why these tests started failing!

For compiler-rt/test/asan/TestCases/Linux/odr_c_test.c, expected string CHECK: The following global variable is not properly aligned did not occur anymore. So, global ZZZ is now aligned.

And for the other case:

.../compiler-rt/test/asan/TestCases/set_shadow_test.c:37:10: error: XF1: expected string not found in input
 // XF1: AddressSanitizer: stack-buffer-underflow
              ^

we don't trigger this stack buffer underflow anymore.

vsk edited reviewers, added: eugenis, vitalybuka; removed: vsk.Mar 3 2020, 7:17 AM
vsk added a subscriber: vsk.

Adding reviewers with more familiarity with Asan.

jyknight added inline comments.Mar 3 2020, 7:53 AM
compiler-rt/test/asan/TestCases/Linux/odr_c_test.c
4–6

The test is explicitly testing the detection of the conflict between the common ZZZ (in FILE1) vs a non-common ZZZ (in FILE2), via the non-matching alignment.

Adding -fcommon here is correct.

compiler-rt/test/asan/TestCases/set_shadow_test.c
1

This test looks like this test wants to pretend the global "a" is on the stack, but when "a" is an actual global, ASAN knows it doesn't need to instrument the store, so the pretending fails.

I think a nicer fix would be this:

@@ -21,13 +21,13 @@
 void __asan_set_shadow_f5(size_t addr, size_t size);
 void __asan_set_shadow_f8(size_t addr, size_t size);
 
-char a __attribute__((aligned(8)));
+char* a;
 
 void f(long arg) {
   size_t shadow_offset;
   size_t shadow_scale;
   __asan_get_shadow_mapping(&shadow_scale, &shadow_offset);
-  size_t addr = (((size_t)&a) >> shadow_scale) + shadow_offset;
+  size_t addr = (((size_t)a) >> shadow_scale) + shadow_offset;
 
   switch (arg) {
   // X00-NOT: AddressSanitizer
@@ -61,9 +61,10 @@
 int main(int argc, char **argv) {
   assert(argc > 1);
 
+  a = malloc(8);
   long arg = strtol(argv[1], 0, 16);
   f(arg);
-  a = 1;
+  *a = 1;
   printf("PASS\n");
   return 0;
 }

Thanks James, I will prepare a new revision!
The test-suite needs porting too (see comment in D75056) and am first looking into that, after that I will return to this.

Thanks for that solution, have copied it to the test file.

I wanted to include these test changes in the recommit, but perhaps it's nice to commit this separately (as this this a change in a different component).
So wanted to check if we are happy with this?

vitalybuka accepted this revision.Apr 8 2020, 6:18 PM
This revision is now accepted and ready to land.Apr 8 2020, 6:18 PM
SjoerdMeijer closed this revision.Apr 22 2020, 2:05 AM

Thanks for taking a look. I had already merged this into the other commit, the one that changed the behaviour of -fcommon. So, this has been committed, closing this change.