From 39056820e9923092fa9ab5178403c3591144da62 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Tue, 30 Apr 2024 09:56:47 +0200 Subject: [PATCH] enabled JIT; added patches to fix instruction detection on x86 and thread safety problem [release 10.43-2mamba;Mon Apr 29 2024] --- ..._locking_region_in_sjlit_malloc_exec.patch | 32 +++++++ ...2-10.43-x86_xgetbv_feature_detection.patch | 83 +++++++++++++++++++ pcre2.spec | 18 ++-- 3 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 pcre2-10.43-fix_locking_region_in_sjlit_malloc_exec.patch create mode 100644 pcre2-10.43-x86_xgetbv_feature_detection.patch diff --git a/pcre2-10.43-fix_locking_region_in_sjlit_malloc_exec.patch b/pcre2-10.43-fix_locking_region_in_sjlit_malloc_exec.patch new file mode 100644 index 0000000..c51e080 --- /dev/null +++ b/pcre2-10.43-fix_locking_region_in_sjlit_malloc_exec.patch @@ -0,0 +1,32 @@ +From ad89dd8ecd25589d236bd20b36f2abf69f938fd1 Mon Sep 17 00:00:00 2001 +From: lbonn +Date: Tue, 2 Apr 2024 12:55:33 +0200 +Subject: [PATCH] Fix locking region in sjlit_malloc_exec (#244) + +The locked section needs to extend until we are done modifying internal +block offsets and sizes, otherwise we risk running into data corruption +in a multi-threaded context. + +This bug was introduced in 7de0fee9a7376b33e31a3903487cd9933da3a606 +--- + sljit_src/allocator_src/sljitExecAllocatorCore.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sljit_src/allocator_src/sljitExecAllocatorCore.c b/sljit_src/allocator_src/sljitExecAllocatorCore.c +index 32c29fb6..4e1119bc 100644 +--- a/sljit_src/allocator_src/sljitExecAllocatorCore.c ++++ b/sljit_src/allocator_src/sljitExecAllocatorCore.c +@@ -235,12 +235,12 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) + header->size = chunk_size; + next_header = AS_BLOCK_HEADER(header, chunk_size); + } +- SLJIT_ALLOCATOR_UNLOCK(); + next_header->size = 1; + next_header->prev_size = chunk_size; + #ifdef SLJIT_HAS_EXECUTABLE_OFFSET + next_header->executable_offset = executable_offset; + #endif /* SLJIT_HAS_EXECUTABLE_OFFSET */ ++ SLJIT_ALLOCATOR_UNLOCK(); + return MEM_START(header); + } + diff --git a/pcre2-10.43-x86_xgetbv_feature_detection.patch b/pcre2-10.43-x86_xgetbv_feature_detection.patch new file mode 100644 index 0000000..aef7b64 --- /dev/null +++ b/pcre2-10.43-x86_xgetbv_feature_detection.patch @@ -0,0 +1,83 @@ +From 56dbde07b05252f0b304b04040a86cfb9f109ae9 Mon Sep 17 00:00:00 2001 +From: Zoltan Herczeg +Date: Sat, 23 Mar 2024 07:51:02 +0000 +Subject: [PATCH] Add xgetbv feature detection support on x86 + +--- + sljit_src/sljitNativeX86_common.c | 42 +++++++++++++++++++++++++++++++ + 1 file changed, 42 insertions(+) + +diff --git a/sljit_src/sljitNativeX86_common.c b/sljit_src/sljitNativeX86_common.c +index 3d5c02b7..de519e6b 100644 +--- a/sljit_src/sljitNativeX86_common.c ++++ b/sljit_src/sljitNativeX86_common.c +@@ -391,6 +391,7 @@ static const sljit_u8 freg_lmap[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2] = { + #define CPU_FEATURE_CMOV 0x020 + #define CPU_FEATURE_AVX 0x040 + #define CPU_FEATURE_AVX2 0x080 ++#define CPU_FEATURE_OSXSAVE 0x100 + + static sljit_u32 cpu_feature_list = 0; + +@@ -491,6 +492,42 @@ static void execute_cpu_id(sljit_u32 info[4]) + #endif /* _MSC_VER && _MSC_VER >= 1400 */ + } + ++static sljit_u32 execute_get_xcr0_low(void) ++{ ++ sljit_u32 xcr0; ++ ++#if defined(_MSC_VER) && _MSC_VER >= 1400 ++ ++ xcr0 = (sljit_u32)_xgetbv(0); ++ ++#elif defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__TINYC__) ++ ++ /* AT&T syntax. */ ++ __asm__ ( ++ "xorl %%ecx, %%ecx\n" ++ "xgetbv\n" ++ : "=a" (xcr0) ++ : ++#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) ++ : "ecx", "edx" ++#else /* !SLJIT_CONFIG_X86_32 */ ++ : "rcx", "rdx" ++#endif /* SLJIT_CONFIG_X86_32 */ ++ ); ++ ++#else /* _MSC_VER < 1400 */ ++ ++ /* Intel syntax. */ ++ __asm { ++ mov ecx, 0 ++ xgetbv ++ mov xcr0, eax ++ } ++ ++#endif /* _MSC_VER && _MSC_VER >= 1400 */ ++ return xcr0; ++} ++ + static void get_cpu_features(void) + { + sljit_u32 feature_list = CPU_FEATURE_DETECTED; +@@ -518,6 +555,8 @@ static void get_cpu_features(void) + + if (info[2] & 0x80000) + feature_list |= CPU_FEATURE_SSE41; ++ if (info[2] & 0x8000000) ++ feature_list |= CPU_FEATURE_OSXSAVE; + if (info[2] & 0x10000000) + feature_list |= CPU_FEATURE_AVX; + #if (defined SLJIT_DETECT_SSE2 && SLJIT_DETECT_SSE2) +@@ -535,6 +574,9 @@ static void get_cpu_features(void) + if (info[2] & 0x20) + feature_list |= CPU_FEATURE_LZCNT; + ++ if ((feature_list & CPU_FEATURE_OSXSAVE) && (execute_get_xcr0_low() & 0x4) == 0) ++ feature_list &= ~(sljit_u32)(CPU_FEATURE_AVX | CPU_FEATURE_AVX2); ++ + cpu_feature_list = feature_list; + } + diff --git a/pcre2.spec b/pcre2.spec index 1be8816..abfdb5a 100644 --- a/pcre2.spec +++ b/pcre2.spec @@ -1,6 +1,6 @@ Name: pcre2 Version: 10.43 -Release: 1mamba +Release: 2mamba Summary: PCRE - Perl Compatible Regular Expressions Group: System/Libraries Vendor: openmamba @@ -8,6 +8,8 @@ Distribution: openmamba Packager: Silvan Calarco URL: https://github.com/PCRE2Project/pcre2 Source: https://github.com/PCRE2Project/pcre2.git/pcre2-%{version}/pcre2-%{version}.tar.bz2 +Patch0: pcre2-10.43-x86_xgetbv_feature_detection.patch +Patch1: pcre2-10.43-fix_locking_region_in_sjlit_malloc_exec.patch License: BSD ## AUTOBUILDREQ-BEGIN BuildRequires: glibc-devel @@ -40,17 +42,18 @@ This package contains libraries and header files for developing applications tha %prep %setup -q +cd src/sljit +%patch 0 -p2 -b .x86_xgetbv_feature_detection +%patch 1 -p2 -b .fix_locking_region_in_sjlit_malloc_exec +cd ../.. sed -i "s| man/man| share/man/man|" CMakeLists.txt %build %cmake -d build \ -DPCRE2_BUILD_PCRE2_16=ON \ - -DPCRE2_BUILD_PCRE2_32=ON - -#% configure \ -# --enable-pcre2-16 \ -# --enable-pcre2-32 + -DPCRE2_BUILD_PCRE2_32=ON \ + -DPCRE2_SUPPORT_JIT=ON %make @@ -106,6 +109,9 @@ mv %{buildroot}/usr/cmake %{buildroot}%{_libdir}/cmake %doc ChangeLog NEWS README %changelog +* Mon Apr 29 2024 Silvan Calarco 10.43-2mamba +- enabled JIT; added patches to fix instruction detection on x86 and thread safety problem + * Tue Feb 20 2024 Automatic Build System 10.43-1mamba - automatic version update by autodist