public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* libsanitizer: merge from upstream
@ 2022-05-04  8:59 Martin Liška
  2022-05-04 23:07 ` [PATCH] libsanitizer: cherry-pick commit f52e365092aa " H.J. Lu
  2022-08-30 10:53 ` libsanitizer: merge " Martin Liška
  0 siblings, 2 replies; 10+ messages in thread
From: Martin Liška @ 2022-05-04  8:59 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 372 bytes --]

Hello.

I'm going to do merge from upstream.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests. I've also tested
on ppc64le-linux-gnu and verified the ABI.

The only real change is a small change in
gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
where we need --param=asan-use-after-return=0.

I'm going to push the patches.

Thanks,
Martin

[-- Attachment #2: 0004-libsanitizer-update-test-that-mixes-fake-and-real-st.patch --]
[-- Type: text/x-patch, Size: 977 bytes --]

From c1d4f2ed67713d30c0903b939d95065b5de83b2a Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 2 May 2022 13:58:49 +0200
Subject: [PATCH 4/4] libsanitizer: update test that mixes fake and real stack

gcc/testsuite/ChangeLog:

	* c-c++-common/asan/alloca_loop_unpoisoning.c: Do not combine
	fake and real stack.
---
 gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c b/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
index 3050d3ba94b..86f0ce6d8a0 100644
--- a/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
+++ b/gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
@@ -1,5 +1,6 @@
 /* { dg-do run } */
 /* { dg-require-effective-target alloca } */
+/* { dg-options "--param=asan-use-after-return=0" } */
 
 /* This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.  */
 
-- 
2.36.0


[-- Attachment #3: 0003-libsanitizer-Update-Makefile.am-files.patch --]
[-- Type: text/x-patch, Size: 11529 bytes --]

From b4ad0ea58c0f2ca16fdc1a15a4b04d2df7a77e57 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 2 May 2022 13:20:06 +0200
Subject: [PATCH 3/4] libsanitizer: Update Makefile.am files.

libsanitizer/ChangeLog:

	* tsan/Makefile.am: Update Makefile.am files.
	* hwasan/Makefile.am: Likewise.
	* sanitizer_common/Makefile.am: Likewise.
	* Makefile.in: Re-generate.
	* asan/Makefile.in: Likewise.
	* hwasan/Makefile.in: Likewise.
	* interception/Makefile.in: Likewise.
	* libbacktrace/Makefile.in: Likewise.
	* lsan/Makefile.in: Likewise.
	* sanitizer_common/Makefile.in: Likewise.
	* tsan/Makefile.in: Likewise.
	* ubsan/Makefile.in: Likewise.
---
 libsanitizer/Makefile.in                  |  1 -
 libsanitizer/asan/Makefile.in             |  1 -
 libsanitizer/hwasan/Makefile.am           |  1 +
 libsanitizer/hwasan/Makefile.in           | 10 ++++++----
 libsanitizer/interception/Makefile.in     |  1 -
 libsanitizer/libbacktrace/Makefile.in     |  1 -
 libsanitizer/lsan/Makefile.in             |  1 -
 libsanitizer/sanitizer_common/Makefile.am |  1 +
 libsanitizer/sanitizer_common/Makefile.in | 11 ++++++-----
 libsanitizer/tsan/Makefile.am             |  1 -
 libsanitizer/tsan/Makefile.in             | 15 ++++++---------
 libsanitizer/ubsan/Makefile.in            |  1 -
 12 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/libsanitizer/Makefile.in b/libsanitizer/Makefile.in
index aab88deb6e8..65e7f2e9553 100644
--- a/libsanitizer/Makefile.in
+++ b/libsanitizer/Makefile.in
@@ -345,7 +345,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in
index 2476fbc5a26..7833a9a4c3f 100644
--- a/libsanitizer/asan/Makefile.in
+++ b/libsanitizer/asan/Makefile.in
@@ -399,7 +399,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
diff --git a/libsanitizer/hwasan/Makefile.am b/libsanitizer/hwasan/Makefile.am
index e12c0a0ce71..b8d39af4322 100644
--- a/libsanitizer/hwasan/Makefile.am
+++ b/libsanitizer/hwasan/Makefile.am
@@ -28,6 +28,7 @@ hwasan_files = \
 	hwasan_memintrinsics.cpp \
 	hwasan_new_delete.cpp \
 	hwasan_poisoning.cpp \
+	hwasan_preinit.cpp \
 	hwasan_report.cpp \
 	hwasan_setjmp_aarch64.S \
 	hwasan_setjmp_x86_64.S \
diff --git a/libsanitizer/hwasan/Makefile.in b/libsanitizer/hwasan/Makefile.in
index 67553f3979d..b9b942003a3 100644
--- a/libsanitizer/hwasan/Makefile.in
+++ b/libsanitizer/hwasan/Makefile.in
@@ -152,9 +152,10 @@ am__objects_1 = hwasan_allocation_functions.lo hwasan_allocator.lo \
 	hwasan_fuchsia.lo hwasan_globals.lo hwasan_interceptors.lo \
 	hwasan_interceptors_vfork.lo hwasan_linux.lo \
 	hwasan_memintrinsics.lo hwasan_new_delete.lo \
-	hwasan_poisoning.lo hwasan_report.lo hwasan_setjmp_aarch64.lo \
-	hwasan_setjmp_x86_64.lo hwasan_tag_mismatch_aarch64.lo \
-	hwasan_thread.lo hwasan_thread_list.lo hwasan_type_test.lo
+	hwasan_poisoning.lo hwasan_preinit.lo hwasan_report.lo \
+	hwasan_setjmp_aarch64.lo hwasan_setjmp_x86_64.lo \
+	hwasan_tag_mismatch_aarch64.lo hwasan_thread.lo \
+	hwasan_thread_list.lo hwasan_type_test.lo
 am_libhwasan_la_OBJECTS = $(am__objects_1)
 libhwasan_la_OBJECTS = $(am_libhwasan_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -387,7 +388,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -430,6 +430,7 @@ hwasan_files = \
 	hwasan_memintrinsics.cpp \
 	hwasan_new_delete.cpp \
 	hwasan_poisoning.cpp \
+	hwasan_preinit.cpp \
 	hwasan_report.cpp \
 	hwasan_setjmp_aarch64.S \
 	hwasan_setjmp_x86_64.S \
@@ -574,6 +575,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_memintrinsics.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_new_delete.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_poisoning.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_preinit.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_report.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_setjmp_aarch64.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_setjmp_x86_64.Plo@am__quote@
diff --git a/libsanitizer/interception/Makefile.in b/libsanitizer/interception/Makefile.in
index bce788aeea7..85dd386de47 100644
--- a/libsanitizer/interception/Makefile.in
+++ b/libsanitizer/interception/Makefile.in
@@ -317,7 +317,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
diff --git a/libsanitizer/libbacktrace/Makefile.in b/libsanitizer/libbacktrace/Makefile.in
index ece4f11a855..c0243fa4aab 100644
--- a/libsanitizer/libbacktrace/Makefile.in
+++ b/libsanitizer/libbacktrace/Makefile.in
@@ -367,7 +367,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
diff --git a/libsanitizer/lsan/Makefile.in b/libsanitizer/lsan/Makefile.in
index 857f244cd86..d8fd4ee9557 100644
--- a/libsanitizer/lsan/Makefile.in
+++ b/libsanitizer/lsan/Makefile.in
@@ -362,7 +362,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
diff --git a/libsanitizer/sanitizer_common/Makefile.am b/libsanitizer/sanitizer_common/Makefile.am
index a70dae4389f..99330390ba4 100644
--- a/libsanitizer/sanitizer_common/Makefile.am
+++ b/libsanitizer/sanitizer_common/Makefile.am
@@ -59,6 +59,7 @@ sanitizer_common_files = \
 	sanitizer_procmaps_mac.cpp \
 	sanitizer_procmaps_solaris.cpp \
 	sanitizer_solaris.cpp \
+	sanitizer_stack_store.cpp \
 	sanitizer_stackdepot.cpp \
 	sanitizer_stacktrace.cpp \
 	sanitizer_stacktrace_libcdep.cpp \
diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in
index c4b009fed83..07047bd4b17 100644
--- a/libsanitizer/sanitizer_common/Makefile.in
+++ b/libsanitizer/sanitizer_common/Makefile.in
@@ -140,10 +140,10 @@ am__objects_1 = sancov_flags.lo sanitizer_allocator.lo \
 	sanitizer_procmaps_bsd.lo sanitizer_procmaps_common.lo \
 	sanitizer_procmaps_linux.lo sanitizer_procmaps_mac.lo \
 	sanitizer_procmaps_solaris.lo sanitizer_solaris.lo \
-	sanitizer_stackdepot.lo sanitizer_stacktrace.lo \
-	sanitizer_stacktrace_libcdep.lo sanitizer_stacktrace_sparc.lo \
-	sanitizer_symbolizer_mac.lo sanitizer_symbolizer_report.lo \
-	sanitizer_stacktrace_printer.lo \
+	sanitizer_stack_store.lo sanitizer_stackdepot.lo \
+	sanitizer_stacktrace.lo sanitizer_stacktrace_libcdep.lo \
+	sanitizer_stacktrace_sparc.lo sanitizer_symbolizer_mac.lo \
+	sanitizer_symbolizer_report.lo sanitizer_stacktrace_printer.lo \
 	sanitizer_stoptheworld_linux_libcdep.lo \
 	sanitizer_stoptheworld_mac.lo sanitizer_suppressions.lo \
 	sanitizer_symbolizer.lo sanitizer_symbolizer_libbacktrace.lo \
@@ -354,7 +354,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -420,6 +419,7 @@ sanitizer_common_files = \
 	sanitizer_procmaps_mac.cpp \
 	sanitizer_procmaps_solaris.cpp \
 	sanitizer_solaris.cpp \
+	sanitizer_stack_store.cpp \
 	sanitizer_stackdepot.cpp \
 	sanitizer_stacktrace.cpp \
 	sanitizer_stacktrace_libcdep.cpp \
@@ -576,6 +576,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_procmaps_mac.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_procmaps_solaris.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_solaris.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_stack_store.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_stackdepot.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_stacktrace.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_stacktrace_libcdep.Plo@am__quote@
diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am
index ae588a67df6..da80743da9d 100644
--- a/libsanitizer/tsan/Makefile.am
+++ b/libsanitizer/tsan/Makefile.am
@@ -15,7 +15,6 @@ toolexeclib_LTLIBRARIES = libtsan.la
 nodist_toolexeclib_HEADERS = libtsan_preinit.o
 
 tsan_files = \
-	tsan_clock.cpp \
 	tsan_debugging.cpp \
 	tsan_external.cpp \
 	tsan_fd.cpp \
diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in
index 538d2e8eb68..36498832bb8 100644
--- a/libsanitizer/tsan/Makefile.in
+++ b/libsanitizer/tsan/Makefile.in
@@ -146,12 +146,12 @@ am__installdirs = "$(DESTDIR)$(toolexeclibdir)" \
 	"$(DESTDIR)$(toolexeclibdir)"
 LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
 am__DEPENDENCIES_1 =
-am__objects_1 = tsan_clock.lo tsan_debugging.lo tsan_external.lo \
-	tsan_fd.lo tsan_flags.lo tsan_ignoreset.lo \
-	tsan_interceptors_posix.lo tsan_interceptors_mac.lo \
-	tsan_interface_ann.lo tsan_interface_atomic.lo \
-	tsan_interface.lo tsan_interface_java.lo tsan_malloc_mac.lo \
-	tsan_md5.lo tsan_mman.lo tsan_mutexset.lo tsan_new_delete.lo \
+am__objects_1 = tsan_debugging.lo tsan_external.lo tsan_fd.lo \
+	tsan_flags.lo tsan_ignoreset.lo tsan_interceptors_posix.lo \
+	tsan_interceptors_mac.lo tsan_interface_ann.lo \
+	tsan_interface_atomic.lo tsan_interface.lo \
+	tsan_interface_java.lo tsan_malloc_mac.lo tsan_md5.lo \
+	tsan_mman.lo tsan_mutexset.lo tsan_new_delete.lo \
 	tsan_platform_linux.lo tsan_platform_mac.lo \
 	tsan_platform_posix.lo tsan_platform_windows.lo tsan_report.lo \
 	tsan_rtl.lo tsan_rtl_access.lo tsan_rtl_mutex.lo \
@@ -391,7 +391,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -421,7 +420,6 @@ ACLOCAL_AMFLAGS = -I m4
 toolexeclib_LTLIBRARIES = libtsan.la
 nodist_toolexeclib_HEADERS = libtsan_preinit.o
 tsan_files = \
-	tsan_clock.cpp \
 	tsan_debugging.cpp \
 	tsan_external.cpp \
 	tsan_fd.cpp \
@@ -585,7 +583,6 @@ mostlyclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_clock.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_debugging.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_external.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsan_fd.Plo@am__quote@
diff --git a/libsanitizer/ubsan/Makefile.in b/libsanitizer/ubsan/Makefile.in
index 497e0338696..92a8e387fd7 100644
--- a/libsanitizer/ubsan/Makefile.in
+++ b/libsanitizer/ubsan/Makefile.in
@@ -356,7 +356,6 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
-- 
2.36.0


[-- Attachment #4: 0002-libsanitizer-Apply-local-patches.patch --]
[-- Type: text/x-patch, Size: 13843 bytes --]

From 1c0069ab7ad0d76072adf3dc006b515a670a3ccb Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 20 Jul 2021 10:46:51 -0700
Subject: [PATCH 2/4] libsanitizer: Apply local patches

---
 libsanitizer/asan/asan_globals.cpp            | 19 ------------------
 libsanitizer/asan/asan_interceptors.h         |  7 ++++++-
 libsanitizer/asan/asan_mapping.h              |  2 +-
 .../sanitizer_linux_libcdep.cpp               |  4 ++++
 .../sanitizer_common/sanitizer_mac.cpp        | 12 +++++++++--
 libsanitizer/sanitizer_common/sanitizer_mac.h | 20 +++++++++++++++++++
 .../sanitizer_platform_limits_linux.cpp       |  5 ++++-
 .../sanitizer_platform_limits_posix.h         |  2 +-
 .../sanitizer_common/sanitizer_stacktrace.cpp | 17 +++++++++++-----
 libsanitizer/tsan/tsan_rtl_ppc64.S            |  1 +
 libsanitizer/ubsan/ubsan_flags.cpp            |  1 +
 libsanitizer/ubsan/ubsan_handlers.cpp         | 15 ++++++++++++++
 libsanitizer/ubsan/ubsan_handlers.h           |  8 ++++++++
 libsanitizer/ubsan/ubsan_platform.h           |  2 ++
 14 files changed, 85 insertions(+), 30 deletions(-)

diff --git a/libsanitizer/asan/asan_globals.cpp b/libsanitizer/asan/asan_globals.cpp
index ecc2600f039..326a49798f0 100644
--- a/libsanitizer/asan/asan_globals.cpp
+++ b/libsanitizer/asan/asan_globals.cpp
@@ -153,23 +153,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
   }
 }
 
-// Check ODR violation for given global G by checking if it's already poisoned.
-// We use this method in case compiler doesn't use private aliases for global
-// variables.
-static void CheckODRViolationViaPoisoning(const Global *g) {
-  if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
-    // This check may not be enough: if the first global is much larger
-    // the entire redzone of the second global may be within the first global.
-    for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
-      if (g->beg == l->g->beg &&
-          (flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
-          !IsODRViolationSuppressed(g->name))
-        ReportODRViolation(g, FindRegistrationSite(g),
-                           l->g, FindRegistrationSite(l->g));
-    }
-  }
-}
-
 // Clang provides two different ways for global variables protection:
 // it can poison the global itself or its private alias. In former
 // case we may poison same symbol multiple times, that can help us to
@@ -215,8 +198,6 @@ static void RegisterGlobal(const Global *g) {
     // where two globals with the same name are defined in different modules.
     if (UseODRIndicator(g))
       CheckODRViolationViaIndicator(g);
-    else
-      CheckODRViolationViaPoisoning(g);
   }
   if (CanPoisonMemory())
     PoisonRedZones(*g);
diff --git a/libsanitizer/asan/asan_interceptors.h b/libsanitizer/asan/asan_interceptors.h
index 047b044c8bf..105c672cc24 100644
--- a/libsanitizer/asan/asan_interceptors.h
+++ b/libsanitizer/asan/asan_interceptors.h
@@ -81,7 +81,12 @@ void InitializePlatformInterceptors();
 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
     !SANITIZER_NETBSD
 # define ASAN_INTERCEPT___CXA_THROW 1
-# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
+# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \
+     || ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION
+#   define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
+# else
+#   define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
+# endif
 # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
 #  define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
 # else
diff --git a/libsanitizer/asan/asan_mapping.h b/libsanitizer/asan/asan_mapping.h
index 4ff09b103d5..1b6669e1270 100644
--- a/libsanitizer/asan/asan_mapping.h
+++ b/libsanitizer/asan/asan_mapping.h
@@ -181,7 +181,7 @@
 #  elif defined(__aarch64__)
 #    define ASAN_SHADOW_OFFSET_CONST 0x0000001000000000
 #  elif defined(__powerpc64__)
-#    define ASAN_SHADOW_OFFSET_CONST 0x0000100000000000
+#    define ASAN_SHADOW_OFFSET_CONST 0x0000020000000000
 #  elif defined(__s390x__)
 #    define ASAN_SHADOW_OFFSET_CONST 0x0010000000000000
 #  elif SANITIZER_FREEBSD
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
index 25ad825f568..d966d857a76 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -792,9 +792,13 @@ u32 GetNumberOfCPUs() {
 #elif SANITIZER_SOLARIS
   return sysconf(_SC_NPROCESSORS_ONLN);
 #else
+#if defined(CPU_COUNT)
   cpu_set_t CPUs;
   CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
   return CPU_COUNT(&CPUs);
+#else
+  return 1;
+#endif
 #endif
 }
 
diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
index 05512a576ad..7ce8d670ecc 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp
@@ -38,7 +38,7 @@
 extern char **environ;
 #endif
 
-#if defined(__has_include) && __has_include(<os/trace.h>)
+#if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__)
 #define SANITIZER_OS_TRACE 1
 #include <os/trace.h>
 #else
@@ -71,7 +71,15 @@ extern "C" {
 #include <mach/mach_time.h>
 #include <mach/vm_statistics.h>
 #include <malloc/malloc.h>
-#include <os/log.h>
+#if defined(__has_builtin) && __has_builtin(__builtin_os_log_format)
+# include <os/log.h>
+#else
+   /* Without support for __builtin_os_log_format, fall back to the older
+      method.  */
+# define OS_LOG_DEFAULT 0
+# define os_log_error(A,B,C) \
+  asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", (C));
+#endif
 #include <pthread.h>
 #include <sched.h>
 #include <signal.h>
diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.h b/libsanitizer/sanitizer_common/sanitizer_mac.h
index 0b6af5a3c0e..96a5986a47a 100644
--- a/libsanitizer/sanitizer_common/sanitizer_mac.h
+++ b/libsanitizer/sanitizer_common/sanitizer_mac.h
@@ -14,6 +14,26 @@
 
 #include "sanitizer_common.h"
 #include "sanitizer_platform.h"
+
+/* TARGET_OS_OSX is not present in SDKs before Darwin16 (macOS 10.12) use
+   TARGET_OS_MAC (we have no support for iOS in any form for these versions,
+   so there's no ambiguity).  */
+#if !defined(TARGET_OS_OSX) && TARGET_OS_MAC
+# define TARGET_OS_OSX 1
+#endif
+
+/* Other TARGET_OS_xxx are not present on earlier versions, define them to
+   0 (we have no support for them; they are not valid targets anyway).  */
+#ifndef TARGET_OS_IOS
+#define TARGET_OS_IOS 0
+#endif
+#ifndef TARGET_OS_TV
+#define TARGET_OS_TV 0
+#endif
+#ifndef TARGET_OS_WATCH
+#define TARGET_OS_WATCH 0
+#endif
+
 #if SANITIZER_MAC
 #include "sanitizer_posix.h"
 
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
index 9d577570ea1..2b1a2f7932c 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
@@ -26,7 +26,10 @@
 
 // With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
 // are not defined anywhere in userspace headers. Fake them. This seems to work
-// fine with newer headers, too.
+// fine with newer headers, too.  Beware that with <sys/stat.h>, struct stat
+// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64.
+// Also, for some platforms (e.g. mips) there are additional members in the
+// <sys/stat.h> struct stat:s.
 #include <linux/posix_types.h>
 #  if defined(__x86_64__) || defined(__mips__) || defined(__hexagon__)
 #    include <sys/stat.h>
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index 62a99035db3..89772a7e5c0 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(160, 216);
+                                           : FIRST_32_SECOND_64(144, 216);
 const unsigned struct_kernel_stat64_sz = 104;
 #elif defined(__s390__) && !defined(__s390x__)
 const unsigned struct_kernel_stat_sz = 64;
diff --git a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
index 3013a0c4abd..7386285f34b 100644
--- a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
@@ -87,8 +87,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
   // Nope, this does not look right either. This means the frame after next does
   // not have a valid frame pointer, but we can still extract the caller PC.
   // Unfortunately, there is no way to decide between GCC and LLVM frame
-  // layouts. Assume LLVM.
-  return bp_prev;
+  // layouts. Assume GCC.
+  return bp_prev - 1;
 #else
   return (uhwptr*)bp;
 #endif
@@ -111,14 +111,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
          IsAligned((uptr)frame, sizeof(*frame)) &&
          size < max_depth) {
 #ifdef __powerpc__
-    // PowerPC ABIs specify that the return address is saved at offset
-    // 16 of the *caller's* stack frame.  Thus we must dereference the
-    // back chain to find the caller frame before extracting it.
+    // PowerPC ABIs specify that the return address is saved on the
+    // *caller's* stack frame.  Thus we must dereference the back chain
+    // to find the caller frame before extracting it.
     uhwptr *caller_frame = (uhwptr*)frame[0];
     if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
         !IsAligned((uptr)caller_frame, sizeof(uhwptr)))
       break;
+    // For most ABIs the offset where the return address is saved is two
+    // register sizes.  The exception is the SVR4 ABI, which uses an
+    // offset of only one register size.
+#ifdef _CALL_SYSV
+    uhwptr pc1 = caller_frame[1];
+#else
     uhwptr pc1 = caller_frame[2];
+#endif
 #elif defined(__s390__)
     uhwptr pc1 = frame[14];
 #elif defined(__riscv)
diff --git a/libsanitizer/tsan/tsan_rtl_ppc64.S b/libsanitizer/tsan/tsan_rtl_ppc64.S
index 8285e21aa1e..9e533a71a9c 100644
--- a/libsanitizer/tsan/tsan_rtl_ppc64.S
+++ b/libsanitizer/tsan/tsan_rtl_ppc64.S
@@ -1,5 +1,6 @@
 #include "tsan_ppc_regs.h"
 
+        .machine altivec
         .section .text
         .hidden __tsan_setjmp
         .globl _setjmp
diff --git a/libsanitizer/ubsan/ubsan_flags.cpp b/libsanitizer/ubsan/ubsan_flags.cpp
index 25cefd46ce2..9a66bd37518 100644
--- a/libsanitizer/ubsan/ubsan_flags.cpp
+++ b/libsanitizer/ubsan/ubsan_flags.cpp
@@ -50,6 +50,7 @@ void InitializeFlags() {
   {
     CommonFlags cf;
     cf.CopyFrom(*common_flags());
+    cf.print_summary = false;
     cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
     OverrideCommonFlags(cf);
   }
diff --git a/libsanitizer/ubsan/ubsan_handlers.cpp b/libsanitizer/ubsan/ubsan_handlers.cpp
index e201e6bba22..2184625aa6e 100644
--- a/libsanitizer/ubsan/ubsan_handlers.cpp
+++ b/libsanitizer/ubsan/ubsan_handlers.cpp
@@ -894,6 +894,21 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
 
 }  // namespace __ubsan
 
+void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData,
+                                           ValueHandle Function) {
+  GET_REPORT_OPTIONS(false);
+  CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
+  handleCFIBadIcall(&Data, Function, Opts);
+}
+
+void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData,
+                                                 ValueHandle Function) {
+  GET_REPORT_OPTIONS(true);
+  CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
+  handleCFIBadIcall(&Data, Function, Opts);
+  Die();
+}
+
 void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
                                             ValueHandle Value,
                                             uptr ValidVtable) {
diff --git a/libsanitizer/ubsan/ubsan_handlers.h b/libsanitizer/ubsan/ubsan_handlers.h
index 219fb15de55..9f412353fc0 100644
--- a/libsanitizer/ubsan/ubsan_handlers.h
+++ b/libsanitizer/ubsan/ubsan_handlers.h
@@ -215,12 +215,20 @@ enum CFITypeCheckKind : unsigned char {
   CFITCK_VMFCall,
 };
 
+struct CFIBadIcallData {
+  SourceLocation Loc;
+  const TypeDescriptor &Type;
+};
+
 struct CFICheckFailData {
   CFITypeCheckKind CheckKind;
   SourceLocation Loc;
   const TypeDescriptor &Type;
 };
 
+/// \brief Handle control flow integrity failure for indirect function calls.
+RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function)
+
 /// \brief Handle control flow integrity failures.
 RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
             uptr VtableIsValid)
