PATCH: Fix libsanitizer for x32
H.J. Lu
hjl.tools at gmail.com
Thu Dec 5 06:37:02 PST 2013
On Thu, Dec 5, 2013 at 4:59 AM, Konstantin Serebryany
<konstantin.s.serebryany at gmail.com> wrote:
> On Thu, Dec 5, 2013 at 4:47 PM, H.J. Lu <hjl.tools at gmail.com> wrote:
>>
>> There are at least 2 fallouts:
>>
>> 1. -mx32 is broken.
>
> Please send a patch to the llvm-commits list
>
I am enclosing 2 patches here. You can test x32 on Ubuntu
13.04 or newer.
struct stat defined in <asm/stat.h> is incorrect for x32. <asm/stat.h>
is included to get struct __old_kernel_stat. But struct __old_kernel_stat
isn't used for x86-64 and x32. The first patch includes <sys/stat.h> instead
of <asm/stat.h> and comments out size check of struct __old_kernel_stat
for x86-64.
Some fields in shmid_ds as well as clock_t are int64 for x32. The second
patch corrects them for x32.
Thanks.
--
H.J.
-------------- next part --------------
From aa91c65dd8ef7f2fcccae0ca164bfa547e169a5c Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools at gmail.com>
Date: Thu, 5 Dec 2013 06:19:31 -0800
Subject: [PATCH 1/2] Include <sys/stat.h> for x86-64
struct stat defined in <asm/stat.h> is incorrect for x32. <asm/stat.h>
is included to get struct __old_kernel_stat. But struct __old_kernel_stat
isn't used for x86-64 and x32. This patch includes <sys/stat.h> instead
of <asm/stat.h> and comments out size check of struct __old_kernel_stat
for x86-64.
---
libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc
index 01de9c9..bc37df0 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc
@@ -27,6 +27,9 @@
// are not defined anywhere in userspace headers. Fake them. This seems to work
// fine with newer headers, too.
#include <asm/posix_types.h>
+#if defined(__x86_64__)
+#include <sys/stat.h>
+#else
#define ino_t __kernel_ino_t
#define mode_t __kernel_mode_t
#define nlink_t __kernel_nlink_t
@@ -41,6 +44,7 @@
#undef uid_t
#undef gid_t
#undef off_t
+#endif
#include <linux/aio_abi.h>
@@ -58,7 +62,7 @@ namespace __sanitizer {
unsigned struct_statfs64_sz = sizeof(struct statfs64);
} // namespace __sanitizer
-#if !defined(__powerpc64__)
+#if !defined(__powerpc64__) && !defined(__x86_64__)
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
#endif
--
1.8.3.1
-------------- next part --------------
From a8d2227ae1ce9da963dca9e3e1e8e04c3db7ad46 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools at gmail.com>
Date: Thu, 5 Dec 2013 06:24:36 -0800
Subject: [PATCH 2/2] Correct __sanitizer_shmid_ds/__sanitizer_clock_t for x32
Some fields in shmid_ds as well as clock_t are int64 for x32. This
patch corrects them for x32.
---
.../sanitizer_common/sanitizer_platform_limits_posix.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index f98ebea..be6e6cf 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -167,6 +167,11 @@ namespace __sanitizer {
#elif !defined(__powerpc64__)
uptr __unused0;
#endif
+ #if defined(__x86_64__) && !defined(_LP64)
+ u64 shm_atime;
+ u64 shm_dtime;
+ u64 shm_ctime;
+ #else
uptr shm_atime;
#ifndef _LP64
uptr __unused1;
@@ -179,14 +184,21 @@ namespace __sanitizer {
#ifndef _LP64
uptr __unused3;
#endif
+ #endif
#ifdef __powerpc__
uptr shm_segsz;
#endif
int shm_cpid;
int shm_lpid;
+ #if defined(__x86_64__) && !defined(_LP64)
+ u64 shm_nattch;
+ u64 __unused4;
+ u64 __unused5;
+ #else
uptr shm_nattch;
uptr __unused4;
uptr __unused5;
+ #endif
};
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
@@ -294,7 +306,11 @@ namespace __sanitizer {
};
#endif
+#if defined(__x86_64__) && !defined(_LP64)
+ typedef long long __sanitizer_clock_t;
+#else
typedef long __sanitizer_clock_t;
+#endif
#if SANITIZER_LINUX
#if defined(_LP64) || defined(__x86_64__) || defined(__powerpc__)
--
1.8.3.1
More information about the llvm-commits
mailing list