Blame 0001-Fix-sanitizer-common-build-with-glibc-2.31.patch

a5fc7ec
From 25395eb64390546dffe2a2494876909d27b999c3 Mon Sep 17 00:00:00 2001
a5fc7ec
From: Evgenii Stepanov <eugenis@google.com>
a5fc7ec
Date: Mon, 25 Nov 2019 13:52:17 -0800
a5fc7ec
Subject: [PATCH] Fix sanitizer-common build with glibc 2.31
a5fc7ec
a5fc7ec
Summary:
a5fc7ec
As mentioned in D69104, glibc changed ABI recently with the [[ https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=2f959dfe849e0646e27403f2e4091536496ac0f0| 2f959dfe ]] change.
a5fc7ec
D69104 dealt with just 32-bit ARM, but that is just one of the many affected architectures.
a5fc7ec
E.g. x86_64, i?86, riscv64, sparc 32-bit, s390 31-bit are affected too (and various others).
a5fc7ec
a5fc7ec
This patch instead of adding a long list of further architectures that wouldn't be checked ever next to arm 32-bit changes the structures to match the 2.31 layout and performs the checking on Linux for ipc_perm mode position/size only on non-Linux or on Linux with glibc 2.31 or later.  I think this matches what is done for aarch64 already.
a5fc7ec
If needed, we could list architectures that haven't changed ABI (e.g. powerpc), so that they would be checked even with older glibcs.  AFAIK sanitizers don't actually use ipc_perm.mode and
a5fc7ec
so all they care about is the size and alignment of the whole structure.
a5fc7ec
a5fc7ec
Note, s390 31-bit and arm 32-bit big-endian changed ABI even further, there will now be shmctl with old symbol version and shmctl@@GLIBC_2.31 which will be incompatible.  I'm afraid this isn't really solvable unless the sanitizer libraries are symbol versioned and use matching symbol versions to glibc symbols for stuff they intercept, plus use dlvsym.
a5fc7ec
This patch doesn't try to address that.
a5fc7ec
a5fc7ec
Patch by Jakub Jelinek.
a5fc7ec
a5fc7ec
Reviewers: kcc, eugenis, dvyukov
a5fc7ec
a5fc7ec
Reviewed By: eugenis
a5fc7ec
a5fc7ec
Subscribers: jyknight, kristof.beyls, fedor.sergeev, simoncook, PkmX, s.egerton, steven.zhang, #sanitizers, llvm-commits
a5fc7ec
a5fc7ec
Tags: #sanitizers, #llvm
a5fc7ec
a5fc7ec
Differential Revision: https://reviews.llvm.org/D70662
a5fc7ec
---
a5fc7ec
 .../sanitizer_common/sanitizer_platform_limits_posix.cc   |  5 +++--
a5fc7ec
 .../sanitizer_common/sanitizer_platform_limits_posix.h    | 15 +--------------
a5fc7ec
 2 files changed, 4 insertions(+), 16 deletions(-)
a5fc7ec
a5fc7ec
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
a5fc7ec
index b7fa6e8..abdf794 100644
a5fc7ec
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
a5fc7ec
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
a5fc7ec
@@ -1126,8 +1126,9 @@ CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
a5fc7ec
 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
a5fc7ec
 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
a5fc7ec
 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
a5fc7ec
-#if !defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)
a5fc7ec
-/* On aarch64 glibc 2.20 and earlier provided incorrect mode field.  */
a5fc7ec
+#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
a5fc7ec
+/* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit
a5fc7ec
+   on many architectures.  */
a5fc7ec
 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
a5fc7ec
 #endif
a5fc7ec
 
a5fc7ec
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
a5fc7ec
index f1a4fd7..029a209 100644
a5fc7ec
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
a5fc7ec
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
a5fc7ec
@@ -203,26 +203,13 @@ namespace __sanitizer {
a5fc7ec
     u64 __unused1;
a5fc7ec
     u64 __unused2;
a5fc7ec
 #elif defined(__sparc__)
a5fc7ec
-#if defined(__arch64__)
a5fc7ec
     unsigned mode;
a5fc7ec
-    unsigned short __pad1;
a5fc7ec
-#else
a5fc7ec
-    unsigned short __pad1;
a5fc7ec
-    unsigned short mode;
a5fc7ec
     unsigned short __pad2;
a5fc7ec
-#endif
a5fc7ec
     unsigned short __seq;
a5fc7ec
     unsigned long long __unused1;
a5fc7ec
     unsigned long long __unused2;
a5fc7ec
-#elif defined(__mips__) || defined(__aarch64__) || defined(__s390x__)
a5fc7ec
-    unsigned int mode;
a5fc7ec
-    unsigned short __seq;
a5fc7ec
-    unsigned short __pad1;
a5fc7ec
-    unsigned long __unused1;
a5fc7ec
-    unsigned long __unused2;
a5fc7ec
 #else
a5fc7ec
-    unsigned short mode;
a5fc7ec
-    unsigned short __pad1;
a5fc7ec
+    unsigned int mode;
a5fc7ec
     unsigned short __seq;
a5fc7ec
     unsigned short __pad2;
a5fc7ec
 #if defined(__x86_64__) && !defined(_LP64)
a5fc7ec
-- 
a5fc7ec
1.8.3.1
a5fc7ec