mbox series

[0/2] libsanitizer: Merge with upstream commit fdf4c035225d

Message ID 20211006200732.1857173-1-hjl.tools@gmail.com
Headers show
Series libsanitizer: Merge with upstream commit fdf4c035225d | expand

Message

H.J. Lu Oct. 6, 2021, 8:07 p.m. UTC
I am checking in these patches to merge with upstream commit:

commit fdf4c035225de52f596899931b1f6100e5e3e928
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Sep 10 06:24:36 2021 -0700

    [sanitizer] Support Intel CET

    1. Include <cet.h> in sanitizer_common/sanitizer_asm.h to mark Intel CET
    support when Intel CET is enabled.
    2. Add _CET_ENDBR to function entries in assembly codes so that ENDBR
    instruction will be generated when Intel CET is enabled.

    Reviewed By: dvyukov

    Differential Revision: https://reviews.llvm.org/D111185

H.J. Lu (2):
  libsanitizer: Merge with upstream
  libsanitizer: Apply local patches

 libsanitizer/MERGE                            |  2 +-
 libsanitizer/asan/asan_allocator.cpp          | 15 -----
 libsanitizer/asan/asan_allocator.h            |  2 -
 libsanitizer/asan/asan_debugging.cpp          |  5 +-
 libsanitizer/asan/asan_stats.cpp              |  4 +-
 libsanitizer/hwasan/hwasan.cpp                |  4 +-
 libsanitizer/hwasan/hwasan_setjmp_x86_64.S    |  2 +
 libsanitizer/lsan/lsan_common.cpp             | 56 ++++++++---------
 libsanitizer/lsan/lsan_common.h               |  3 +
 libsanitizer/sanitizer_common/sanitizer_asm.h |  4 ++
 .../sanitizer_chained_origin_depot.cpp        | 11 ++--
 .../sanitizer_chained_origin_depot.h          |  9 +--
 ...tizer_common_interceptors_vfork_i386.inc.S |  1 +
 ...zer_common_interceptors_vfork_x86_64.inc.S |  1 +
 .../sanitizer_common_libcdep.cpp              | 20 +++---
 .../sanitizer_common/sanitizer_hash.h         | 24 +++++++
 .../sanitizer_platform_interceptors.h         |  4 +-
 .../sanitizer_platform_limits_freebsd.cpp     | 21 +++++++
 .../sanitizer_platform_limits_freebsd.h       | 16 +++++
 .../sanitizer_common/sanitizer_stackdepot.cpp | 49 ++++++++-------
 .../sanitizer_common/sanitizer_stackdepot.h   | 10 +--
 .../sanitizer_stackdepotbase.h                |  9 +--
 libsanitizer/tsan/tsan_interceptors.h         |  6 +-
 libsanitizer/tsan/tsan_interceptors_posix.cpp | 13 ++--
 libsanitizer/tsan/tsan_interface.cpp          |  5 +-
 libsanitizer/tsan/tsan_platform_linux.cpp     | 18 +++---
 libsanitizer/tsan/tsan_platform_mac.cpp       | 62 ++++++++++---------
 libsanitizer/tsan/tsan_rtl.cpp                |  8 +--
 libsanitizer/tsan/tsan_rtl.h                  |  9 +--
 libsanitizer/tsan/tsan_rtl_amd64.S            |  6 ++
 30 files changed, 227 insertions(+), 172 deletions(-)

Comments

Gerald Pfeifer Oct. 7, 2021, 9:40 p.m. UTC | #1
On Wed, 6 Oct 2021, H.J. Lu via Gcc-patches wrote:
> I am checking in these patches to merge with upstream commit:

Thus breaking bootstrap on FreeBSD:

GCC-HEAD/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp:370:36: error: 'MD5_CTX' was not declared in this scope
  370 | const unsigned MD5_CTX_sz = sizeof(MD5_CTX);
      |                                    ^~~~~~~
GCC-HEAD/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp:371:36: error: 
'MD5_DIGEST_STRING_LENGTH' was not declared in this scope; did you mean 
'SHA256_DIGEST_STRING_LENGTH'?
  371 | const unsigned MD5_return_length = MD5_DIGEST_STRING_LENGTH;
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                    SHA256_DIGEST_STRING_LENGTH

I stared the the sources for minutes and FreeBSD include files and could
not find what was wrong.

Then I realized: GCC has its own include/md5 which misses some of these!


Looking how old md5 is (and deprecated) I cannot help wonder whether you
merged something that wasn't new, but intentionally left out originally?

Or include paths are broken.


Gerald