diff --git a/libsanitizer/ubsan/ubsan_platform.h b/libsanitizer/ubsan/ubsan_platform.h
index d2cc2e10bd2..ad3e883f0f3 100644
--- a/libsanitizer/ubsan/ubsan_platform.h
+++ b/libsanitizer/ubsan/ubsan_platform.h
@@ -12,6 +12,7 @@
 #ifndef UBSAN_PLATFORM_H
 #define UBSAN_PLATFORM_H
 
+#ifndef CAN_SANITIZE_UB
 // Other platforms should be easy to add, and probably work as-is.
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) ||        \
     defined(__NetBSD__) || defined(__DragonFly__) ||                           \
@@ -21,5 +22,6 @@
 #else
 # define CAN_SANITIZE_UB 0
 #endif
+#endif //CAN_SANITIZE_UB
 
 #endif
-- 
2.36.0


[-- Attachment #5: 0001-libsanitizer-merge-from-upstream-0a1bcab9f3bf75c4c5d.patch.bz2 --]
[-- Type: application/x-bzip, Size: 140324 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] libsanitizer: cherry-pick commit f52e365092aa from upstream
  2022-05-04  8:59 libsanitizer: merge from upstream Martin Liška
@ 2022-05-04 23:07 ` H.J. Lu
  2022-05-05 11:24   ` Martin Liška
  2022-08-30 10:53 ` libsanitizer: merge " Martin Liška
  1 sibling, 1 reply; 10+ messages in thread
From: H.J. Lu @ 2022-05-04 23:07 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

On Wed, May 4, 2022 at 1:59 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hello.
>
> I'm going to do merge from upstream.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests. I've also tested
> on ppc64le-linux-gnu and verified the ABI.
>
> The only real change is a small change in
> gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
> where we need --param=asan-use-after-return=0.
>
> I'm going to push the patches.

Hi,

I am checking in this patch to cherry-pick

f52e365092aa [sanitizer] Use newfstatat for x32

to restore x32 build.

-- 
H.J.

[-- Attachment #2: 0001-libsanitizer-cherry-pick-commit-f52e365092aa-from-up.patch --]
[-- Type: application/x-patch, Size: 1530 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] libsanitizer: cherry-pick commit f52e365092aa from upstream
  2022-05-04 23:07 ` [PATCH] libsanitizer: cherry-pick commit f52e365092aa " H.J. Lu
@ 2022-05-05 11:24   ` Martin Liška
  2022-05-05 16:21     ` H.J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-05-05 11:24 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches, Tobias Burnus

On 5/5/22 01:07, H.J. Lu wrote:
> On Wed, May 4, 2022 at 1:59 AM Martin Liška <mliska@suse.cz> wrote:
>> 
>> Hello.
>> 
>> I'm going to do merge from upstream.
>> 
>> Patch can bootstrap on x86_64-linux-gnu and survives regression
>> tests. I've also tested on ppc64le-linux-gnu and verified the ABI.
>> 
>> The only real change is a small change in 
>> gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c where we
>> need --param=asan-use-after-return=0.
>> 
>> I'm going to push the patches.
> 
> Hi,
> 
> I am checking in this patch to cherry-pick
> 
> f52e365092aa [sanitizer] Use newfstatat for x32
> 
> to restore x32 build.
> 

I'm going to do one more merge from upstream
(75f9e83ace52773af65dcebca543005ec8a2705d) as we want to include Tobias's
revision 6f095babc2b7d564168c7afc5bf6afb2188fd6b4 and my
revision f1b9245199f3457a4d06d32d1bc6e44573c166e3.

Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] libsanitizer: cherry-pick commit f52e365092aa from upstream
  2022-05-05 11:24   ` Martin Liška
@ 2022-05-05 16:21     ` H.J. Lu
  2022-05-05 18:28       ` Martin Liška
  0 siblings, 1 reply; 10+ messages in thread
From: H.J. Lu @ 2022-05-05 16:21 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Tobias Burnus

On Thu, May 5, 2022 at 4:24 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 5/5/22 01:07, H.J. Lu wrote:
> > On Wed, May 4, 2022 at 1:59 AM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> Hello.
> >>
> >> I'm going to do merge from upstream.
> >>
> >> Patch can bootstrap on x86_64-linux-gnu and survives regression
> >> tests. I've also tested on ppc64le-linux-gnu and verified the ABI.
> >>
> >> The only real change is a small change in
> >> gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c where we
> >> need --param=asan-use-after-return=0.
> >>
> >> I'm going to push the patches.
> >
> > Hi,
> >
> > I am checking in this patch to cherry-pick
> >
> > f52e365092aa [sanitizer] Use newfstatat for x32
> >
> > to restore x32 build.
> >
>
> I'm going to do one more merge from upstream
> (75f9e83ace52773af65dcebca543005ec8a2705d) as we want to include Tobias's
> revision 6f095babc2b7d564168c7afc5bf6afb2188fd6b4 and my
> revision f1b9245199f3457a4d06d32d1bc6e44573c166e3.

I am testing a patch for

https://github.com/llvm/llvm-project/issues/55288

to fix:

https://gcc.gnu.org/pipermail/gcc-regression/2022-May/076571.html

The same bug is also in GCC 12.  But somehow, it doesn't show up in
GCC tests.

-- 
H.J.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] libsanitizer: cherry-pick commit f52e365092aa from upstream
  2022-05-05 16:21     ` H.J. Lu
