From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 0B75D3858C20 for ; Fri, 1 Jul 2022 08:33:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B75D3858C20 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 290EF66A1B; Fri, 1 Jul 2022 04:33:52 -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 Date: Fri, 01 Jul 2022 16:33:51 +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=-8.6 required=5.0 tests=BAYES_00, 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 08:33:58 -0000 Please configure your mail client to send the patch as plain text (not HTML, and don't replace a tab with 8 whitespaces, etc). If it's not possible, send the patch as an attachment. And, it's better to separate the changes in https://reviews.llvm.org/D127098 and struct_kernel_stat_sz into two patches, one just "cherry-pick LLVM commit aabbccdd...", another changes struct_kernel_stat_sz. It would make the reviewing and tracking of changes easier. On Fri, 2022-07-01 at 08:18 +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), was still used in some places. > Therefore, defined(__mips64) is swapped with SANITIZER_MIPS64, which take= s the ABI into account as well - defined(__mips64) && _MIPS_SIM =3D=3D ABI6= 4. > - 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 (https://reviews.llvm.or= g/D124212), the n32 ABI still didn't use them, even though they are support= ed, > as per https://github.com/torvalds/linux/blob/master/arch/mips/kernel/sys= calls/syscall_n32.tbl. > - struct_kernel_stat_sz was not updated after being changed in LLVM's sou= rce tree. >=20 > See https://reviews.llvm.org/D127098. > =C2=A0 =C2=A0=20 > libsanitizer/ChangeLog: >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 * sanitizer_common/sanitizer_linux.cpp (defin= ed): Resolve > =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 ASAN build issues for the n32 ABI. > =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * sanitizer_common/sanitizer_platform.h = (defined): Likewise. > =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * sanitizer_common/sanitizer_platform_li= mits_posix.h: Likewise. >=20 > --- >=20 > =C2=A0libsanitizer/sanitizer_common/sanitizer_linux.cpp =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 17 ++++++++++------- > =C2=A0libsanitizer/sanitizer_common/sanitizer_platform.h =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A02 +- > =C2=A0libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h | = =C2=A02 +- > =C2=A03 files changed, 12 insertions(+), 9 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=A0SANITIZER_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=A0SANITIZER_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(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=A0return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)pa= th, (uptr)buf, 0); > =C2=A0# =C2=A0 =C2=A0elif SANITIZER_LINUX > -# =C2=A0 =C2=A0 =C2=A0if SANITIZER_WORDSIZE =3D=3D 64 || SANITIZER_X32 > +# =C2=A0 =C2=A0 =C2=A0if SANITIZER_WORDSIZE =3D=3D 64 || SANITIZER_X32 |= | \ > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(defined(__mips__) && _MIPS_SIM =3D= =3D _ABIN32) > =C2=A0 =C2=A0return 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=A00); > =C2=A0# =C2=A0 =C2=A0 =C2=A0else > @@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) { > =C2=A0 =C2=A0return 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=A0AT_SYMLINK_NOFOLLOW); > =C2=A0# =C2=A0 =C2=A0elif SANITIZER_LINUX > -# =C2=A0 =C2=A0 =C2=A0if defined(_LP64) || SANITIZER_X32 > +# =C2=A0 =C2=A0 =C2=A0if defined(_LP64) || SANITIZER_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=A0return 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=A0AT_SYMLINK_NOFOLLOW); > =C2=A0# =C2=A0 =C2=A0 =C2=A0else > @@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() { > =C2=A0 =C2=A0return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAM= E()) + 1)) - 1; > =C2=A0#elif SANITIZER_RISCV64 > =C2=A0 =C2=A0return (1ULL << 38) - 1; > -# elif defined(__mips64) > +# elif SANITIZER_MIPS64 > =C2=A0 =C2=A0return (1ULL << 40) - 1; =C2=A0// 0x000000ffffffffffUL; > =C2=A0# elif defined(__s390x__) > =C2=A0 =C2=A0return (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=A0define SANITIZER_MIPS 1 > -# =C2=A0if defined(__mips64) > +# =C2=A0if defined(__mips64) && _MIPS_SIM =3D=3D _ABI64 > =C2=A0# =C2=A0 =C2=A0define SANITIZER_MIPS32 0 > =C2=A0# =C2=A0 =C2=A0define SANITIZER_MIPS64 1 > =C2=A0# =C2=A0else > diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posi= x.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h > index 89772a7e5c0..62a99035db3 100644 > --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h > +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h > @@ -83,7 +83,7 @@ const unsigned struct_kernel_stat64_sz =3D 104; > =C2=A0#elif defined(__mips__) > =C2=A0const unsigned struct_kernel_stat_sz =3D SANITIZER_ANDROID > =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 ? FIRST_32_SECOND_64(104, 128) > - =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 : FIRST_32_SECOND_64(144, 216); > + =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 : FIRST_32_SECOND_64(160, 216); > =C2=A0const unsigned struct_kernel_stat64_sz =3D 104; > =C2=A0#elif defined(__s390__) && !defined(__s390x__) > =C2=A0const unsigned struct_kernel_stat_sz =3D 64; >=20 > --- --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University