aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.bp4
-rw-r--r--dist2/CMakeLists.txt11
-rw-r--r--dist2/config-cmake.h.in1
-rw-r--r--dist2/configure.ac18
-rw-r--r--dist2/src/config.h.in3
-rw-r--r--dist2/src/pcre2_internal.h11
-rw-r--r--dist2/src/pcre2_match.c3
-rw-r--r--include_internal/config.h3
8 files changed, 48 insertions, 6 deletions
diff --git a/Android.bp b/Android.bp
index 591acd48..15cc1a83 100644
--- a/Android.bp
+++ b/Android.bp
@@ -38,10 +38,6 @@ cc_defaults {
"-DHAVE_CONFIG_H",
"-Wall",
"-Werror",
- // TODO(http://b/153760240): Remove this once we have
- // patched sources to leave a large stack array uninitialized
- // (stack_frames_vector from pcre2_match.c).
- "-ftrivial-auto-var-init=uninitialized",
],
tidy_checks: [
"-google-build-using-namespace",
diff --git a/dist2/CMakeLists.txt b/dist2/CMakeLists.txt
index 4737687b..a7ef67e1 100644
--- a/dist2/CMakeLists.txt
+++ b/dist2/CMakeLists.txt
@@ -107,8 +107,9 @@ FIND_PACKAGE( Editline )
# Configuration checks
-INCLUDE(CheckIncludeFile)
+INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckFunctionExists)
+INCLUDE(CheckIncludeFile)
INCLUDE(CheckTypeSize)
CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
@@ -123,6 +124,14 @@ CHECK_FUNCTION_EXISTS(bcopy HAVE_BCOPY)
CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
+set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
+CHECK_C_SOURCE_COMPILES(
+ "int main() { char buf[128] __attribute__((uninitialized)); (void)buf; return 0; }"
+ HAVE_ATTRIBUTE_UNINITIALIZED
+)
+set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
+
# User-configurable options
#
# Note: CMakeSetup displays these in alphabetical order, regardless of
diff --git a/dist2/config-cmake.h.in b/dist2/config-cmake.h.in
index 529b0093..44d51ae8 100644
--- a/dist2/config-cmake.h.in
+++ b/dist2/config-cmake.h.in
@@ -1,5 +1,6 @@
/* config.h for CMake builds */
+#cmakedefine HAVE_ATTRIBUTE_UNINITIALIZED 1
#cmakedefine HAVE_DIRENT_H 1
#cmakedefine HAVE_INTTYPES_H 1
#cmakedefine HAVE_STDINT_H 1
diff --git a/dist2/configure.ac b/dist2/configure.ac
index 93c2b531..f3086f18 100644
--- a/dist2/configure.ac
+++ b/dist2/configure.ac
@@ -72,6 +72,24 @@ AC_PROG_LN_S
PCRE2_VISIBILITY
+# Check for Clang __attribute__((uninitialized)) feature
+
+AC_MSG_CHECKING([for __attribute__((uninitialized))])
+AC_LANG_PUSH([C])
+tmp_CFLAGS=$CFLAGS
+CFLAGS="$CFLAGS -Werror"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,
+ [[char buf[128] __attribute__((uninitialized));(void)buf]])],
+ [pcre2_cc_cv_attribute_uninitialized=yes],
+ [pcre2_cc_cv_attribute_uninitialized=no])
+AC_MSG_RESULT([$pcre2_cc_cv_attribute_uninitialized])
+if test "$pcre2_cc_cv_attribute_uninitialized" = yes; then
+ AC_DEFINE([HAVE_ATTRIBUTE_UNINITIALIZED], 1, [Define this if your compiler
+ supports __attribute__((uninitialized))])
+fi
+CFLAGS=$tmp_CFLAGS
+AC_LANG_POP([C])
+
# Versioning
PCRE2_MAJOR="pcre2_major"
diff --git a/dist2/src/config.h.in b/dist2/src/config.h.in
index 6b8eb7e9..5406da0a 100644
--- a/dist2/src/config.h.in
+++ b/dist2/src/config.h.in
@@ -52,6 +52,9 @@ sure both macros are undefined; an emulation function will then be used. */
LF does in an ASCII/Unicode environment. */
#undef EBCDIC_NL25
+/* Define this if your compiler supports __attribute__((uninitialized)) */
+#undef HAVE_ATTRIBUTE_UNINITIALIZED
+
/* Define to 1 if you have the `bcopy' function. */
#undef HAVE_BCOPY
diff --git a/dist2/src/pcre2_internal.h b/dist2/src/pcre2_internal.h
index 814d91bd..aa7ce887 100644
--- a/dist2/src/pcre2_internal.h
+++ b/dist2/src/pcre2_internal.h
@@ -76,6 +76,17 @@ typedef int BOOL;
#include <valgrind/memcheck.h>
#endif
+/* -ftrivial-auto-var-init support supports initializing all local variables
+to avoid some classes of bug, but this can cause an unacceptable slowdown
+for large on-stack arrays in hot functions. This macro lets us annotate
+such arrays. */
+
+#ifdef HAVE_ATTRIBUTE_UNINITIALIZED
+#define PCRE2_KEEP_UNINITIALIZED __attribute__((uninitialized))
+#else
+#define PCRE2_KEEP_UNINITIALIZED
+#endif
+
/* Older versions of MSVC lack snprintf(). This define allows for
warning/error-free compilation and testing with MSVC compilers back to at least
MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */
diff --git a/dist2/src/pcre2_match.c b/dist2/src/pcre2_match.c
index 419561fd..e5cf2c42 100644
--- a/dist2/src/pcre2_match.c
+++ b/dist2/src/pcre2_match.c
@@ -6048,7 +6048,8 @@ proves to be too small, it is replaced by a larger one on the heap. To get a
vector of the size required that is aligned for pointers, allocate it as a
vector of pointers. */
-PCRE2_SPTR stack_frames_vector[START_FRAMES_SIZE/sizeof(PCRE2_SPTR)];
+PCRE2_SPTR stack_frames_vector[START_FRAMES_SIZE/sizeof(PCRE2_SPTR)]
+ PCRE2_KEEP_UNINITIALIZED;
mb->stack_frames = (heapframe *)stack_frames_vector;
/* A length equal to PCRE2_ZERO_TERMINATED implies a zero-terminated
diff --git a/include_internal/config.h b/include_internal/config.h
index a699a139..10c77e5c 100644
--- a/include_internal/config.h
+++ b/include_internal/config.h
@@ -53,6 +53,9 @@ sure both macros are undefined; an emulation function will then be used. */
LF does in an ASCII/Unicode environment. */
/* #undef EBCDIC_NL25 */
+/* Define this if your compiler supports __attribute__((uninitialized)) */
+#define HAVE_ATTRIBUTE_UNINITIALIZED 1
+
/* Define to 1 if you have the `bcopy' function. */
#define HAVE_BCOPY 1