@ 2022-05-05 18:28       ` Martin Liška
  2022-05-05 18:40         ` H.J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-05-05 18:28 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches, Tobias Burnus

On 5/5/22 18:21, H.J. Lu wrote:
> On Thu, May 5, 2022 at 4:24 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> On 5/5/22 01:07, H.J. Lu wrote:
>>> On Wed, May 4, 2022 at 1:59 AM Martin Liška <mliska@suse.cz> wrote:
>>>>
>>>> Hello.
>>>>
>>>> I'm going to do merge from upstream.
>>>>
>>>> Patch can bootstrap on x86_64-linux-gnu and survives regression
>>>> tests. I've also tested on ppc64le-linux-gnu and verified the ABI.
>>>>
>>>> The only real change is a small change in
>>>> gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c where we
>>>> need --param=asan-use-after-return=0.
>>>>
>>>> I'm going to push the patches.
>>>
>>> Hi,
>>>
>>> I am checking in this patch to cherry-pick
>>>
>>> f52e365092aa [sanitizer] Use newfstatat for x32
>>>
>>> to restore x32 build.
>>>
>>
>> I'm going to do one more merge from upstream
>> (75f9e83ace52773af65dcebca543005ec8a2705d) as we want to include Tobias's
>> revision 6f095babc2b7d564168c7afc5bf6afb2188fd6b4 and my
>> revision f1b9245199f3457a4d06d32d1bc6e44573c166e3.
> 
> I am testing a patch for
> 
> https://github.com/llvm/llvm-project/issues/55288
> 
> to fix:
> 
> https://gcc.gnu.org/pipermail/gcc-regression/2022-May/076571.html