PS: At this point I am counting about *seven* distinct bootstrap 
breakages on my nightly testers in the last six weeks or so. :-(
H.J. Lu Oct. 7, 2021, 9:56 p.m. UTC | #2
On Thu, Oct 7, 2021 at 2:41 PM Gerald Pfeifer <gerald@pfeifer.com> wrote:
>
> On Wed, 6 Oct 2021, H.J. Lu via Gcc-patches wrote:
> > I am checking in these patches to merge with upstream commit:
>
> Thus breaking bootstrap on FreeBSD:
>
> GCC-HEAD/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp:370:36: error: 'MD5_CTX' was not declared in this scope
>   370 | const unsigned MD5_CTX_sz = sizeof(MD5_CTX);
>       |                                    ^~~~~~~
> GCC-HEAD/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp:371:36: error:
> 'MD5_DIGEST_STRING_LENGTH' was not declared in this scope; did you mean
> 'SHA256_DIGEST_STRING_LENGTH'?
>   371 | const unsigned MD5_return_length = MD5_DIGEST_STRING_LENGTH;
>       |                                    ^~~~~~~~~~~~~~~~~~~~~~~~
>       |                                    SHA256_DIGEST_STRING_LENGTH
>
> I stared the the sources for minutes and FreeBSD include files and could
> not find what was wrong.

compiler-rt sync brought in

commit 18a7ebda99044473fdbce6376993714ff54e6690
Author: David Carlier <devnexen@gmail.com>
Date:   Wed Oct 6 06:01:50 2021 +0100

    [Sanitizers] intercept md5 and sha* apis on FreeBSD.

    Reviewed By: vitalybuka

    Differential Revision: https://reviews.llvm.org/D110989

diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
 b/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
index bfe3eea464d..64535805e40 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -69,6 +69,11 @@
 #include <semaphore.h>
 #include <signal.h>
 #include <stddef.h>
+#include <md5.h>
+#include <sha224.h>
+#include <sha256.h>
+#include <sha384.h>
+#include <sha512.h>
 #include <stdio.h>
 #include <stringlist.h>
 #include <term.h>
@@ -361,6 +366,22 @@ const int si_SEGV_MAPERR = SEGV_MAPERR;
 const int si_SEGV_ACCERR = SEGV_ACCERR;
 const int unvis_valid = UNVIS_VALID;
 const int unvis_validpush = UNVIS_VALIDPUSH;
+
+const unsigned MD5_CTX_sz = sizeof(MD5_CTX);
+const unsigned MD5_return_length = MD5_DIGEST_STRING_LENGTH;
+
+#define SHA2_CONST(LEN)                                                      \
+  const unsigned SHA##LEN##_CTX_sz = sizeof(SHA##LEN##_CTX);                 \
+  const unsigned SHA##LEN##_return_length = SHA##LEN##_DIGEST_STRING_LENGTH; \
+  const unsigned SHA##LEN##_block_length = SHA##LEN##_BLOCK_LENGTH;          \
+  const unsigned SHA##LEN##_digest_length = SHA##LEN##_DIGEST_LENGTH
+
+SHA2_CONST(224);
+SHA2_CONST(256);
+SHA2_CONST(384);
+SHA2_CONST(512);
+
+#undef SHA2_CONST
 }  // namespace __sanitizer

Does compiler-rt compile on FreeBSD?  If not, please file a compiler-rt bug.
If yes, why doesn't it work in GCC?

> Then I realized: GCC has its own include/md5 which misses some of these!
>
>
> Looking how old md5 is (and deprecated) I cannot help wonder whether you
> merged something that wasn't new, but intentionally left out originally?
>
> Or include paths are broken.
>
>
> Gerald
>
>
> PS: At this point I am counting about *seven* distinct bootstrap
> breakages on my nightly testers in the last six weeks or so. :-(
Gerald Pfeifer Oct. 9, 2021, 10:28 p.m. UTC | #3
On Thu, 7 Oct 2021, H.J. Lu wrote:
>> Thus breaking bootstrap on FreeBSD:
>>
>> GCC-HEAD/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp:370:36: error: 'MD5_CTX' was not declared in this scope
>   370 | const unsigned MD5_CTX_sz = sizeof(MD5_CTX);
>>       |                                    ^~~~~~~
>> GCC-HEAD/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp:371:36: error:
>> 'MD5_DIGEST_STRING_LENGTH' was not declared in this scope
> compiler-rt sync brought in
> 
> commit 18a7ebda99044473fdbce6376993714ff54e6690
> Author: David Carlier <devnexen@gmail.com>
> Date:   Wed Oct 6 06:01:50 2021 +0100
> 
>     [Sanitizers] intercept md5 and sha* apis on FreeBSD.
> 
>     Reviewed By: vitalybuka
> 
>     Differential Revision: https://reviews.llvm.org/D110989
> 
> diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
>  b/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
> index bfe3eea464d..64535805e40 100644
> --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
> +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
> @@ -69,6 +69,11 @@
>  #include <semaphore.h>
>  #include <signal.h>
>  #include <stddef.h>
> +#include <md5.h>

Yep, and here is the problem: In the case of Clang this uses FreeBSD's 
<md5.h>.

In the case of GCC apparently this uses our own, bare-bone md5.h - 
include/md5.h.

Boom. Regression. Bootstrap failure on every platfor and version of
FreeBSD. (FreeBSD 11.x is also broken by this patch, in a different 
way, alas went end of life a week ago.)

I now filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102675 and
sadly don't have an idea how to tackle this.

Gerald