Port-sparc64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Any volunteers to fix ASAN on sparc64?



Hey folks,

the address space sanitizer in gcc in -current does not work on sparc64.

To test set ASAN_OPTIONS to "verbosity=2" in your environment,
disable ASLR by sysctl -w security.pax.aslr.global=0 and
then with test.c being a typical hello world program:

	cc -O2 -Wall -fsanitize=address -g test.c
	./a.out

The result will not run, which is (I think) due to the VA layout assumed
by the sparc64 parts of the asan code to be that of more modern T4 or
similar processors, while we need it to run on the old VA layout for
Ultrasparc I machines.

I tried to patch that (see below), but ran out of time getting it to
work. This would be really helpfull to have working before the netbsd-10
branch - any takers?

Martin


Index: asan/asan_mapping.h
===================================================================
RCS file: /cvsroot/src/external/gpl3/gcc/dist/libsanitizer/asan/asan_mapping.h,v
retrieving revision 1.10
diff -u -p -r1.10 asan_mapping.h
--- asan/asan_mapping.h	11 Apr 2021 23:54:25 -0000	1.10
+++ asan/asan_mapping.h	26 Jun 2021 14:30:18 -0000
@@ -168,7 +168,14 @@ static const u64 kMIPS32_ShadowOffset32 
 static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
 static const u64 kPPC64_ShadowOffset64 = 1ULL << 41;
 static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52;
+
+#ifdef __NetBSD__
+// should be (VMA_BITS-8), but that is not always available here
+static const u64 kSPARC64_ShadowOffset64 = 1ULL << 35;	// see VMA_BITS
+#else
 static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43;  // 0x80000000000
+#endif
+
 static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30;  // 0x40000000
 static const u64 kFreeBSD_ShadowOffset64 = 1ULL << 46;  // 0x400000000000
 static const u64 kNetBSD_ShadowOffset32 = 1ULL << 30;  // 0x40000000
Index: asan/asan_mapping_sparc64.h
===================================================================
RCS file: /cvsroot/src/external/gpl3/gcc/dist/libsanitizer/asan/asan_mapping_sparc64.h,v
retrieving revision 1.2
diff -u -p -r1.2 asan_mapping_sparc64.h
--- asan/asan_mapping_sparc64.h	11 Apr 2021 23:54:25 -0000	1.2
+++ asan/asan_mapping_sparc64.h	26 Jun 2021 14:30:18 -0000
@@ -18,7 +18,13 @@
 //   0xfff8000000000000 - 0xffffffffffffffff
 //   0x0000000000000000 - 0x0007ffffffffffff
 
+#ifdef __NetBSD__
+// needs to run on UltraSparc I, so above VA split is not on bit 52, but
+// already on bit 44
+#define VMA_BITS 44
+#else
 #define VMA_BITS 52
+#endif
 #define HIGH_BITS (64 - VMA_BITS)
 
 // The idea is to chop the high bits before doing the scaling, so the two
Index: asan/asan_poisoning.cc
===================================================================
RCS file: /cvsroot/src/external/gpl3/gcc/dist/libsanitizer/asan/asan_poisoning.cc,v
retrieving revision 1.3
diff -u -p -r1.3 asan_poisoning.cc
--- asan/asan_poisoning.cc	11 Apr 2021 23:54:25 -0000	1.3
+++ asan/asan_poisoning.cc	26 Jun 2021 14:30:18 -0000
@@ -32,6 +32,8 @@ bool CanPoisonMemory() {
 void PoisonShadow(uptr addr, uptr size, u8 value) {
   if (value && !CanPoisonMemory()) return;
   CHECK(AddrIsAlignedByGranularity(addr));
+  if (!AddrIsInMem(addr))
+    Printf("PoisonShadow(addr: %p, size: %zx, value: %x) - addr out of range\n", (void*)addr, size, value);
   CHECK(AddrIsInMem(addr));
   CHECK(AddrIsAlignedByGranularity(addr + size));
   CHECK(AddrIsInMem(addr + size - SHADOW_GRANULARITY));
Index: asan/asan_shadow_setup.cc
===================================================================
RCS file: /cvsroot/src/external/gpl3/gcc/dist/libsanitizer/asan/asan_shadow_setup.cc,v
retrieving revision 1.3
diff -u -p -r1.3 asan_shadow_setup.cc
--- asan/asan_shadow_setup.cc	11 Apr 2021 23:54:25 -0000	1.3
+++ asan/asan_shadow_setup.cc	26 Jun 2021 14:30:18 -0000
@@ -27,8 +27,16 @@ namespace __asan {
 void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name) {
   CHECK_EQ((beg % GetMmapGranularity()), 0);
   CHECK_EQ(((end + 1) % GetMmapGranularity()), 0);
+
+Report("ReserveShadowMemoryRange: beg: 0x%zx, end: 0x%zx, name: %s\n",
+    beg, end, name);
+
   uptr size = end - beg + 1;
+
+Report("ReserveShadowMemoryRange: size: 0x%zx\n", size);
+
   DecreaseTotalMmap(size);  // Don't count the shadow against mmap_limit_mb.
+
   if (!MmapFixedNoReserve(beg, size, name)) {
     Report(
         "ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. "



Home | Main Index | Thread Index | Old Index