Interesting. How did you run these tests that the error shows up?

> 
> The same bug is also in GCC 12.  But somehow, it doesn't show up in
> GCC tests.

So please backport it once it's merged.

Martin


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] libsanitizer: cherry-pick commit f52e365092aa from upstream
  2022-05-05 18:28       ` Martin Liška
@ 2022-05-05 18:40         ` H.J. Lu
  0 siblings, 0 replies; 10+ messages in thread
From: H.J. Lu @ 2022-05-05 18:40 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Tobias Burnus

On Thu, May 5, 2022 at 11:28 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 5/5/22 18:21, H.J. Lu wrote:
> > On Thu, May 5, 2022 at 4:24 AM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> On 5/5/22 01:07, H.J. Lu wrote:
> >>> On Wed, May 4, 2022 at 1:59 AM Martin Liška <mliska@suse.cz> wrote:
> >>>>
> >>>> Hello.
> >>>>
> >>>> I'm going to do merge from upstream.
> >>>>
> >>>> Patch can bootstrap on x86_64-linux-gnu and survives regression
> >>>> tests. I've also tested on ppc64le-linux-gnu and verified the ABI.
> >>>>
> >>>> The only real change is a small change in
> >>>> gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c where we
> >>>> need --param=asan-use-after-return=0.
> >>>>
> >>>> I'm going to push the patches.
> >>>
> >>> Hi,
> >>>
> >>> I am checking in this patch to cherry-pick
> >>>
> >>> f52e365092aa [sanitizer] Use newfstatat for x32
> >>>
> >>> to restore x32 build.
> >>>
> >>
> >> I'm going to do one more merge from upstream
> >> (75f9e83ace52773af65dcebca543005ec8a2705d) as we want to include Tobias's
> >> revision 6f095babc2b7d564168c7afc5bf6afb2188fd6b4 and my
> >> revision f1b9245199f3457a4d06d32d1bc6e44573c166e3.
> >
> > I am testing a patch for
> >
> > https://github.com/llvm/llvm-project/issues/55288

