From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 83A2D38515FE for ; Fri, 1 Jul 2022 12:58:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83A2D38515FE Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id A07A166837; Fri, 1 Jul 2022 08:58:56 -0400 (EDT) Message-ID: Subject: Re: [PATCH] Mips: Resolve build issues for the n32 ABI From: Xi Ruoyao To: Dimitrije Milosevic , "gcc-patches@gcc.gnu.org" Cc: Djordje Todorovic , Richard Sandiford Date: Fri, 01 Jul 2022 20:58:54 +0800 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.2 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_SUSPICIOUS_NTLD, GIT_PATCH_0, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP, T_PDS_OTHER_BAD_TLD, 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: Fri, 01 Jul 2022 12:59:00 -0000 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 reas= ons: > - 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 wi= th 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 wor= d 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/sys= calls/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 * sani= tizer_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 b= uild 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 * sani= tizer_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. > --- >=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/libsanit= izer/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/st= at.h. To > =C2=A0// access stat from asm/stat.h, without conflicting with definition= 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_P= RIVATE_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 SANITIZE= R_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 SANITIZE= R_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 (defined= (__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)pa= th, (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 || SANIT= IZER_X32 > +#=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if SANITIZER_WORDSIZE =3D=3D 64 || SANIT= IZER_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, (uptr= )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)pa= th, (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, (uptr= )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_FRAM= E()) + 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/libsani= tizer/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 > --- --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University