From 0703f64e64b41fda4b337faf57bd8c42d484c49f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 20 Oct 2025 11:30:54 +0200 Subject: [PATCH] lib/kru: fix collision when user plays with -march option Affects just clang, apparently. This is just a copy from knot-dns changes, doing a bit more than this resolver commit title says. See: https://gitlab.nic.cz/knot/knot-dns/-/commit/ec4a2567b213efdb8ecab6573cebbc74fbb507b2 https://gitlab.nic.cz/knot/knot-dns/-/commit/509d9d82b51c58ea572dccb09f4fdbe1a3c2571e --- lib/kru-avx2.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/kru-avx2.c b/lib/kru-avx2.c index a850c5c83..fd38b34fc 100644 --- a/lib/kru-avx2.c +++ b/lib/kru-avx2.c @@ -14,17 +14,17 @@ along with this program. If not, see . */ -// Checked with clang 5 (2017) and gcc 6 (2016). +// Checked with clang 12 (2021) and gcc 6 (2016). // For other cases we'll rather keep just the generic implementation. -#if defined(__x86_64__) && (__clang_major__ >= 5 || __GNUC__ >= 6) +#if defined(__x86_64__) && (__clang_major__ >= 12 || __GNUC__ >= 6) && !defined(__APPLE__) // This file has code for new-ish x86 (2015+ usually, Atom 2021+) - AES + AVX2 -#if __clang_major__ >= 12 - #pragma clang attribute push (__attribute__((target("arch=x86-64-v3,aes"))), \ - apply_to = function) -#elif __clang__ - #pragma clang attribute push (__attribute__((target("avx2,aes"))), \ - apply_to = function) +#ifdef __clang__ + // Force using specific instructions only if target architecture/optimization not specified + #if !defined(__AVX2__) + #pragma clang attribute push (__attribute__((target("arch=x86-64-v3,aes"))), \ + apply_to = function) + #endif #else #pragma GCC push_options #if __GNUC__ >= 11 @@ -46,7 +46,9 @@ KR_EXPORT const struct kru_api KRU_AVX2 = KRU_API_INITIALIZER; #ifdef __clang__ - #pragma clang attribute pop + #if !defined(__AVX2__) + #pragma clang attribute pop + #endif #else #pragma GCC pop_options #endif -- 2.47.3