I submitted:

https://reviews.llvm.org/D125025

> > to fix:
> >
> > https://gcc.gnu.org/pipermail/gcc-regression/2022-May/076571.html
>
> Interesting. How did you run these tests that the error shows up?

Just normal GCC bootstrap and check with x32 enabled.

> >
> > The same bug is also in GCC 12.  But somehow, it doesn't show up in
> > GCC tests.
>
> So please backport it once it's merged.
>

Will do after GCC 12 is released.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: libsanitizer: merge from upstream
  2022-05-04  8:59 libsanitizer: merge from upstream Martin Liška
  2022-05-04 23:07 ` [PATCH] libsanitizer: cherry-pick commit f52e365092aa " H.J. Lu
@ 2022-08-30 10:53 ` Martin Liška
  2022-09-04 19:50   ` Iain Sandoe
  1 sibling, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-08-30 10:53 UTC (permalink / raw)
  To: GCC Patches

On 5/4/22 10:59, Martin Liška wrote:
> Hello.
> 
> I'm going to do merge from upstream.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests. I've also tested
> on ppc64le-linux-gnu and verified the ABI.
> 
> The only real change is a small change in
> gcc/testsuite/c-c++-common/asan/alloca_loop_unpoisoning.c
> where we need --param=asan-use-after-return=0.
> 
> I'm going to push the patches.
> 
> Thanks,
> Martin

Hi.

I've just done one more merge from upstream.
Upstream revision: 84a71d5259c2682403cdbd8710592410a2f128ab.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: libsanitizer: merge from upstream
  2022-08-30 10:53 ` libsanitizer: merge " Martin Liška
