Page MenuHomePhabricator

Port asan to FreeBSD AArch64
Needs ReviewPublic

Authored by andrew on Apr 18 2017, 9:20 AM.

Details

Summary

Add the compiler-rt support for running AddressSanitizer on FreeBSD on AArch64. FreeBSD only uses a 48-bit address space on arm64. It also currently lacks a method for exposing the esr register to a signal handler.

The esr issue is expected to be fixed soon, however until then there is no way to query it.

Diff Detail

Repository
rL LLVM

Event Timeline

andrew created this revision.Apr 18 2017, 9:20 AM
andrew added a comment.May 9 2017, 9:01 AM

Is there any feedback on this?

dim added a comment.EditedMay 27 2017, 6:51 AM

Unfortunately it does not yet compile on FreeBSD 12/arm64, as there is a problem with the system header <machine/pmap.h>:

In file included from /home/dim/src/llvm-trunk/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc:66:
In file included from /usr/include/vm/pmap.h:90:
/usr/include/machine/pmap.h:57:28: error: unknown type name 'vm_page_t'
void pmap_page_set_memattr(vm_page_t m, vm_memattr_t ma);
                           ^
/usr/include/machine/pmap.h:57:41: error: unknown type name 'vm_memattr_t'
void pmap_page_set_memattr(vm_page_t m, vm_memattr_t ma);
                                        ^
/usr/include/machine/pmap.h:66:2: error: unknown type name 'vm_memattr_t'
        vm_memattr_t            pv_memattr;
        ^
3 errors generated.

I've now tried commenting out the inclusion of <vm/pmap.h>, to side-step the issue. It's still building...

dim added a comment.May 27 2017, 7:13 AM

It turns out I added the <vm/pmap.h> inclusion in rL263157, but it and the two other headers are not needed anymore, as the following diff at least makes it compile:

--- lib/sanitizer_common/sanitizer_linux.cc     (revision 303869)
+++ lib/sanitizer_common/sanitizer_linux.cc     (working copy)
@@ -60,10 +60,7 @@
 #include <unistd.h>

 #if SANITIZER_FREEBSD
-#include <sys/exec.h>
 #include <sys/sysctl.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
 #include <machine/atomic.h>
 extern "C" {
 // <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on
dim added a comment.May 27 2017, 7:16 AM

Actually the <sys/exec.h> header is still needed for the ps_string usage later in the file, so the diff becomes:

--- lib/sanitizer_common/sanitizer_linux.cc     (revision 303869)
+++ lib/sanitizer_common/sanitizer_linux.cc     (working copy)
@@ -62,8 +62,6 @@
 #if SANITIZER_FREEBSD
 #include <sys/exec.h>
 #include <sys/sysctl.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
 #include <machine/atomic.h>
 extern "C" {
 // <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on
dim added a comment.May 27 2017, 9:33 AM

With that last patch, I get the following test results, which are not greatly different from those on x86:

********************
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 2319.27s
********************
Failing Tests (27):
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.AllocAndRelease/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.AllocAndRelease/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.DuplicateNear/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.DuplicateNear/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.EnabledWrite/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.EnabledWrite/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.MultipleAllocAndRelease/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.MultipleAllocAndRelease/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.SuccessiveNear/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.SuccessiveNear/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.UnalignedNear/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.UnalignedNear/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.ZeroNear/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.ZeroNear/4
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.ZeroSizeNear/3
    LLVM-Unit :: Support/SupportTests/AllocationTests/MappedMemoryTest.ZeroSizeNear/4
    LLVM-Unit :: Support/SupportTests/FileSystemTest.permissions
    AddressSanitizer-aarch64-freebsd :: TestCases/Posix/asan-sigbus.cpp
    AddressSanitizer-aarch64-freebsd :: TestCases/Posix/fread_fwrite.cc
    AddressSanitizer-aarch64-freebsd :: TestCases/Posix/strerror_r_test.cc
    AddressSanitizer-aarch64-freebsd :: TestCases/Posix/waitid.cc
    AddressSanitizer-aarch64-freebsd :: TestCases/throw_invoke_test.cc
    SafeStack :: buffer-copy-vla.c
    SafeStack :: buffer-copy.c
    SafeStack :: init.c
    SafeStack :: pthread-cleanup.c
    SafeStack :: pthread.c

  Expected Passes    : 20117
  Expected Failures  : 54
  Unsupported Tests  : 12556
  Unexpected Failures: 27

2 warning(s) in tests.
emaste added a reviewer: kcc.Nov 20 2017, 6:27 PM
bsdjhb added a subscriber: bsdjhb.Jul 27 2018, 3:01 PM
bsdjhb added inline comments.
lib/sanitizer_common/sanitizer_linux_libcdep.cc
329

aarch64 on FreeBSD uses TLS variant I and the code futher below assumes Variant II used on x86. You might be able to add reuse the variant I code I have in the FreeBSD/mips64 ASAN patch though for this.