From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id B9138385609A for ; Mon, 4 Jul 2022 11:23:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9138385609A Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9A8D123A; Mon, 4 Jul 2022 04:23:25 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 486C53F66F; Mon, 4 Jul 2022 04:23:24 -0700 (PDT) From: Richard Sandiford To: Xi Ruoyao via Gcc-patches Mail-Followup-To: Xi Ruoyao via Gcc-patches , Dimitrije Milosevic , Xi Ruoyao , Djordje Todorovic , richard.sandiford@arm.com Cc: Dimitrije Milosevic , Xi Ruoyao , Djordje Todorovic Subject: Re: [PATCH] Mips: Resolve build issues for the n32 ABI References: Date: Mon, 04 Jul 2022 12:23:23 +0100 In-Reply-To: (Xi Ruoyao via Gcc-patches's message of "Fri, 01 Jul 2022 20:58:54 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-54.0 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 11:23:27 -0000 Xi Ruoyao via Gcc-patches writes: > On Fri, 2022-07-01 at 12:40 +0000, Dimitrije Milosevic wrote: >> Building the ASAN for the n32 MIPS ABI currently fails, due to a few rea= sons: >> - defined(__mips64), which is set solely based on the architecture type = (32-bit/64-bit),=20 >> was still used in some places. Therefore, defined(__mips64) is swapped w= ith SANITIZER_MIPS64,=20 >> which takes the ABI into account as well - defined(__mips64) &&=20 >> _MIPS_SIM =3D=3D ABI64. >> - The n32 ABI still uses 64-bit *Linux* system calls, even though the wo= rd size is 32 bits. >> - After the transition to canonical system calls=20 >> (https://reviews.llvm.org/D124212), the n32 ABI still didn't use them, >> even though they are supported, >> as per https://github.com/torvalds/linux/blob/master/arch/mips/kernel/sy= scalls/syscall_n32.tbl. >>=20 >> See https://reviews.llvm.org/D127098. >>=20 >> =C2=A0=C2=A0=C2=A0 libsanitizer/ChangeLog: >> =C2=A0=C2=A0=C2=A0=20 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * san= itizer_common/sanitizer_linux.cpp (defined): Resolve >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ASAN = build issues for the Mips n32 ABI. >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * san= itizer_common/sanitizer_platform.h (defined): Likewise. > > LGTM (with the ChangeLog format fixed), but I think you need to commit > this into LLVM repository first. And in the commit message you should > say something like "cherry-pick 0011aabb... from upstream". Then we > still require the approve from a maintainer. You know this area far better than I do, so: rubber-stamp OK for cherry-picking the patch into GCC once it's in LLVM. Thanks, Richard > >> --- >>=20 >> =C2=A0libsanitizer/sanitizer_common/sanitizer_linux.cpp=C2=A0 | 17 +++++= +++++------- >> =C2=A0libsanitizer/sanitizer_common/sanitizer_platform.h |=C2=A0 2 +- >> =C2=A02 files changed, 11 insertions(+), 8 deletions(-) >>=20 >> diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsani= tizer/sanitizer_common/sanitizer_linux.cpp >> index e2c32d679ad..5ba033492e7 100644 >> --- a/libsanitizer/sanitizer_common/sanitizer_linux.cpp >> +++ b/libsanitizer/sanitizer_common/sanitizer_linux.cpp >> @@ -34,7 +34,7 @@ >> =C2=A0// format. Struct kernel_stat is defined as 'struct stat' in asm/s= tat.h. To >> =C2=A0// access stat from asm/stat.h, without conflicting with definitio= n in >> =C2=A0// sys/stat.h, we use this trick. >> -#if defined(__mips64) >> +#if SANITIZER_MIPS64 >> =C2=A0#include >> =C2=A0#include >> =C2=A0#define stat kernel_stat >> @@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE =3D FUTEX_WAKE | FUTEX_= PRIVATE_FLAG; >> =C2=A0// Are we using 32-bit or 64-bit Linux syscalls? >> =C2=A0// x32 (which defines __x86_64__) has SANITIZER_WORDSIZE =3D=3D 32 >> =C2=A0// but it still needs to use 64-bit syscalls. >> -#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) |= |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SANIT= IZER_WORDSIZE =3D=3D 64) >> +#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) |= | \ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SANIT= IZER_WORDSIZE =3D=3D 64 ||=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 \ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (defi= ned(__mips__) && _MIPS_SIM =3D=3D _ABIN32)) >> =C2=A0# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1 >> =C2=A0#else >> =C2=A0# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0 >> @@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct= stat *out) { >> =C2=A0} >> =C2=A0#endif >> =C2=A0 >> -#if defined(__mips64) >> +#if SANITIZER_MIPS64 >> =C2=A0// Undefine compatibility macros from >> =C2=A0// so that they would not clash with the kernel_stat >> =C2=A0// st_[a|m|c]time fields >> @@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) { >> =C2=A0#if SANITIZER_FREEBSD >> =C2=A0=C2=A0 return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)p= ath, (uptr)buf, 0); >> =C2=A0#=C2=A0=C2=A0=C2=A0 elif SANITIZER_LINUX >> -#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if SANITIZER_WORDSIZE =3D=3D 64 || SANI= TIZER_X32 >> +#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if SANITIZER_WORDSIZE =3D=3D 64 || SANI= TIZER_X32 || \ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (defined(__mips_= _) && _MIPS_SIM =3D=3D _ABIN32) >> =C2=A0=C2=A0 return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (upt= r)path, (uptr)buf, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 0); >> =C2=A0#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else >> @@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) { >> =C2=A0=C2=A0 return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)p= ath, (uptr)buf, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 AT_SYMLINK_NOFOLLOW); >> =C2=A0#=C2=A0=C2=A0=C2=A0 elif SANITIZER_LINUX >> -#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if defined(_LP64) || SANITIZER_X32 >> +#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if defined(_LP64) || SANITIZER_X32 ||= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (defined(__mips_= _) && _MIPS_SIM =3D=3D _ABIN32) >> =C2=A0=C2=A0 return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (upt= r)path, (uptr)buf, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 AT_SYMLINK_NOFOLLOW); >> =C2=A0#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else >> @@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() { >> =C2=A0=C2=A0 return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRA= ME()) + 1)) - 1; >> =C2=A0#elif SANITIZER_RISCV64 >> =C2=A0=C2=A0 return (1ULL << 38) - 1; >> -# elif defined(__mips64) >> +# elif SANITIZER_MIPS64 >> =C2=A0=C2=A0 return (1ULL << 40) - 1;=C2=A0 // 0x000000ffffffffffUL; >> =C2=A0# elif defined(__s390x__) >> =C2=A0=C2=A0 return (1ULL << 53) - 1;=C2=A0 // 0x001fffffffffffffUL; >> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsan= itizer/sanitizer_common/sanitizer_platform.h >> index 8fe0d831431..8bd9a327623 100644 >> --- a/libsanitizer/sanitizer_common/sanitizer_platform.h >> +++ b/libsanitizer/sanitizer_common/sanitizer_platform.h >> @@ -159,7 +159,7 @@ >> =C2=A0 >> =C2=A0#if defined(__mips__) >> =C2=A0#=C2=A0 define SANITIZER_MIPS 1 >> -#=C2=A0 if defined(__mips64) >> +#=C2=A0 if defined(__mips64) && _MIPS_SIM =3D=3D _ABI64 >> =C2=A0#=C2=A0=C2=A0=C2=A0 define SANITIZER_MIPS32 0 >> =C2=A0#=C2=A0=C2=A0=C2=A0 define SANITIZER_MIPS64 1 >> =C2=A0#=C2=A0 else >>=20 >> ---