@ 2022-09-04 19:50   ` Iain Sandoe
  2022-09-05  7:31     ` Martin Liška
  0 siblings, 1 reply; 10+ messages in thread
From: Iain Sandoe @ 2022-09-04 19:50 UTC (permalink / raw)
  To: Martin Liska; +Cc: GCC Patches

Hi Martin,

> On 30 Aug 2022, at 11:53, Martin Liška <mliska@suse.cz> wrote:
> 
> On 5/4/22 10:59, Martin Liška wrote:
>> Hello.
> I've just done one more merge from upstream.
> Upstream revision: 84a71d5259c2682403cdbd8710592410a2f128ab.

Which (again) breaks bootstrap on Darwin (since upstream uses features
and APIs not present in GCC and/or supported by the systems we support).

Worked around as below; we will need to find a way to handle the
macOS 13+ changes.

Iain


[pushed] [libsanitizer, Darwin] Fix bootstrap after recent merge.

The latest merge to libsanitizer includes changes to handle macOS 13+.
However, these changes are incompatible with GCC and so we need to find
an alternate solution.  To restore bootstrap back this change out until
the alternate can be found.
---
 .../sanitizer_procmaps_mac.cpp                | 62 +++----------------
 1 file changed, 10 insertions(+), 52 deletions(-)

diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp
index 4b0e6781976..ba4259acd46 100644
--- a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp
@@ -146,8 +146,13 @@ static bool IsDyldHdr(const mach_header *hdr) {
 // until we hit a Mach header matching dyld instead. These recurse
 // calls are expensive, but the first memory map generation occurs
 // early in the process, when dyld is one of the only images loaded,
-// so it will be hit after only a few iterations.  These assumptions don't hold
-// on macOS 13+ anymore (dyld itself has moved into the shared cache).
+// so it will be hit after only a few iterations.  These assumptions don't
+// hold on macOS 13+ anymore (dyld itself has moved into the shared cache).
+
+// FIXME: Unfortunately, the upstream revised version to deal with macOS 13+
+// is incompatible with GCC and also uses APIs not available on earlier
+// systems which we support; backed out for now.
+
 static mach_header *GetDyldImageHeaderViaVMRegion() {
   vm_address_t address = 0;
 
@@ -171,64 +176,17 @@ static mach_header *GetDyldImageHeaderViaVMRegion() {
   }
 }
 
-extern "C" {
-struct dyld_shared_cache_dylib_text_info {
-  uint64_t version;  // current version 2
-  // following fields all exist in version 1
-  uint64_t loadAddressUnslid;
-  uint64_t textSegmentSize;
-  uuid_t dylibUuid;
-  const char *path;  // pointer invalid at end of iterations
-  // following fields all exist in version 2
-  uint64_t textSegmentOffset;  // offset from start of cache
-};
-typedef struct dyld_shared_cache_dylib_text_info
-    dyld_shared_cache_dylib_text_info;
-
-extern bool _dyld_get_shared_cache_uuid(uuid_t uuid);
-extern const void *_dyld_get_shared_cache_range(size_t *length);
-extern int dyld_shared_cache_iterate_text(
-    const uuid_t cacheUuid,
-    void (^callback)(const dyld_shared_cache_dylib_text_info *info));
-}  // extern "C"
-
-static mach_header *GetDyldImageHeaderViaSharedCache() {
-  uuid_t uuid;
-  bool hasCache = _dyld_get_shared_cache_uuid(uuid);
-  if (!hasCache)
-    return nullptr;
-
-  size_t cacheLength;
-  __block uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength);
-  CHECK(cacheStart && cacheLength);
-
-  __block mach_header *dyldHdr = nullptr;
-  int res = dyld_shared_cache_iterate_text(
-      uuid, ^(const dyld_shared_cache_dylib_text_info *info) {
-        CHECK_GE(info->version, 2);
-        mach_header *hdr =
-            (mach_header *)(cacheStart + info->textSegmentOffset);
-        if (IsDyldHdr(hdr))
-          dyldHdr = hdr;
-      });
-  CHECK_EQ(res, 0);
-
-  return dyldHdr;
-}
-
 const mach_header *get_dyld_hdr() {
   if (!dyld_hdr) {
     // On macOS 13+, dyld itself has moved into the shared cache.  Looking it up
     // via vm_region_recurse_64() causes spins/hangs/crashes.
+    // FIXME: find a way to do this compatible with GCC.
     if (GetMacosAlignedVersion() >= MacosVersion(13, 0)) {
-      dyld_hdr = GetDyldImageHeaderViaSharedCache();
-      if (!dyld_hdr) {
         VReport(1,
-                "Failed to lookup the dyld image header in the shared cache on "
-                "macOS 13+ (or no shared cache in use).  Falling back to "
+                "looking up the dyld image header in the shared cache on "
+                "macOS 13+ is not yet supported.  Falling back to "
                 "lookup via vm_region_recurse_64().\n");
         dyld_hdr = GetDyldImageHeaderViaVMRegion();
-      }
     } else {
       dyld_hdr = GetDyldImageHeaderViaVMRegion();
     }
-- 
2.24.3 (Apple Git-128)



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: libsanitizer: merge from upstream
  2022-09-04 19:50   ` Iain Sandoe
@ 2022-09-05  7:31     ` Martin Liška
  2022-09-05  7:44       ` Rainer Orth
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-09-05  7:31 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: GCC Patches

On 9/4/22 21:50, Iain Sandoe wrote:
> Hi Martin,
> 
>> On 30 Aug 2022, at 11:53, Martin Liška <mliska@suse.cz> wrote:
>>
>> On 5/4/22 10:59, Martin Liška wrote:
>>> Hello.
>> I've just done one more merge from upstream.
>> Upstream revision: 84a71d5259c2682403cdbd8710592410a2f128ab.
> 
> Which (again) breaks bootstrap on Darwin (since upstream uses features
> and APIs not present in GCC and/or supported by the systems we support).

Hi.

Can you please report that to upstream and create a patch that would
be accepted by upstream?

Thanks,
Martin

> 
> Worked around as below; we will need to find a way to handle the
> macOS 13+ changes.
> 
> Iain
> 
> 
> [pushed] [libsanitizer, Darwin] Fix bootstrap after recent merge.
> 
> The latest merge to libsanitizer includes changes to handle macOS 13+.
> However, these changes are incompatible with GCC and so we need to find
> an alternate solution.  To restore bootstrap back this change out until
> the alternate can be found.
> ---
>  .../sanitizer_procmaps_mac.cpp                | 62 +++----------------
>  1 file changed, 10 insertions(+), 52 deletions(-)
> 
> diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp
> index 4b0e6781976..ba4259acd46 100644
> --- a/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp
> +++ b/libsanitizer/sanitizer_common/sanitizer_procmaps_mac.cpp
> @@ -146,8 +146,13 @@ static bool IsDyldHdr(const mach_header *hdr) {
>  // until we hit a Mach header matching dyld instead. These recurse
>  // calls are expensive, but the first memory map generation occurs
>  // early in the process, when dyld is one of the only images loaded,
> -// so it will be hit after only a few iterations.  These assumptions don't hold
> -// on macOS 13+ anymore (dyld itself has moved into the shared cache).
> +// so it will be hit after only a few iterations.  These assumptions don't
> +// hold on macOS 13+ anymore (dyld itself has moved into the shared cache).
> +
> +// FIXME: Unfortunately, the upstream revised version to deal with macOS 13+
> +// is incompatible with GCC and also uses APIs not available on earlier
> +// systems which we support; backed out for now.
> +
>  static mach_header *GetDyldImageHeaderViaVMRegion() {
>    vm_address_t address = 0;
>  
> @@ -171,64 +176,17 @@ static mach_header *GetDyldImageHeaderViaVMRegion() {
>    }
>  }
>  
> -extern "C" {
> -struct dyld_shared_cache_dylib_text_info {
> -  uint64_t version;  // current version 2
> -  // following fields all exist in version 1
> -  uint64_t loadAddressUnslid;
> -  uint64_t textSegmentSize;
> -  uuid_t dylibUuid;
> -  const char *path;  // pointer invalid at end of iterations
> -  // following fields all exist in version 2
> -  uint64_t textSegmentOffset;  // offset from start of cache
> -};
> -typedef struct dyld_shared_cache_dylib_text_info
> -    dyld_shared_cache_dylib_text_info;
> -
> -extern bool _dyld_get_shared_cache_uuid(uuid_t uuid);
> -extern const void *_dyld_get_shared_cache_range(size_t *length);
> -extern int dyld_shared_cache_iterate_text(
> -    const uuid_t cacheUuid,
> -    void (^callback)(const dyld_shared_cache_dylib_text_info *info));
> -}  // extern "C"
> -
> -static mach_header *GetDyldImageHeaderViaSharedCache() {
> -  uuid_t uuid;
> -  bool hasCache = _dyld_get_shared_cache_uuid(uuid);
> -  if (!hasCache)
> -    return nullptr;
> -
> -  size_t cacheLength;
> -  __block uptr cacheStart = (uptr)_dyld_get_shared_cache_range(&cacheLength);
> -  CHECK(cacheStart && cacheLength);
> -
> -  __block mach_header *dyldHdr = nullptr;
> -  int res = dyld_shared_cache_iterate_text(
> -      uuid, ^(const dyld_shared_cache_dylib_text_info *info) {
> -        CHECK_GE(info->version, 2);
> -        mach_header *hdr =
> -            (mach_header *)(cacheStart + info->textSegmentOffset);
> -        if (IsDyldHdr(hdr))
> -          dyldHdr = hdr;
> -      });
> -  CHECK_EQ(res, 0);
> -
> -  return dyldHdr;
> -}
> -
>  const mach_header *get_dyld_hdr() {
>    if (!dyld_hdr) {
>      // On macOS 13+, dyld itself has moved into the shared cache.  Looking it up
>      // via vm_region_recurse_64() causes spins/hangs/crashes.
> +    // FIXME: find a way to do this compatible with GCC.
>      if (GetMacosAlignedVersion() >= MacosVersion(13, 0)) {
> -      dyld_hdr = GetDyldImageHeaderViaSharedCache();
> -      if (!dyld_hdr) {
>          VReport(1,
> -                "Failed to lookup the dyld image header in the shared cache on "
> -                "macOS 13+ (or no shared cache in use).  Falling back to "
> +                "looking up the dyld image header in the shared cache on "
> +                "macOS 13+ is not yet supported.  Falling back to "
>                  "lookup via vm_region_recurse_64().\n");
>          dyld_hdr = GetDyldImageHeaderViaVMRegion();
> -      }
>      } else {
>        dyld_hdr = GetDyldImageHeaderViaVMRegion();
>      }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: libsanitizer: merge from upstream
  2022-09-05  7:31     ` Martin Liška
@ 2022-09-05  7:44       ` Rainer Orth
  0 siblings, 0 replies; 10+ messages in thread
From: Rainer Orth @ 2022-09-05  7:44 UTC (permalink / raw)
  To: Martin Liška; +Cc: Iain Sandoe, GCC Patches

Hi Martin,

> On 9/4/22 21:50, Iain Sandoe wrote:
>> Hi Martin,
>> 
>>> On 30 Aug 2022, at 11:53, Martin Liška <mliska@suse.cz> wrote:
>>>
>>> On 5/4/22 10:59, Martin Liška wrote:
>>>> Hello.
>>> I've just done one more merge from upstream.
>>> Upstream revision: 84a71d5259c2682403cdbd8710592410a2f128ab.
>> 
>> Which (again) breaks bootstrap on Darwin (since upstream uses features
>> and APIs not present in GCC and/or supported by the systems we support).
>
> Hi.
>
> Can you please report that to upstream and create a patch that would
> be accepted by upstream?

this may be difficult, unfortunately.  Some time ago, I tried to get an
answer to the question which macOS versions are supposed to be supported
by upstream LLVM and got nothing, despite the massive involvement of
Apple in the project.  Still, it's certainly worth a try.

As a datapoint, both recent libsanitizer imports broke Solaris 11.3
bootstrap, which is still supported by GCC, but never was by LLVM.  In
the first case, I managed to get a patch in to fix that (and a
non-trivial one at that), in the current case I even created the
breakage myself by (again) forgetting that upstream eventually gets
imported into GCC with its wider range of supported Solaris versions.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-09-05  7:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04  8:59 libsanitizer: merge from upstream Martin Liška
2022-05-04 23:07 ` [PATCH] libsanitizer: cherry-pick commit f52e365092aa " H.J. Lu
2022-05-05 11:24   ` Martin Liška
2022-05-05 16:21     ` H.J. Lu
2022-05-05 18:28       ` Martin Liška
2022-05-05 18:40         ` H.J. Lu
2022-08-30 10:53 ` libsanitizer: merge " Martin Liška
2022-09-04 19:50   ` Iain Sandoe
2022-09-05  7:31     ` Martin Liška
2022-09-05  7:44       ` Rainer Orth

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).