Hi, This small patch enables libsanitizer on ARM. It has been tested successfully on cortex-a9 hardware (via the GCC testsuite).
I have chosen to bundle -funwind-table with -fsanitize=* so that a useful backtrace can be printed to the user in case of error, otherwise the reporting is limited to one line belonging to libsanitizer.so. Note that the testsuite currently fails when executing under qemu: - support of /proc/self/maps does not conform to the kernel format. One extra space is missing from some lines, which confuses libsanitizer. Patch proposed to upstream qemu: http://lists.gnu.org/archive/html/qemu-devel/2013-02/msg03051.html - qemu reserves some memory space by default, conflicting with libsanitizer needs. Workaround: invoke qemu with -R 0 - libsanitizer detects if its output is a tty, and when GCC testsuite is executed under qemu, libsanitizer concludes that it is actually running under a tty, and adds beautyfying characters which confuse dejanu. OK? Christophe. 2013-03-27 Christophe Lyon <christophe.l...@linaro.org> gcc/ * config/arm/arm.c (arm_asan_shadow_offset): New function. (TARGET_ASAN_SHADOW_OFFSET): Define. * config/arm/linux-eabi.h (ASAN_CC1_SPEC): Define. (LINUX_OR_ANDROID_CC): Add ASAN_CC1_SPEC. libsanitizer/ * configure.tgt: Add ARM pattern.
=== modified file 'gcc/config/arm/arm.c' --- gcc/config/arm/arm.c 2013-02-28 10:26:41 +0000 +++ gcc/config/arm/arm.c 2013-03-04 08:39:02 +0000 @@ -280,6 +280,8 @@ static void arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1, bool op0_preserve_value); +static unsigned HOST_WIDE_INT arm_asan_shadow_offset (void); + /* Table of machine attributes. */ static const struct attribute_spec arm_attribute_table[] = @@ -649,6 +651,9 @@ #define TARGET_CANONICALIZE_COMPARISON \ arm_canonicalize_comparison +#undef TARGET_ASAN_SHADOW_OFFSET +#define TARGET_ASAN_SHADOW_OFFSET arm_asan_shadow_offset + struct gcc_target targetm = TARGET_INITIALIZER; /* Obstack for minipool constant handling. */ @@ -27393,4 +27398,12 @@ } +/* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ + +static unsigned HOST_WIDE_INT +arm_asan_shadow_offset (void) +{ + return (unsigned HOST_WIDE_INT) 1 << 29; +} + #include "gt-arm.h" === modified file 'gcc/config/arm/linux-eabi.h' --- gcc/config/arm/linux-eabi.h 2013-01-10 20:38:27 +0000 +++ gcc/config/arm/linux-eabi.h 2013-03-26 09:59:11 +0000 @@ -84,10 +84,14 @@ LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \ LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC) +#undef ASAN_CC1_SPEC +#define ASAN_CC1_SPEC "%{fsanitize=*:-funwind-tables}" + #undef CC1_SPEC #define CC1_SPEC \ - LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \ - GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC) + LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC, \ + GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " " \ + ANDROID_CC1_SPEC) #define CC1PLUS_SPEC \ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC) === modified file 'libsanitizer/configure.tgt' --- libsanitizer/configure.tgt 2013-02-11 23:13:37 +0000 +++ libsanitizer/configure.tgt 2013-03-04 08:39:02 +0000 @@ -29,6 +29,8 @@ ;; sparc*-*-linux*) ;; + arm*-*-linux*) + ;; x86_64-*-darwin[1]* | i?86-*-darwin[1]*) TSAN_SUPPORTED=no ;;