Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package orc for openSUSE:Factory checked in at 2024-09-25 21:51:21 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/orc (Old) and /work/SRC/openSUSE:Factory/.orc.new.29891 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "orc" Wed Sep 25 21:51:21 2024 rev:48 rq:1203294 version:0.4.40 Changes: -------- --- /work/SRC/openSUSE:Factory/orc/orc.changes 2024-07-25 11:59:33.467453193 +0200 +++ /work/SRC/openSUSE:Factory/.orc.new.29891/orc.changes 2024-09-25 21:51:25.675628626 +0200 @@ -1,0 +2,20 @@ +Mon Sep 23 13:26:01 UTC 2024 - Bjørn Lie <bjorn....@gmail.com> + +- Update to version 0.4.40: + + Security: Minor follow-up fixes for CVE-2024-40897 + + Fix include header use from C++ + + orccodemem: Assorted memory mapping fixes + + powerpc: fix div255w which still used the inexact substitution + + powerpc: Disable VSX and ISA 2.07 for Apple targets + + powerpc: Allow detection of ppc64 in Mac OS + + x86: work around old GCC versions (pre 9.0) having broken + xgetbv implementationsv + + x86: consider MSYS2/Cygwin as Windows for ABI purposes only + + x86: handle unnatural and misaligned array pointers + + x86: Fix non-C11 typedefs + + x86: try fixing AVX detection again by adding check for XSAVE + + Some compatibility fixes for Musl + + meson: Fix detecting XSAVE on older AppleClangv + + Check return values of malloc() and realloc() + +------------------------------------------------------------------- Old: ---- orc-0.4.39.tar.xz New: ---- orc-0.4.40.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ orc.spec ++++++ --- /var/tmp/diff_new_pack.v41JYH/_old 2024-09-25 21:51:26.283653952 +0200 +++ /var/tmp/diff_new_pack.v41JYH/_new 2024-09-25 21:51:26.283653952 +0200 @@ -18,7 +18,7 @@ Name: orc -Version: 0.4.39 +Version: 0.4.40 Release: 0 Summary: The Oil Runtime Compiler License: BSD-3-Clause ++++++ orc-0.4.39.tar.xz -> orc-0.4.40.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/.gitlab-ci.yml new/orc-0.4.40/.gitlab-ci.yml --- old/orc-0.4.39/.gitlab-ci.yml 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/.gitlab-ci.yml 2024-09-12 21:04:54.000000000 +0200 @@ -55,6 +55,24 @@ paths: - "build/meson-logs/*txt" +alpine 3.20 ppc64le: + stage: build + tags: + - 'orc-alpine-ppc64' + script: + - apk add git build-base linux-headers meson + - meson setup $MESON_ARGS -Dorc-backend=altivec build/ + - meson compile --verbose -C build/ + - meson test -C build/ + - ORC_DEBUG=2 ./build/tools/orc-bugreport + - meson install -C build/ + artifacts: + name: "${CI_JOB_NAME}_${CI_COMMIT_SHA}" + expire_in: '5 days' + when: 'always' + paths: + - "build/meson-logs/*txt" + debian sid: extends: '.debian' image: 'debian:sid-slim' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/RELEASE new/orc-0.4.40/RELEASE --- old/orc-0.4.39/RELEASE 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/RELEASE 2024-09-12 21:04:54.000000000 +0200 @@ -1,8 +1,27 @@ +0.4.40 +====== + +- Security: Minor follow-up fixes for CVE-2024-40897 (Sebastian Dröge) +- powerpc: fix div255w which still used the inexact substitution (L. E. Segovia) +- x86: work around old GCC versions (pre 9.0) having broken xgetbv + implementations (L. E. Segovia) +- x86: consider MSYS2/Cygwin as Windows for ABI purposes only (L. E. Segovia) +- x86: handle unnatural and misaligned array pointers (L. E. Segovia) +- orccodemem: Assorted memory mapping fixes (L. E. Segovia) +- Fix include header use from C++ (Kleis Auke Wolthuizen) +- Some compatibility fixes for Musl (L. E. Segovia) +- ppc: Disable VSX and ISA 2.07 for Apple targets (L. E. Segovia) +- ppc: Allow detection of ppc64 in Mac OS (L. E. Segovia) +- x86: Fix non-C11 typedefs (L. E. Segovia) +- meson: Fix detecting XSAVE on older AppleClang (L. E. Segovia) +- x86: try fixing AVX detection again by adding check for XSAVE (L. E. Segovia) +- Check return values of malloc() and realloc() (Vladimir D. Seleznev) + 0.4.39 ====== - Security: Fix error message printing buffer overflow leading to possible - code executation in orcc with specific input files (CVE-2024-40897). This + code execution in orcc with specific input files (CVE-2024-40897). This only affects developers and CI environments using orcc, not users of liborc (Sebastian Dröge, L. E. Segovia) - div255w: fix off-by-one error in the implementations (L. E. Segovia) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/examples/volscale.c new/orc-0.4.40/examples/volscale.c --- old/orc-0.4.39/examples/volscale.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/examples/volscale.c 2024-09-12 21:04:54.000000000 +0200 @@ -145,7 +145,7 @@ static void -do_volume_backup (OrcExecutor *ex) +do_volume_backup (OrcExecutor * ORC_RESTRICT ex) { orc_int16 *dest; orc_int32 *vols; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/meson.build new/orc-0.4.40/meson.build --- old/orc-0.4.39/meson.build 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/meson.build 2024-09-12 21:04:54.000000000 +0200 @@ -1,4 +1,4 @@ -project ('orc', 'c', version : '0.4.39', +project ('orc', 'c', version : '0.4.40', meson_version : '>= 0.55.0', default_options : ['buildtype=debugoptimized', 'warning_level=1'] ) @@ -124,6 +124,11 @@ cdata.set('HAVE_THREAD_PTHREAD', true) endif +if cpu_family.startswith('x86') and cc.get_define('_MSC_VER') == '' + xgetbv = cc.has_header_symbol('immintrin.h', '_xgetbv') or cc.has_header_symbol('xsaveintrin.h', '_xgetbv') + cdata.set('ORC_NEEDS_ASM_XSAVE', not xgetbv) +endif + monotonic_test = ''' #include <time.h> #include <unistd.h> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orc.c new/orc-0.4.40/orc/orc.c --- old/orc-0.4.39/orc/orc.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orc.c 2024-09-12 21:04:54.000000000 +0200 @@ -14,6 +14,7 @@ #include <orc/orcprogram.h> #include <orc/orcdebug.h> +#include <orc/orcutils-private.h> #include <orc/orconce.h> #include "orcinternal.h" @@ -109,7 +110,7 @@ return NULL; /* max size of len is 32767, cannot overflow */ - value = malloc (sizeof (value) * len); + value = orc_malloc (sizeof (value) * len); if (GetEnvironmentVariableA (key, value, len) != (len - 1)) { free (value); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orc.h new/orc-0.4.40/orc/orc.h --- old/orc-0.4.39/orc/orc.h 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orc.h 2024-09-12 21:04:54.000000000 +0200 @@ -9,8 +9,11 @@ #include <orc/orcparse.h> #include <orc/orccpu.h> +ORC_BEGIN_DECLS + ORC_API void orc_init (void); ORC_API const char * orc_version_string (void); -#endif +ORC_END_DECLS +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcbytecode.c new/orc-0.4.40/orc/orcbytecode.c --- old/orc-0.4.39/orc/orcbytecode.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcbytecode.c 2024-09-12 21:04:54.000000000 +0200 @@ -5,6 +5,7 @@ #include <orc/orc.h> #include <orc/orcbytecode.h> +#include <orc/orcutils-private.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -22,11 +23,11 @@ { OrcBytecode *bytecode; - bytecode = malloc (sizeof(OrcBytecode)); + bytecode = orc_malloc (sizeof(OrcBytecode)); memset (bytecode, 0, sizeof(OrcBytecode)); bytecode->alloc_len = 256; - bytecode->bytecode = malloc(bytecode->alloc_len); + bytecode->bytecode = orc_malloc(bytecode->alloc_len); return bytecode; } @@ -188,7 +189,7 @@ { if (bytecode->length >= bytecode->alloc_len) { bytecode->alloc_len += 256; - bytecode->bytecode = realloc (bytecode->bytecode, bytecode->alloc_len); + bytecode->bytecode = orc_realloc (bytecode->bytecode, bytecode->alloc_len); } bytecode->bytecode[bytecode->length] = byte; bytecode->length++; @@ -335,7 +336,7 @@ char *s; len = orc_bytecode_parse_get_int (parse); - s = malloc (len + 1); + s = orc_malloc (len + 1); for(i=0;i<len;i++){ s[i] = orc_bytecode_parse_get_byte (parse); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orccode.c new/orc-0.4.40/orc/orccode.c --- old/orc-0.4.39/orc/orccode.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orccode.c 2024-09-12 21:04:54.000000000 +0200 @@ -7,6 +7,7 @@ #include <orc/orcprogram.h> #include <orc/orcdebug.h> +#include <orc/orcutils-private.h> #include <orc/orcinternal.h> #ifdef _WIN64 @@ -17,7 +18,7 @@ orc_code_new (void) { OrcCode *code; - code = malloc(sizeof(OrcCode)); + code = orc_malloc(sizeof(OrcCode)); memset (code, 0, sizeof(OrcCode)); return code; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orccodemem.c new/orc-0.4.40/orc/orccodemem.c --- old/orc-0.4.39/orc/orccodemem.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orccodemem.c 2024-09-12 21:04:54.000000000 +0200 @@ -15,7 +15,6 @@ #ifdef HAVE_CODEMEM_MMAP #include <sys/mman.h> -#include <sys/errno.h> #endif #ifdef HAVE_CODEMEM_VIRTUALALLOC @@ -29,6 +28,7 @@ #include <orc/orcinternal.h> #include <orc/orcprogram.h> +#include <orc/orcutils-private.h> #include <orc/orcdebug.h> @@ -68,7 +68,7 @@ { OrcCodeRegion *region; - region = malloc(sizeof(OrcCodeRegion)); + region = orc_malloc(sizeof(OrcCodeRegion)); memset (region, 0, sizeof(OrcCodeRegion)); if (!orc_code_region_allocate_codemem (region)) { @@ -91,7 +91,7 @@ return NULL; } - chunk = malloc(sizeof(OrcCodeChunk)); + chunk = orc_malloc(sizeof(OrcCodeChunk)); memset (chunk, 0, sizeof(OrcCodeChunk)); chunk->offset = 0; @@ -109,7 +109,7 @@ { OrcCodeChunk *newchunk; - newchunk = malloc(sizeof(OrcCodeChunk)); + newchunk = orc_malloc(sizeof(OrcCodeChunk)); memset (newchunk, 0, sizeof(OrcCodeChunk)); newchunk->region = chunk->region; @@ -187,7 +187,7 @@ OrcCodeRegion *region; OrcCodeChunk *chunk; int aligned_size = - (size + _orc_codemem_alignment) & (~_orc_codemem_alignment); + (MAX(1, size) + _orc_codemem_alignment) & (~_orc_codemem_alignment); orc_global_mutex_lock (); chunk = orc_code_region_get_free_chunk (aligned_size); @@ -195,8 +195,7 @@ orc_global_mutex_unlock (); ORC_ERROR ("Failed to get free chunk memory"); - /* TODO: error out more gracefully? */ - ORC_ASSERT (0); + return; } region = chunk->region; @@ -367,10 +366,18 @@ /* On UWP, we can't allocate memory as executable from the start. We can only * set that later after compiling and copying the code over. This is a good * idea in general to avoid security issues, so we do it on win32 too. */ - void *write_ptr; + void *write_ptr = NULL; + char *msg = NULL; write_ptr = _virtualalloc (NULL, SIZE, MEM_COMMIT, PAGE_READWRITE); - if (!write_ptr) + if (!write_ptr) { + FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, GetLastError(), 0, (LPTSTR)&msg, 0, NULL); + ORC_ERROR ("Couldn't allocate mapping on %p of size %d: %s", region, + SIZE, msg); + LocalFree (msg); return FALSE; + } region->write_ptr = write_ptr; region->exec_ptr = region->write_ptr; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orccompiler.c new/orc-0.4.40/orc/orccompiler.c --- old/orc-0.4.39/orc/orccompiler.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orccompiler.c 2024-09-12 21:04:54.000000000 +0200 @@ -431,11 +431,11 @@ program->orccode->exec = program->code_exec; program->orccode->n_insns = compiler->n_insns; - program->orccode->insns = malloc(sizeof(OrcInstruction) * compiler->n_insns); + program->orccode->insns = orc_malloc(sizeof(OrcInstruction) * compiler->n_insns); memcpy (program->orccode->insns, compiler->insns, sizeof(OrcInstruction) * compiler->n_insns); - program->orccode->vars = malloc (sizeof(OrcCodeVariable) * ORC_N_COMPILER_VARIABLES); + program->orccode->vars = orc_malloc (sizeof(OrcCodeVariable) * ORC_N_COMPILER_VARIABLES); memset (program->orccode->vars, 0, sizeof(OrcCodeVariable) * ORC_N_COMPILER_VARIABLES); for(i=0;i<ORC_N_COMPILER_VARIABLES;i++){ @@ -469,7 +469,7 @@ if (compiler->error) goto error; ORC_INFO("allocating code memory"); - compiler->code = malloc(65536); + compiler->code = orc_malloc(65536); compiler->codeptr = compiler->code; if (compiler->error) goto error; @@ -576,6 +576,13 @@ #endif orc_code_allocate_codemem (program->orccode, program->orccode->code_size); + if (program->orccode->chunk == NULL) { + program->code_exec = (void *)orc_executor_emulate; + program->orccode->exec = (void *)orc_executor_emulate; + orc_compiler_error (compiler, "Cannot reserve executable memory, using emulation"); + compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE; + goto error; + } #if defined(__APPLE__) && (!defined(TARGET_OS_OSX) || TARGET_OS_OSX) #if defined(MAC_OS_VERSION_11_0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 @@ -1256,7 +1263,7 @@ compiler->vars[i].vartype = ORC_VAR_TYPE_TEMP; compiler->vars[i].size = compiler->vars[var].size; - compiler->vars[i].name = malloc (strlen(compiler->vars[var].name) + 10); + compiler->vars[i].name = orc_malloc (strlen(compiler->vars[var].name) + 10); sprintf(compiler->vars[i].name, "%s.dup%d", compiler->vars[var].name, j); compiler->n_dup_vars++; @@ -1270,7 +1277,7 @@ compiler->vars[i].vartype = ORC_VAR_TYPE_TEMP; compiler->vars[i].size = size; - compiler->vars[i].name = malloc (10); + compiler->vars[i].name = orc_malloc (10); sprintf(compiler->vars[i].name, "tmp%d", i); compiler->n_dup_vars++; @@ -1312,7 +1319,7 @@ va_end (varargs); n = strlen (tmp); - p->asm_code = realloc (p->asm_code, p->asm_code_len + n + 1); + p->asm_code = orc_realloc (p->asm_code, p->asm_code_len + n + 1); memcpy (p->asm_code + p->asm_code_len, tmp, n + 1); p->asm_code_len += n; } @@ -1490,12 +1497,13 @@ if (compiler->error_msg) return; #ifdef HAVE_VASPRINTF - vasprintf (&s, fmt, args); + if (vasprintf (&s, fmt, args) < 0) + ORC_ASSERT (0); #elif defined(_UCRT) - s = malloc (ORC_COMPILER_ERROR_BUFFER_SIZE); + s = orc_malloc (ORC_COMPILER_ERROR_BUFFER_SIZE); vsnprintf_s (s, ORC_COMPILER_ERROR_BUFFER_SIZE, _TRUNCATE, fmt, args); #else - s = malloc (ORC_COMPILER_ERROR_BUFFER_SIZE); + s = orc_malloc (ORC_COMPILER_ERROR_BUFFER_SIZE); vsnprintf (s, ORC_COMPILER_ERROR_BUFFER_SIZE, fmt, args); #endif compiler->error_msg = s; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orccpu-x86.c new/orc-0.4.40/orc/orccpu-x86.c --- old/orc-0.4.39/orc/orccpu-x86.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orccpu-x86.c 2024-09-12 21:04:54.000000000 +0200 @@ -34,6 +34,17 @@ #ifdef _MSC_VER # include <intrin.h> +#elif defined(__GNUC__) +#if __GNUC__ >= 8 && __GNUC__ < 9 +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71659 +# include <xsaveintrin.h> +#endif +#endif + +#if !defined(_MSC_VER) || defined(__clang__) +#define ORC_TARGET_XSAVE __attribute__((target("xsave"))) +#else +#define ORC_TARGET_XSAVE #endif #include <orc/orcdebug.h> @@ -304,15 +315,26 @@ // Checks if XMM and YMM state are enabled in XCR0. // See 14.3 DETECTION OF INTEL® AVX INSTRUCTIONS on the // Intel® 64 and IA-32 Architectures Software Developerâs Manual -#if !defined(_MSC_VER) || defined(__clang__) -#define ORC_TARGET_XSAVE __attribute__((target("xsave"))) +#define XSAVE_SUPPORT_XMM 1U << 1 +#define XSAVE_SUPPORT_YMM 1U << 2 +// On a kernel with Gather Data Sampling mitigation, the former will +// be disabled -- both bits must be enabled, otherwise it'll hit an +// undefined opcode trap. +// See https://docs.kernel.org/admin-guide/hw-vuln/gather_data_sampling.html +#define XSAVE_SUPPORT_AVX (XSAVE_SUPPORT_YMM | XSAVE_SUPPORT_XMM) +#ifdef ORC_NEEDS_ASM_XSAVE +static orc_bool check_xcr0_ymm() +{ + uint32_t xcr0; + __asm__ ("xgetbv" : "=a" (xcr0) : "c" (0) : "%edx" ); + return ((xcr0 & XSAVE_SUPPORT_AVX) == XSAVE_SUPPORT_AVX); +} #else -#define ORC_TARGET_XSAVE -#endif static orc_bool ORC_TARGET_XSAVE check_xcr0_ymm() { - return (_xgetbv(0) & 6U) != 0U; + return (_xgetbv(0) & XSAVE_SUPPORT_AVX) == XSAVE_SUPPORT_AVX; } +#endif static void orc_x86_cpuid_handle_standard_flags (void) @@ -345,14 +367,16 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=1854795 // https://gitlab.freedesktop.org/gstreamer/orc/-/issues/65 - orc_bool osxsave_enabled = (ecx & (1 << 27)) != 0; - const int avx_instructions_supported = ecx & (1 << 28); + // check for xsave enabled (bit 26) and xsave available (bit 27) + const orc_uint32 xsave_bits = (1U << 26) | (1U << 27); + orc_bool osxsave_enabled = (ecx & xsave_bits) == xsave_bits; + const orc_bool avx_instructions_supported = (ecx & (1 << 28)) != 0; get_cpuid (0x00000007, &eax, &ebx, &ecx, &edx); - const int avx2_instructions_supported = ebx & (1 << 5); + const orc_bool avx2_instructions_supported = (ebx & (1 << 5)) != 0; - // If xgetbv is available, validate YMM state available + // If xgetbv is available, validate XMM and YMM state available if (osxsave_enabled) { osxsave_enabled = check_xcr0_ymm(); } @@ -362,7 +386,7 @@ orc_x86_sse_flags |= ORC_TARGET_AVX_AVX; } - if (avx2_instructions_supported) { + if (avx_instructions_supported && avx2_instructions_supported) { orc_x86_sse_flags |= ORC_TARGET_AVX_AVX2; } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcexecutor.c new/orc-0.4.40/orc/orcexecutor.c --- old/orc-0.4.39/orc/orcexecutor.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcexecutor.c 2024-09-12 21:04:54.000000000 +0200 @@ -6,6 +6,7 @@ #include <stdlib.h> #include <orc/orcprogram.h> +#include <orc/orcutils-private.h> #include <orc/orcdebug.h> /** @@ -21,7 +22,7 @@ { OrcExecutor *ex; - ex = malloc(sizeof(OrcExecutor)); + ex = orc_malloc(sizeof(OrcExecutor)); memset(ex,0,sizeof(OrcExecutor)); orc_executor_set_program (ex, program); @@ -278,11 +279,11 @@ OrcCodeVariable *var = code->vars + i; if (var->size) { - tmpspace[i] = malloc(ORC_MAX_VAR_SIZE * CHUNK_SIZE); + tmpspace[i] = orc_malloc(ORC_MAX_VAR_SIZE * CHUNK_SIZE); } } - opcode_ex = malloc(sizeof(OrcOpcodeExecutor)*code->n_insns); + opcode_ex = orc_malloc(sizeof(OrcOpcodeExecutor)*code->n_insns); for(j=0;j<code->n_insns;j++){ insn = code->insns + j; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcopcode.c new/orc-0.4.40/orc/orcopcode.c --- old/orc-0.4.39/orc/orcopcode.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcopcode.c 2024-09-12 21:04:54.000000000 +0200 @@ -5,6 +5,7 @@ #include <orc/orcprogram.h> #include <orc/orcdebug.h> #include <orc/orcinternal.h> +#include <orc/orcutils-private.h> /** * SECTION:orcopcode @@ -34,7 +35,7 @@ if (n_opcodes == n_opcodes_alloc) { n_opcodes_alloc += 100; - opcode_list = realloc(opcode_list, sizeof(OrcOpcode) * n_opcodes_alloc); + opcode_list = orc_realloc(opcode_list, sizeof(OrcOpcode) * n_opcodes_alloc); } opcode = opcode_list + n_opcodes; @@ -63,8 +64,8 @@ major = n_opcode_sets; n_opcode_sets++; - opcode_sets = realloc (opcode_sets, sizeof(OrcOpcodeSet)*n_opcode_sets); - + opcode_sets = orc_realloc (opcode_sets, sizeof(OrcOpcodeSet)*n_opcode_sets); + memset (opcode_sets + major, 0, sizeof(OrcOpcodeSet)); strncpy(opcode_sets[major].prefix, prefix, sizeof(opcode_sets[major].prefix)-1); opcode_sets[major].n_opcodes = n; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcparse.c new/orc-0.4.40/orc/orcparse.c --- old/orc-0.4.39/orc/orcparse.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcparse.c 2024-09-12 21:04:54.000000000 +0200 @@ -362,7 +362,7 @@ int n = sizeof ("error: 123456789012345 \n") + strlen (errors[i]->source) + strlen (errors[i]->text); if (len + n >= size) { size += MAX (n, 256); - _log = realloc(_log, size); + _log = orc_realloc(_log, size); } len += sprintf (_log + len, "%s @ %i: error: %s\n", errors[i]->source, errors[i]->line_number, errors[i]->text); } @@ -430,7 +430,8 @@ #ifdef HAVE_VASPRINTF char *text = NULL; - vasprintf (&text, format, args); + if (vasprintf (&text, format, args) < 0) + ORC_ASSERT (0); #elif defined(_UCRT) char text[ORC_ERROR_LENGTH] = { '\0' }; vsnprintf_s (text, ORC_ERROR_LENGTH, _TRUNCATE, format, args); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram-altivec.c new/orc-0.4.40/orc/orcprogram-altivec.c --- old/orc-0.4.39/orc/orcprogram-altivec.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram-altivec.c 2024-09-12 21:04:54.000000000 +0200 @@ -108,7 +108,7 @@ { unsigned int flags = 0; -#ifdef __powerpc64__ +#if defined(__powerpc64__) || defined(__ppc64__) flags |= ORC_TARGET_POWERPC_64BIT; #endif #if defined(__LITTLE_ENDIAN__) @@ -119,9 +119,11 @@ flags |= orc_powerpc_cpu_flags; #else flags |= ORC_TARGET_POWERPC_ALTIVEC; +#ifndef __APPLE__ flags |= ORC_TARGET_POWERPC_VSX; flags |= ORC_TARGET_POWERPC_V207; #endif +#endif return flags; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram-avx.c new/orc-0.4.40/orc/orcprogram-avx.c --- old/orc-0.4.39/orc/orcprogram-avx.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram-avx.c 2024-09-12 21:04:54.000000000 +0200 @@ -9,6 +9,7 @@ #include <string.h> #include <sys/types.h> +#include <orc/orcx86.h> #include <orc/orcx86-private.h> #include <orc/orcavx.h> #include <orc/orcavx-internal.h> @@ -96,7 +97,7 @@ static void avx_saveable_registers (int *regs, int is_64bit) { -#ifdef HAVE_OS_WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) if (is_64bit) { int i; for (i = 6; i < ORC_AVX_REG_AMOUNT; i++) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram-mips.c new/orc-0.4.40/orc/orcprogram-mips.c --- old/orc-0.4.39/orc/orcprogram-mips.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram-mips.c 2024-09-12 21:04:54.000000000 +0200 @@ -31,6 +31,7 @@ #include <orc/orcmips.h> #include <orc/orcdebug.h> +#include <orc/orcutils-private.h> #include <orc/orcinternal.h> #include <stdlib.h> #include <string.h> @@ -415,7 +416,7 @@ if (compiler->n_insns == 0) return NULL; - instruction_idx = malloc (compiler->n_insns * sizeof(int)); + instruction_idx = orc_malloc (compiler->n_insns * sizeof(int)); for (i=0; i<compiler->n_insns; i++) instruction_idx[i] = i; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram-mmx.c new/orc-0.4.40/orc/orcprogram-mmx.c --- old/orc-0.4.39/orc/orcprogram-mmx.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram-mmx.c 2024-09-12 21:04:54.000000000 +0200 @@ -92,7 +92,7 @@ static void mmx_saveable_registers (int *regs, int is_64bit) { -#ifdef HAVE_OS_WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) if (is_64bit) { int i; for(i = X86_MM0 + 6; i < X86_MM0 + ORC_REG_SIZE; i++){ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram-sse.c new/orc-0.4.40/orc/orcprogram-sse.c --- old/orc-0.4.39/orc/orcprogram-sse.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram-sse.c 2024-09-12 21:04:54.000000000 +0200 @@ -91,7 +91,7 @@ static void sse_saveable_registers (int *regs, int is_64bit) { -#ifdef HAVE_OS_WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) if (is_64bit) { int i; for(i = X86_XMM0 + 6; i < X86_XMM0 + 16; i++){ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram-x86.c new/orc-0.4.40/orc/orcprogram-x86.c --- old/orc-0.4.39/orc/orcprogram-x86.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram-x86.c 2024-09-12 21:04:54.000000000 +0200 @@ -6,10 +6,15 @@ #include <string.h> #include <orc/orcprogram.h> +#include <orc/orcutils-private.h> #include <orc/orcx86.h> #include <orc/orcx86-private.h> #include <orc/orcinternal.h> +#if defined(_WIN32) +#include <windows.h> +#endif + #define ORC_X86_ALIGNED_DEST_CUTOFF 64 #define LABEL_REGION1_SKIP 1 #define LABEL_INNER_LOOP_START 2 @@ -27,7 +32,7 @@ t->validate_registers (c->valid_regs, c->is_64bit); } -#ifdef HAVE_OS_WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) static void orc_x86_saveable_registers (OrcX86Target *t, OrcCompiler *c) { @@ -95,7 +100,7 @@ c->save_regs[X86_R13] = 1; c->save_regs[X86_R14] = 1; c->save_regs[X86_R15] = 1; -#ifdef HAVE_OS_WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) c->save_regs[X86_EDI] = 1; c->save_regs[X86_ESI] = 1; // When present, the upper portions of YMM0-YMM15 and ZMM0-ZMM15 are also @@ -123,7 +128,7 @@ } if (c->is_64bit) { -#ifdef HAVE_OS_WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) c->exec_reg = X86_ECX; c->gp_tmpreg = X86_EDX; #else @@ -442,6 +447,20 @@ return t->get_shift(size); } +static inline orc_bool +has_valid_alignment (const OrcVariable *var) +{ + return (var->alignment % var->size) == 0; +} + +static inline orc_bool +can_be_validly_aligned (const OrcVariable *var, const OrcX86Target *t) +{ + const orc_bool alignment_matches_register = + (var->alignment % t->register_size) == 0; + return alignment_matches_register && has_valid_alignment (var); +} + static void orc_x86_emit_split_3_regions (OrcX86Target *t, OrcCompiler *compiler) { @@ -680,7 +699,7 @@ if (compiler->n_insns == 0) return NULL; - int *const instruction_idx = malloc (compiler->n_insns * sizeof(int)); + int *const instruction_idx = orc_malloc (compiler->n_insns * sizeof(int)); for (int i=0; i<compiler->n_insns; i++) instruction_idx[i] = i; @@ -795,7 +814,7 @@ for (i = ORC_VAR_D1; i <= ORC_VAR_S8; i++) { if (compiler->vars[i].size == 0) continue; - if ((compiler->vars[i].alignment % t->register_size) == 0) { + if (can_be_validly_aligned (&compiler->vars[i], t)) { compiler->vars[i].is_aligned = TRUE; } else { compiler->vars[i].is_aligned = FALSE; @@ -950,7 +969,8 @@ } compiler->loop_shift = save_loop_shift; - compiler->vars[align_var].is_aligned = TRUE; + /* Consider as aligned only if the alignment allows so */ + compiler->vars[align_var].is_aligned = has_valid_alignment (&compiler->vars[align_var]); } orc_x86_emit_label (compiler, LABEL_REGION1_SKIP); @@ -1036,6 +1056,30 @@ orc_x86_do_fixups (compiler); } +static void +orc_x86_flush_cache (OrcCode *code) +{ +#if defined(__APPLE__) + sys_dcache_flush(code->code, code->code_size); + sys_icache_invalidate(code->exec, code->code_size); +#elif defined (_WIN32) + HANDLE h_proc = GetCurrentProcess(); + + FlushInstructionCache(h_proc, code->code, code->code_size); + + if ((void *) code->exec != (void *) code->code) + FlushInstructionCache(h_proc, code->exec, code->code_size); +#elif __has_builtin(__builtin_clear_cache) + __builtin_clear_cache (code->code, code->code + code->code_size); + if ((void *) code->exec != (void *) code->code) + __builtin_clear_cache (code->exec, code->exec + code->code_size); +#else + __clear_cache (code->code, code->code + code->code_size); + if ((void *) code->exec != (void *) code->code) + __clear_cache (code->exec, code->exec + code->code_size); +#endif +} + void orc_x86_register_extension (OrcTarget *t, OrcX86Target *x86t) { @@ -1054,6 +1098,7 @@ t->load_constant = orc_x86_load_constant; t->get_flag_name = x86t->get_flag_name; t->load_constant_long = x86t->load_constant_long; + t->flush_cache = orc_x86_flush_cache; t->target_data = x86t; orc_target_register (t); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcprogram.c new/orc-0.4.40/orc/orcprogram.c --- old/orc-0.4.39/orc/orcprogram.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcprogram.c 2024-09-12 21:04:54.000000000 +0200 @@ -36,10 +36,10 @@ */ orc_init (); - p = malloc(sizeof(OrcProgram)); + p = orc_malloc(sizeof(OrcProgram)); memset (p, 0, sizeof(OrcProgram)); - p->name = malloc (40); + p->name = orc_malloc (40); sprintf(p->name, "func_%p", p); return p; @@ -364,7 +364,7 @@ program->vars[i].vartype = ORC_VAR_TYPE_TEMP; program->vars[i].size = program->vars[var].size; - program->vars[i].name = malloc (strlen(program->vars[var].name) + 10); + program->vars[i].name = orc_malloc (strlen(program->vars[var].name) + 10); sprintf(program->vars[i].name, "%s.dup%d", program->vars[var].name, j); program->n_temp_vars++; @@ -1303,7 +1303,7 @@ { OrcCompiler *compiler; - compiler = malloc (sizeof(OrcCompiler)); + compiler = orc_malloc (sizeof(OrcCompiler)); memset (compiler, 0, sizeof(OrcCompiler)); return orc_compiler_compile_program (compiler, program, target, flags); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcrule.c new/orc-0.4.40/orc/orcrule.c --- old/orc-0.4.39/orc/orcrule.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcrule.c 2024-09-12 21:04:54.000000000 +0200 @@ -6,6 +6,7 @@ #include <stdlib.h> #include <orc/orcprogram.h> +#include <orc/orcutils-private.h> #include <orc/orcdebug.h> /** @@ -49,7 +50,7 @@ rule_set->opcode_major = opcode_set->opcode_major; rule_set->required_target_flags = required_flags; - rule_set->rules = malloc (sizeof(OrcRule) * opcode_set->n_opcodes); + rule_set->rules = orc_malloc (sizeof(OrcRule) * opcode_set->n_opcodes); memset (rule_set->rules, 0, sizeof(OrcRule) * opcode_set->n_opcodes); return rule_set; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcrules-altivec.c new/orc-0.4.40/orc/orcrules-altivec.c --- old/orc-0.4.39/orc/orcrules-altivec.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcrules-altivec.c 2024-09-12 21:04:54.000000000 +0200 @@ -1513,23 +1513,22 @@ static void powerpc_rule_div255w (OrcCompiler *p, void *user, OrcInstruction *insn) { - int src1 = ORC_SRC_ARG (p, insn, 0); - int dest = ORC_DEST_ARG (p, insn, 0); - int tmp = orc_compiler_get_temp_reg (p); - int tmp2 = orc_compiler_get_temp_reg (p); - int tmpc; + const int src1 = ORC_SRC_ARG (p, insn, 0); + const int dest = ORC_DEST_ARG(p, insn, 0); + const int tmp = powerpc_get_constant (p, ORC_CONST_SPLAT_W, 7); + const int tmpc = powerpc_get_constant (p, ORC_CONST_SPLAT_W, 0x8081); + + { + // mulhuw + const int perm = powerpc_get_constant_full(p, 0x10110001, 0x14150405, + 0x18190809, 0x1c1d0c0d); + + powerpc_emit_vmuleuh (p, p->tmpreg, src1, tmpc); + powerpc_emit_vmulouh (p, dest, src1, tmpc); + powerpc_emit_vperm (p, dest, dest, p->tmpreg, perm); + } - tmpc = powerpc_get_constant (p, ORC_CONST_SPLAT_W, 0x0001); - - ORC_ASM_CODE(p," vspltish %s, 8\n", powerpc_get_regname(tmp2)); - powerpc_emit_VX(p, 0x1000034c, powerpc_regnum(tmp2), 8, 0); - - powerpc_emit_VX_2 (p, "vadduhm", 0x10000040, dest, src1, tmpc); - - powerpc_emit_VX_2 (p, "vsrh", 0x10000244, tmp, src1, tmp2); - powerpc_emit_VX_2 (p, "vadduhm", 0x10000040, dest, dest, tmp); - - powerpc_emit_VX_2 (p, "vsrh", 0x10000244, dest, dest, tmp2); + powerpc_emit_VX_2 (p, "vsrh", 0x10000244, dest, dest, tmp); } static void diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcutils-private.h new/orc-0.4.40/orc/orcutils-private.h --- old/orc-0.4.39/orc/orcutils-private.h 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcutils-private.h 2024-09-12 21:04:54.000000000 +0200 @@ -38,6 +38,9 @@ char ** strsplit (const char *s, char delimiter); char * get_tag_value (char *s, const char *tag); +void * orc_malloc(size_t size); +void * orc_realloc(void * ptr, size_t size); + orc_int64 _strtoll (const char *nptr, char **endptr, int base); #define ORC_VECTOR_ITEM_CHUNK 32 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcutils.c new/orc-0.4.40/orc/orcutils.c --- old/orc-0.4.39/orc/orcutils.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcutils.c 2024-09-12 21:04:54.000000000 +0200 @@ -35,6 +35,7 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#include <errno.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> @@ -46,6 +47,21 @@ * @short_description: Orc utility functions */ +void * +orc_malloc(size_t size) +{ + void *ret; + + ret = malloc(size); + + if (ret == NULL) { + ORC_ERROR ("orc_malloc(%zu): %s", size, strerror(errno)); + ORC_ASSERT (0); + } + + return ret; +} + #if defined(__arm__) || defined(__aarch64__) || defined(__mips__) char * get_proc_cpuinfo (void) @@ -81,13 +97,27 @@ _strndup (const char *s, int n) { char *r; - r = malloc (n+1); + r = orc_malloc (n+1); memcpy(r,s,n); r[n]=0; return r; } +void * +orc_realloc(void *ptr, size_t size) +{ + void *ret; + + ret = realloc(ptr, size); + if (ret == NULL) { + ORC_ERROR ("orc_realloc(%p, %zu): %s", ptr, size, strerror(errno)); + ORC_ASSERT (0); + } + + return ret; +} + char ** strsplit (const char *s, char delimiter) { @@ -97,14 +127,14 @@ while (*s == ' ') s++; - list = malloc (1 * sizeof(char *)); + list = orc_malloc (1 * sizeof(char *)); while (*s) { tok = s; while (*s && *s != delimiter) s++; list[n] = _strndup (tok, s - tok); while (*s && *s == delimiter) s++; - list = realloc (list, (n + 2) * sizeof(char *)); + list = orc_realloc (list, (n + 2) * sizeof(char *)); n++; } @@ -225,7 +255,7 @@ orc_vector_extend (OrcVector *vector) { vector->n_items_alloc += ORC_VECTOR_ITEM_CHUNK; - vector->items = realloc (vector->items, sizeof(void *) * vector->n_items_alloc); + vector->items = orc_realloc (vector->items, sizeof(void *) * vector->n_items_alloc); } void diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcutils.h new/orc-0.4.40/orc/orcutils.h --- old/orc-0.4.39/orc/orcutils.h 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcutils.h 2024-09-12 21:04:54.000000000 +0200 @@ -254,6 +254,10 @@ #endif #endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + ORC_BEGIN_DECLS #ifdef ORC_ENABLE_UNSTABLE_API diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcx86-private.h new/orc-0.4.40/orc/orcx86-private.h --- old/orc-0.4.39/orc/orcx86-private.h 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcx86-private.h 2024-09-12 21:04:54.000000000 +0200 @@ -2,9 +2,6 @@ #include <orc/orcutils.h> -typedef struct _OrcX86Target OrcX86Target; -typedef struct _OrcTarget OrcTarget; - ORC_BEGIN_DECLS ORC_INTERNAL void orc_x86_register_extension(OrcTarget *t, OrcX86Target *x86t); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/orc/orcx86insn.c new/orc-0.4.40/orc/orcx86insn.c --- old/orc-0.4.39/orc/orcx86insn.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/orc/orcx86insn.c 2024-09-12 21:04:54.000000000 +0200 @@ -8,6 +8,7 @@ #include <string.h> #include <orc/orc.h> +#include <orc/orcutils-private.h> #include <orc/orcx86.h> #include <orc/orcavx.h> #include <orc/orcsse.h> @@ -1084,7 +1085,7 @@ OrcX86Insn *xinsn; if (p->n_output_insns >= p->n_output_insns_alloc) { p->n_output_insns_alloc += 10; - p->output_insns = realloc (p->output_insns, + p->output_insns = orc_realloc (p->output_insns, sizeof(OrcX86Insn) * p->n_output_insns_alloc); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/tools/orc-bugreport.c new/orc-0.4.40/tools/orc-bugreport.c --- old/orc-0.4.39/tools/orc-bugreport.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/tools/orc-bugreport.c 2024-09-12 21:04:54.000000000 +0200 @@ -6,6 +6,7 @@ #include <orc/orc.h> #include <orc-test/orctest.h> #include <orc/orcparse.h> +#include <orc/orcutils-private.h> #include <stdio.h> #include <stdlib.h> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orc-0.4.39/tools/orcc.c new/orc-0.4.40/tools/orcc.c --- old/orc-0.4.39/tools/orcc.c 2024-07-19 13:02:41.000000000 +0200 +++ new/orc-0.4.40/tools/orcc.c 2024-09-12 21:04:54.000000000 +0200 @@ -6,6 +6,7 @@ #include <orc/orc.h> #include <orc/orcparse.h> #include <orc/orcbytecode.h> +#include <orc/orcutils-private.h> #include <stdio.h> #include <stdlib.h>