gcc/ChangeLog: PR target/106828 * config/loongarch/loongarch.cc (loongarch_asan_shadow_offset): New. (TARGET_ASAN_SHADOW_OFFSET): New.
gcc/testsuite/ChangeLog: PR target/106828 * g++.target/loongarch/pr106828.C: New test. --- gcc/config/loongarch/loongarch.cc | 14 ++++++++++++++ gcc/testsuite/g++.target/loongarch/pr106828.C | 4 ++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/g++.target/loongarch/pr106828.C diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 10acf06ef79..58f92e05796 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -6471,6 +6471,17 @@ loongarch_use_anchors_for_symbol_p (const_rtx symbol) return default_use_anchors_for_symbol_p (symbol); } +/* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ + +static unsigned HOST_WIDE_INT +loongarch_asan_shadow_offset (void) +{ + /* We only have libsanitizer support for LOONGARCH64 at present. + This value is obtained from 'LowShadow' in the file + libsanitizer/asan/asan_mappint.h for Linux/LoongArch64. */ + return TARGET_64BIT ? (HOST_WIDE_INT_1 << 38) : 0; +} + /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" @@ -6665,6 +6676,9 @@ loongarch_use_anchors_for_symbol_p (const_rtx symbol) #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P #define TARGET_USE_ANCHORS_FOR_SYMBOL_P loongarch_use_anchors_for_symbol_p +#undef TARGET_ASAN_SHADOW_OFFSET +#define TARGET_ASAN_SHADOW_OFFSET loongarch_asan_shadow_offset + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-loongarch.h" diff --git a/gcc/testsuite/g++.target/loongarch/pr106828.C b/gcc/testsuite/g++.target/loongarch/pr106828.C new file mode 100644 index 00000000000..190c1db715f --- /dev/null +++ b/gcc/testsuite/g++.target/loongarch/pr106828.C @@ -0,0 +1,4 @@ +/* { dg-do-preprocess } */ +/* { dg-options "-mabi=lp64d -fsanitize=address" } */ + +/* Tests whether the compiler supports compile option '-fsanitize=address'. */ -- 2.31.1