[PATCH] D75520: [compiler-rt] Fix tests after defaulting to -fno-common. NFC.

James Y Knight via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 08:00:16 PST 2020


jyknight added inline comments.


================
Comment at: compiler-rt/test/asan/TestCases/Linux/odr_c_test.c:4-6
+// RUN: %clang_asan -fcommon %s -fPIC -shared -o %dynamiclib1  -DFILE1
+// RUN: %clang_asan -fcommon %s -fPIC -shared -o %dynamiclib2  -DFILE2
+// RUN: %clang_asan -fcommon %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t
----------------
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.


================
Comment at: compiler-rt/test/asan/TestCases/set_shadow_test.c:1
-// RUN: %clang_asan -O0 %s -o %t
+// RUN: %clang_asan -fcommon -O0 %s -o %t
 // RUN: %run %t 0x00 2>&1 | FileCheck %s -check-prefix=X00
----------------
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;
 }
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75520/new/

https://reviews.llvm.org/D75520





More information about the llvm-commits mailing list