* [PATCH] Mips: Resolve build issues for the n32 ABI
@ 2022-07-01 12:40 Dimitrije Milosevic
2022-07-01 12:58 ` Xi Ruoyao
0 siblings, 1 reply; 9+ messages in thread
From: Dimitrije Milosevic @ 2022-07-01 12:40 UTC (permalink / raw)
To: gcc-patches; +Cc: Djordje Todorovic, xry111
Building the ASAN for the n32 MIPS ABI currently fails, due to a few reasons:
- 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 takes the ABI into account as well - defined(__mips64) &&
_MIPS_SIM == ABI64.
- The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
- After the transition to canonical system calls
(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/syscalls/syscall_n32.tbl.
See https://reviews.llvm.org/D127098.
libsanitizer/ChangeLog:
* sanitizer_common/sanitizer_linux.cpp (defined): Resolve
ASAN build issues for the Mips n32 ABI.
* sanitizer_common/sanitizer_platform.h (defined): Likewise.
---
libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
// format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
// access stat from asm/stat.h, without conflicting with definition in
// sys/stat.h, we use this trick.
-#if defined(__mips64)
+#if SANITIZER_MIPS64
#include <asm/unistd.h>
#include <sys/types.h>
#define stat kernel_stat
@@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
// Are we using 32-bit or 64-bit Linux syscalls?
// x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
// but it still needs to use 64-bit syscalls.
-#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
- SANITIZER_WORDSIZE == 64)
+#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
+ SANITIZER_WORDSIZE == 64 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32))
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
#else
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
@@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
}
#endif
-#if defined(__mips64)
+#if SANITIZER_MIPS64
// Undefine compatibility macros from <sys/stat.h>
// so that they would not clash with the kernel_stat
// st_[a|m|c]time fields
@@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
#if SANITIZER_FREEBSD
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
# elif SANITIZER_LINUX
-# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
+# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
0);
# else
@@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# elif SANITIZER_LINUX
-# if defined(_LP64) || SANITIZER_X32
+# if defined(_LP64) || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# else
@@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
#elif SANITIZER_RISCV64
return (1ULL << 38) - 1;
-# elif defined(__mips64)
+# elif SANITIZER_MIPS64
return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
# elif defined(__s390x__)
return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
#if defined(__mips__)
# define SANITIZER_MIPS 1
-# if defined(__mips64)
+# if defined(__mips64) && _MIPS_SIM == _ABI64
# define SANITIZER_MIPS32 0
# define SANITIZER_MIPS64 1
# else
---
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-01 12:40 [PATCH] Mips: Resolve build issues for the n32 ABI Dimitrije Milosevic
@ 2022-07-01 12:58 ` Xi Ruoyao
2022-07-01 14:32 ` Dimitrije Milosevic
2022-07-04 11:23 ` Richard Sandiford
0 siblings, 2 replies; 9+ messages in thread
From: Xi Ruoyao @ 2022-07-01 12:58 UTC (permalink / raw)
To: Dimitrije Milosevic, gcc-patches; +Cc: Djordje Todorovic, Richard Sandiford
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 reasons:
> - 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 takes the ABI into account as well - defined(__mips64) &&
> _MIPS_SIM == ABI64.
> - The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
> - After the transition to canonical system calls
> (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/syscalls/syscall_n32.tbl.
>
> See https://reviews.llvm.org/D127098.
>
> libsanitizer/ChangeLog:
>
> * sanitizer_common/sanitizer_linux.cpp (defined): Resolve
> ASAN build issues for the Mips n32 ABI.
> * sanitizer_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.
> ---
>
> libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
> libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
> 2 files changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
> // format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
> // access stat from asm/stat.h, without conflicting with definition in
> // sys/stat.h, we use this trick.
> -#if defined(__mips64)
> +#if SANITIZER_MIPS64
> #include <asm/unistd.h>
> #include <sys/types.h>
> #define stat kernel_stat
> @@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
> // Are we using 32-bit or 64-bit Linux syscalls?
> // x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
> // but it still needs to use 64-bit syscalls.
> -#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
> - SANITIZER_WORDSIZE == 64)
> +#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
> + SANITIZER_WORDSIZE == 64 || \
> + (defined(__mips__) && _MIPS_SIM == _ABIN32))
> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
> #else
> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
> @@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
> }
> #endif
>
> -#if defined(__mips64)
> +#if SANITIZER_MIPS64
> // Undefine compatibility macros from <sys/stat.h>
> // so that they would not clash with the kernel_stat
> // st_[a|m|c]time fields
> @@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
> #if SANITIZER_FREEBSD
> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
> # elif SANITIZER_LINUX
> -# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
> +# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
> 0);
> # else
> @@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
> AT_SYMLINK_NOFOLLOW);
> # elif SANITIZER_LINUX
> -# if defined(_LP64) || SANITIZER_X32
> +# if defined(_LP64) || SANITIZER_X32 || \
> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
> AT_SYMLINK_NOFOLLOW);
> # else
> @@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
> return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
> #elif SANITIZER_RISCV64
> return (1ULL << 38) - 1;
> -# elif defined(__mips64)
> +# elif SANITIZER_MIPS64
> return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
> # elif defined(__s390x__)
> return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
>
> #if defined(__mips__)
> # define SANITIZER_MIPS 1
> -# if defined(__mips64)
> +# if defined(__mips64) && _MIPS_SIM == _ABI64
> # define SANITIZER_MIPS32 0
> # define SANITIZER_MIPS64 1
> # else
>
> ---
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-01 12:58 ` Xi Ruoyao
@ 2022-07-01 14:32 ` Dimitrije Milosevic
2022-07-04 11:23 ` Richard Sandiford
1 sibling, 0 replies; 9+ messages in thread
From: Dimitrije Milosevic @ 2022-07-01 14:32 UTC (permalink / raw)
To: Xi Ruoyao, gcc-patches; +Cc: Djordje Todorovic, Richard Sandiford
Thanks Xi. Forgive me as I'm not that familiar with the coding standards
when submitting patches for a review.
Here is the updated version of the patch.
Building the ASAN for the n32 MIPS ABI currently fails, due to a few reasons:
- 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 takes the ABI into account as well - defined(__mips64) &&
_MIPS_SIM == ABI64.
- The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
- After the transition to canonical system calls
(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/syscalls/syscall_n32.tbl.
See https://reviews.llvm.org/D127098.
libsanitizer/ChangeLog:
* sanitizer_common/sanitizer_linux.cpp (defined): Resolve
ASAN build issues for the Mips n32 ABI.
* sanitizer_common/sanitizer_platform.h (defined): Likewise.
---
libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
// format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
// access stat from asm/stat.h, without conflicting with definition in
// sys/stat.h, we use this trick.
-#if defined(__mips64)
+#if SANITIZER_MIPS64
#include <asm/unistd.h>
#include <sys/types.h>
#define stat kernel_stat
@@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
// Are we using 32-bit or 64-bit Linux syscalls?
// x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
// but it still needs to use 64-bit syscalls.
-#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
- SANITIZER_WORDSIZE == 64)
+#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
+ SANITIZER_WORDSIZE == 64 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32))
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
#else
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
@@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
}
#endif
-#if defined(__mips64)
+#if SANITIZER_MIPS64
// Undefine compatibility macros from <sys/stat.h>
// so that they would not clash with the kernel_stat
// st_[a|m|c]time fields
@@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
#if SANITIZER_FREEBSD
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
# elif SANITIZER_LINUX
-# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
+# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
0);
# else
@@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# elif SANITIZER_LINUX
-# if defined(_LP64) || SANITIZER_X32
+# if defined(_LP64) || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# else
@@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
#elif SANITIZER_RISCV64
return (1ULL << 38) - 1;
-# elif defined(__mips64)
+# elif SANITIZER_MIPS64
return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
# elif defined(__s390x__)
return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
#if defined(__mips__)
# define SANITIZER_MIPS 1
-# if defined(__mips64)
+# if defined(__mips64) && _MIPS_SIM == _ABI64
# define SANITIZER_MIPS32 0
# define SANITIZER_MIPS64 1
# else
---
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-01 12:58 ` Xi Ruoyao
2022-07-01 14:32 ` Dimitrije Milosevic
@ 2022-07-04 11:23 ` Richard Sandiford
2022-07-06 11:34 ` Dimitrije Milosevic
1 sibling, 1 reply; 9+ messages in thread
From: Richard Sandiford @ 2022-07-04 11:23 UTC (permalink / raw)
To: Xi Ruoyao via Gcc-patches
Cc: Dimitrije Milosevic, Xi Ruoyao, Djordje Todorovic
Xi Ruoyao via Gcc-patches <gcc-patches@gcc.gnu.org> 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 reasons:
>> - 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 takes the ABI into account as well - defined(__mips64) &&
>> _MIPS_SIM == ABI64.
>> - The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
>> - After the transition to canonical system calls
>> (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/syscalls/syscall_n32.tbl.
>>
>> See https://reviews.llvm.org/D127098.
>>
>> libsanitizer/ChangeLog:
>>
>> * sanitizer_common/sanitizer_linux.cpp (defined): Resolve
>> ASAN build issues for the Mips n32 ABI.
>> * sanitizer_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
>
>> ---
>>
>> libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
>> libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
>> 2 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
>> // format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
>> // access stat from asm/stat.h, without conflicting with definition in
>> // sys/stat.h, we use this trick.
>> -#if defined(__mips64)
>> +#if SANITIZER_MIPS64
>> #include <asm/unistd.h>
>> #include <sys/types.h>
>> #define stat kernel_stat
>> @@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
>> // Are we using 32-bit or 64-bit Linux syscalls?
>> // x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
>> // but it still needs to use 64-bit syscalls.
>> -#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
>> - SANITIZER_WORDSIZE == 64)
>> +#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
>> + SANITIZER_WORDSIZE == 64 || \
>> + (defined(__mips__) && _MIPS_SIM == _ABIN32))
>> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
>> #else
>> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
>> @@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
>> }
>> #endif
>>
>> -#if defined(__mips64)
>> +#if SANITIZER_MIPS64
>> // Undefine compatibility macros from <sys/stat.h>
>> // so that they would not clash with the kernel_stat
>> // st_[a|m|c]time fields
>> @@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
>> #if SANITIZER_FREEBSD
>> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
>> # elif SANITIZER_LINUX
>> -# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
>> +# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
>> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
>> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
>> 0);
>> # else
>> @@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
>> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
>> AT_SYMLINK_NOFOLLOW);
>> # elif SANITIZER_LINUX
>> -# if defined(_LP64) || SANITIZER_X32
>> +# if defined(_LP64) || SANITIZER_X32 || \
>> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
>> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
>> AT_SYMLINK_NOFOLLOW);
>> # else
>> @@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
>> return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
>> #elif SANITIZER_RISCV64
>> return (1ULL << 38) - 1;
>> -# elif defined(__mips64)
>> +# elif SANITIZER_MIPS64
>> return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
>> # elif defined(__s390x__)
>> return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
>> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
>>
>> #if defined(__mips__)
>> # define SANITIZER_MIPS 1
>> -# if defined(__mips64)
>> +# if defined(__mips64) && _MIPS_SIM == _ABI64
>> # define SANITIZER_MIPS32 0
>> # define SANITIZER_MIPS64 1
>> # else
>>
>> ---
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-04 11:23 ` Richard Sandiford
@ 2022-07-06 11:34 ` Dimitrije Milosevic
2022-07-06 18:11 ` Xi Ruoyao
0 siblings, 1 reply; 9+ messages in thread
From: Dimitrije Milosevic @ 2022-07-06 11:34 UTC (permalink / raw)
To: Richard Sandiford, Xi Ruoyao via Gcc-patches; +Cc: Xi Ruoyao, Djordje Todorovic
Ping. :)
This change just landed on LLVM (see https://reviews.llvm.org/rG5d8077565e4196efdd4ed525a64c11a96d5aa5dd).
Unfortunately, I do not have commit access, so if anyone can commit it, that would be great!
Here is the patch with the updated commit message.
libsanitizer: Cherry-pick 5d8077565e41 from upstream
Building the ASAN for the n32 MIPS ABI currently fails, due to a few reasons:
- 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 takes the ABI into account as well - defined(__mips64) &&
_MIPS_SIM == ABI64.
- The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
- After the transition to canonical system calls
(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/syscalls/syscall_n32.tbl.
See https://reviews.llvm.org/D127098.
libsanitizer/ChangeLog:
* sanitizer_common/sanitizer_linux.cpp (defined): Resolve
ASAN build issues for the Mips n32 ABI.
* sanitizer_common/sanitizer_platform.h (defined): Likewise.
---
.../sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
.../sanitizer_common/sanitizer_platform.h | 2 +-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
// format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
// access stat from asm/stat.h, without conflicting with definition in
// sys/stat.h, we use this trick.
-#if defined(__mips64)
+#if SANITIZER_MIPS64
#include <asm/unistd.h>
#include <sys/types.h>
#define stat kernel_stat
@@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
// Are we using 32-bit or 64-bit Linux syscalls?
// x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
// but it still needs to use 64-bit syscalls.
-#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
- SANITIZER_WORDSIZE == 64)
+#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
+ SANITIZER_WORDSIZE == 64 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32))
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
#else
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
@@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
}
#endif
-#if defined(__mips64)
+#if SANITIZER_MIPS64
// Undefine compatibility macros from <sys/stat.h>
// so that they would not clash with the kernel_stat
// st_[a|m|c]time fields
@@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
#if SANITIZER_FREEBSD
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
# elif SANITIZER_LINUX
-# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
+# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
0);
# else
@@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# elif SANITIZER_LINUX
-# if defined(_LP64) || SANITIZER_X32
+# if defined(_LP64) || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# else
@@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
#elif SANITIZER_RISCV64
return (1ULL << 38) - 1;
-# elif defined(__mips64)
+# elif SANITIZER_MIPS64
return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
# elif defined(__s390x__)
return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
#if defined(__mips__)
# define SANITIZER_MIPS 1
-# if defined(__mips64)
+# if defined(__mips64) && _MIPS_SIM == _ABI64
# define SANITIZER_MIPS32 0
# define SANITIZER_MIPS64 1
# else
--
2.25.1
From: Richard Sandiford <richard.sandiford@arm.com>
Sent: Monday, July 4, 2022 1:23 PM
To: Xi Ruoyao via Gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Dimitrije Milosevic <Dimitrije.Milosevic@Syrmia.com>; Xi Ruoyao <xry111@xry111.site>; Djordje Todorovic <Djordje.Todorovic@syrmia.com>
Subject: Re: [PATCH] Mips: Resolve build issues for the n32 ABI
Xi Ruoyao via Gcc-patches <gcc-patches@gcc.gnu.org> 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 reasons:
>> - 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 takes the ABI into account as well - defined(__mips64) &&
>> _MIPS_SIM == ABI64.
>> - The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
>> - After the transition to canonical system calls
>> (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/syscalls/syscall_n32.tbl.
>>
>> See https://reviews.llvm.org/D127098.
>>
>> libsanitizer/ChangeLog:
>>
>> * sanitizer_common/sanitizer_linux.cpp (defined): Resolve
>> ASAN build issues for the Mips n32 ABI.
>> * sanitizer_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
>
>> ---
>>
>> libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
>> libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
>> 2 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
>> // format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
>> // access stat from asm/stat.h, without conflicting with definition in
>> // sys/stat.h, we use this trick.
>> -#if defined(__mips64)
>> +#if SANITIZER_MIPS64
>> #include <asm/unistd.h>
>> #include <sys/types.h>
>> #define stat kernel_stat
>> @@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
>> // Are we using 32-bit or 64-bit Linux syscalls?
>> // x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
>> // but it still needs to use 64-bit syscalls.
>> -#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
>> - SANITIZER_WORDSIZE == 64)
>> +#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
>> + SANITIZER_WORDSIZE == 64 || \
>> + (defined(__mips__) && _MIPS_SIM == _ABIN32))
>> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
>> #else
>> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
>> @@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
>> }
>> #endif
>>
>> -#if defined(__mips64)
>> +#if SANITIZER_MIPS64
>> // Undefine compatibility macros from <sys/stat.h>
>> // so that they would not clash with the kernel_stat
>> // st_[a|m|c]time fields
>> @@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
>> #if SANITIZER_FREEBSD
>> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
>> # elif SANITIZER_LINUX
>> -# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
>> +# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
>> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
>> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
>> 0);
>> # else
>> @@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
>> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
>> AT_SYMLINK_NOFOLLOW);
>> # elif SANITIZER_LINUX
>> -# if defined(_LP64) || SANITIZER_X32
>> +# if defined(_LP64) || SANITIZER_X32 || \
>> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
>> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
>> AT_SYMLINK_NOFOLLOW);
>> # else
>> @@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
>> return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
>> #elif SANITIZER_RISCV64
>> return (1ULL << 38) - 1;
>> -# elif defined(__mips64)
>> +# elif SANITIZER_MIPS64
>> return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
>> # elif defined(__s390x__)
>> return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
>> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
>>
>> #if defined(__mips__)
>> # define SANITIZER_MIPS 1
>> -# if defined(__mips64)
>> +# if defined(__mips64) && _MIPS_SIM == _ABI64
>> # define SANITIZER_MIPS32 0
>> # define SANITIZER_MIPS64 1
>> # else
>>
>> ---
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-06 11:34 ` Dimitrije Milosevic
@ 2022-07-06 18:11 ` Xi Ruoyao
2022-07-07 2:21 ` Xi Ruoyao
0 siblings, 1 reply; 9+ messages in thread
From: Xi Ruoyao @ 2022-07-06 18:11 UTC (permalink / raw)
To: Dimitrije Milosevic, Richard Sandiford, Xi Ruoyao via Gcc-patches
Cc: Djordje Todorovic
On Wed, 2022-07-06 at 11:34 +0000, Dimitrije Milosevic wrote:
> Ping. :)
> This change just landed on LLVM (see https://reviews.llvm.org/rG5d8077565e4196efdd4ed525a64c11a96d5aa5dd).
> Unfortunately, I do not have commit access, so if anyone can commit it, that would be great!
> Here is the patch with the updated commit message.
I will push this and
https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596226.html (with
ChangeLog format fixed) after a regression test.
If you will submit more GCC patches, please note:
(1) You may need to sign a FSF copyright assignment or contribute
further patches under DCO. See "Legal Prerequisites" in
https://gcc.gnu.org/contribute.html. For these two patches I'd consider
them "small" enough and acceptable w/o copyright assignment or DCO.
(2) You may require a sourceware.org account with write access to
gcc.git if you can get the approve from Richard or another Global
Reviewer.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-06 18:11 ` Xi Ruoyao
@ 2022-07-07 2:21 ` Xi Ruoyao
0 siblings, 0 replies; 9+ messages in thread
From: Xi Ruoyao @ 2022-07-07 2:21 UTC (permalink / raw)
To: Dimitrije Milosevic, Richard Sandiford, Xi Ruoyao via Gcc-patches
Cc: Djordje Todorovic
On Thu, 2022-07-07 at 02:11 +0800, Xi Ruoyao via Gcc-patches wrote:
> On Wed, 2022-07-06 at 11:34 +0000, Dimitrije Milosevic wrote:
> > Ping. :)
> > This change just landed on LLVM (see
> > https://reviews.llvm.org/rG5d8077565e4196efdd4ed525a64c11a96d5aa5dd)
> > .
> > Unfortunately, I do not have commit access, so if anyone can commit
> > it, that would be great!
> > Here is the patch with the updated commit message.
>
> I will push this and
> https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596226.html (with
> ChangeLog format fixed) after a regression test.
Pushed r13-1548 and r13-1549.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] Mips: Resolve build issues for the n32 ABI
@ 2022-07-01 8:18 Dimitrije Milosevic
2022-07-01 8:33 ` Xi Ruoyao
0 siblings, 1 reply; 9+ messages in thread
From: Dimitrije Milosevic @ 2022-07-01 8:18 UTC (permalink / raw)
To: gcc-patches; +Cc: Djordje Todorovic, xry111
Building the ASAN for the n32 MIPS ABI currently fails, due to a few reasons:
- 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 takes the ABI into account as well - defined(__mips64) && _MIPS_SIM == ABI64.
- The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
- After the transition to canonical system calls (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/syscalls/syscall_n32.tbl.
- struct_kernel_stat_sz was not updated after being changed in LLVM's source tree.
See https://reviews.llvm.org/D127098.
libsanitizer/ChangeLog:
* sanitizer_common/sanitizer_linux.cpp (defined): Resolve
ASAN build issues for the n32 ABI.
* sanitizer_common/sanitizer_platform.h (defined): Likewise.
* sanitizer_common/sanitizer_platform_limits_posix.h: Likewise.
---
libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h | 2 +-
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
// format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
// access stat from asm/stat.h, without conflicting with definition in
// sys/stat.h, we use this trick.
-#if defined(__mips64)
+#if SANITIZER_MIPS64
#include <asm/unistd.h>
#include <sys/types.h>
#define stat kernel_stat
@@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
// Are we using 32-bit or 64-bit Linux syscalls?
// x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
// but it still needs to use 64-bit syscalls.
-#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
- SANITIZER_WORDSIZE == 64)
+#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
+ SANITIZER_WORDSIZE == 64 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32))
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
#else
# define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
@@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
}
#endif
-#if defined(__mips64)
+#if SANITIZER_MIPS64
// Undefine compatibility macros from <sys/stat.h>
// so that they would not clash with the kernel_stat
// st_[a|m|c]time fields
@@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
#if SANITIZER_FREEBSD
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
# elif SANITIZER_LINUX
-# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
+# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
0);
# else
@@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# elif SANITIZER_LINUX
-# if defined(_LP64) || SANITIZER_X32
+# if defined(_LP64) || SANITIZER_X32 || \
+ (defined(__mips__) && _MIPS_SIM == _ABIN32)
return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
AT_SYMLINK_NOFOLLOW);
# else
@@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
#elif SANITIZER_RISCV64
return (1ULL << 38) - 1;
-# elif defined(__mips64)
+# elif SANITIZER_MIPS64
return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
# elif defined(__s390x__)
return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
#if defined(__mips__)
# define SANITIZER_MIPS 1
-# if defined(__mips64)
+# if defined(__mips64) && _MIPS_SIM == _ABI64
# define SANITIZER_MIPS32 0
# define SANITIZER_MIPS64 1
# else
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.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 = 104;
#elif defined(__mips__)
const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
? FIRST_32_SECOND_64(104, 128)
- : FIRST_32_SECOND_64(144, 216);
+ : FIRST_32_SECOND_64(160, 216);
const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__s390__) && !defined(__s390x__)
const unsigned struct_kernel_stat_sz = 64;
---
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Mips: Resolve build issues for the n32 ABI
2022-07-01 8:18 Dimitrije Milosevic
@ 2022-07-01 8:33 ` Xi Ruoyao
0 siblings, 0 replies; 9+ messages in thread
From: Xi Ruoyao @ 2022-07-01 8:33 UTC (permalink / raw)
To: Dimitrije Milosevic, gcc-patches; +Cc: Djordje Todorovic
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 reasons:
> - 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 takes the ABI into account as well - defined(__mips64) && _MIPS_SIM == ABI64.
> - The n32 ABI still uses 64-bit *Linux* system calls, even though the word size is 32 bits.
> - After the transition to canonical system calls (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/syscalls/syscall_n32.tbl.
> - struct_kernel_stat_sz was not updated after being changed in LLVM's source tree.
>
> See https://reviews.llvm.org/D127098.
>
> libsanitizer/ChangeLog:
>
> * sanitizer_common/sanitizer_linux.cpp (defined): Resolve
> ASAN build issues for the n32 ABI.
> * sanitizer_common/sanitizer_platform.h (defined): Likewise.
> * sanitizer_common/sanitizer_platform_limits_posix.h: Likewise.
>
> ---
>
> libsanitizer/sanitizer_common/sanitizer_linux.cpp | 17 ++++++++++-------
> libsanitizer/sanitizer_common/sanitizer_platform.h | 2 +-
> libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h | 2 +-
> 3 files changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/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 @@
> // format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To
> // access stat from asm/stat.h, without conflicting with definition in
> // sys/stat.h, we use this trick.
> -#if defined(__mips64)
> +#if SANITIZER_MIPS64
> #include <asm/unistd.h>
> #include <sys/types.h>
> #define stat kernel_stat
> @@ -124,8 +124,9 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG;
> // Are we using 32-bit or 64-bit Linux syscalls?
> // x32 (which defines __x86_64__) has SANITIZER_WORDSIZE == 32
> // but it still needs to use 64-bit syscalls.
> -#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
> - SANITIZER_WORDSIZE == 64)
> +#if SANITIZER_LINUX && (defined(__x86_64__) || defined(__powerpc64__) || \
> + SANITIZER_WORDSIZE == 64 || \
> + (defined(__mips__) && _MIPS_SIM == _ABIN32))
> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 1
> #else
> # define SANITIZER_LINUX_USES_64BIT_SYSCALLS 0
> @@ -289,7 +290,7 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) {
> }
> #endif
>
> -#if defined(__mips64)
> +#if SANITIZER_MIPS64
> // Undefine compatibility macros from <sys/stat.h>
> // so that they would not clash with the kernel_stat
> // st_[a|m|c]time fields
> @@ -343,7 +344,8 @@ uptr internal_stat(const char *path, void *buf) {
> #if SANITIZER_FREEBSD
> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0);
> # elif SANITIZER_LINUX
> -# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32
> +# if SANITIZER_WORDSIZE == 64 || SANITIZER_X32 || \
> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
> 0);
> # else
> @@ -366,7 +368,8 @@ uptr internal_lstat(const char *path, void *buf) {
> return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf,
> AT_SYMLINK_NOFOLLOW);
> # elif SANITIZER_LINUX
> -# if defined(_LP64) || SANITIZER_X32
> +# if defined(_LP64) || SANITIZER_X32 || \
> + (defined(__mips__) && _MIPS_SIM == _ABIN32)
> return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
> AT_SYMLINK_NOFOLLOW);
> # else
> @@ -1053,7 +1056,7 @@ uptr GetMaxVirtualAddress() {
> return (1ULL << (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1)) - 1;
> #elif SANITIZER_RISCV64
> return (1ULL << 38) - 1;
> -# elif defined(__mips64)
> +# elif SANITIZER_MIPS64
> return (1ULL << 40) - 1; // 0x000000ffffffffffUL;
> # elif defined(__s390x__)
> return (1ULL << 53) - 1; // 0x001fffffffffffffUL;
> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/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 @@
>
> #if defined(__mips__)
> # define SANITIZER_MIPS 1
> -# if defined(__mips64)
> +# if defined(__mips64) && _MIPS_SIM == _ABI64
> # define SANITIZER_MIPS32 0
> # define SANITIZER_MIPS64 1
> # else
> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.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 = 104;
> #elif defined(__mips__)
> const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
> ? FIRST_32_SECOND_64(104, 128)
> - : FIRST_32_SECOND_64(144, 216);
> + : FIRST_32_SECOND_64(160, 216);
> const unsigned struct_kernel_stat64_sz = 104;
> #elif defined(__s390__) && !defined(__s390x__)
> const unsigned struct_kernel_stat_sz = 64;
>
> ---
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-07-07 2:21 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 12:40 [PATCH] Mips: Resolve build issues for the n32 ABI Dimitrije Milosevic
2022-07-01 12:58 ` Xi Ruoyao
2022-07-01 14:32 ` Dimitrije Milosevic
2022-07-04 11:23 ` Richard Sandiford
2022-07-06 11:34 ` Dimitrije Milosevic
2022-07-06 18:11 ` Xi Ruoyao
2022-07-07 2:21 ` Xi Ruoyao
-- strict thread matches above, loose matches on Subject: below --
2022-07-01 8:18 Dimitrije Milosevic
2022-07-01 8:33 ` Xi Ruoyao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).