This is an archive of the discontinued LLVM Phabricator instance.

[lsan] Add lsan support for loongarch64
ClosedPublic

Authored by tangyouling on Dec 8 2022, 6:08 PM.

Details

Summary

This patch enabled lsan for loongarch64 with 47-bit VMA layout.

Depends on D139619

Diff Detail

Event Timeline

tangyouling created this revision.Dec 8 2022, 6:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2022, 6:08 PM
tangyouling requested review of this revision.Dec 8 2022, 6:08 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 8 2022, 6:08 PM
tangyouling edited the summary of this revision. (Show Details)Dec 8 2022, 6:20 PM
$ cat memory-leak.c 
#include <stdlib.h>
void *p;
int main() {
  p = malloc(7);
  p = 0; // The memory is leaked here.
  return 0;
}
$ ./build/bin/clang -fsanitize=address -g memory-leak.c ; ASAN_OPTIONS=detect_leaks=1 ./a.out

=================================================================
==636379==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x555557bac158 in __interceptor_malloc /home/loongson/llvm-work/llvm-project-test3/llvm-project1/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
    #1 0x555557beb03c in main /home/loongson/llvm-work/llvm-project-test3/llvm-project1/memory-leak.c:4:7
    #2 0x7ffff23b1678  (/usr/lib64/libc.so.6+0x25678)

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).
$ ./build/bin/clang -fsanitize=leak -g memory-leak.c && ./a.out

=================================================================
==636372==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x555556a5a94c in __interceptor_malloc /home/loongson/llvm-work/llvm-project-test3/llvm-project1/compiler-rt/lib/lsan/lsan_interceptors.cpp:75:3
    #1 0x555556a5db0c in main /home/loongson/llvm-work/llvm-project-test3/llvm-project1/memory-leak.c:4:7
    #2 0x7ffff11c5678  (/usr/lib64/libc.so.6+0x25678)

SUMMARY: LeakSanitizer: 7 byte(s) leaked in 1 allocation(s).
$ make check-lsan
Testing Time: 38.19s
  Unsupported      : 13
  Passed           : 93
  Expectedly Failed:  2

4 warning(s) in tests
Built target check-lsan
xen0n added inline comments.Dec 8 2022, 7:09 PM
compiler-rt/lib/lsan/lsan_common.cpp
281

Since our VM layout is actually flexible, would it be better to document this, like "Support only the most common VM layout on LoongArch that allows 47 bits of user-space VMA"? Exact wording could be optimized, I'm only describing the gist here.

compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp
4 ↗(On Diff #481489)

Why unnecessarily reorder things, especially putting this in front of the standard library includes?

20–21 ↗(On Diff #481489)

Might be better to split this part of change out of the LoongArch enablement patch after all...

tangyouling added inline comments.Dec 8 2022, 7:21 PM
compiler-rt/lib/lsan/lsan_common.cpp
281

Since our VM layout is actually flexible, would it be better to document this, like "Support only the most common VM layout on LoongArch that allows 47 bits of user-space VMA"? Exact wording could be optimized, I'm only describing the gist here.

How about "Allow 47-bit user-space VMA at current"?

compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp
4 ↗(On Diff #481489)

Why unnecessarily reorder things, especially putting this in front of the standard library includes?

An automatic adjustment of the format.

20–21 ↗(On Diff #481489)

Might be better to split this part of change out of the LoongArch enablement patch after all...

OK.

xen0n added inline comments.Dec 8 2022, 8:01 PM
compiler-rt/lib/lsan/lsan_common.cpp
281

"at present"; if you plan to revisit this later for properly supporting variable VM layouts, omitting the justification is fine to me.

compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp
4 ↗(On Diff #481489)

So you mean you're actually unable to avoid this diff damage?

tangyouling added inline comments.Dec 8 2022, 10:14 PM
compiler-rt/lib/lsan/lsan_common.cpp
281

Support for variable VM layout has not been planned for some time.

compiler-rt/test/asan/TestCases/Linux/leak_check_segv.cpp
4 ↗(On Diff #481489)

I will try to avoid this unnecessary auto-formatting.

  • Separate leak_check_segv.cpp modification.
  • Add some comments.
tangyouling edited the summary of this revision. (Show Details)Dec 9 2022, 12:04 AM
SixWeining added inline comments.Dec 9 2022, 12:13 AM
compiler-rt/test/lsan/TestCases/swapcontext.cpp
8

Why we are here? For the same reason as Android mentioned above?

tangyouling added inline comments.Dec 9 2022, 1:57 AM
compiler-rt/test/lsan/TestCases/swapcontext.cpp
8

Not for that reason.
Test passed when adding a sleep() in Child(), but not quite sure what the reason is?

 void Child() {
   int child_stack;
+  sleep(1);
   printf("Child: %p\n", &child_stack);

Please rebase code for test errors.

rebase code.

LGTM. Is there any objection?

MaskRay accepted this revision.Jan 12 2023, 10:27 AM

LGTM.

This revision is now accepted and ready to land.Jan 12 2023, 10:27 AM
This revision was automatically updated to reflect the committed changes.