From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 704BF312816 for ; Thu, 22 Jan 2026 17:21:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769102516; cv=none; b=F/7VAtiMSWsWBQLnGpFbiEMvflLuEObkP14z8yUx7jGyQu+uFQgUkftHKI01i6xQmzoaEsTXc4J8dhM9xp/rBK44YORNEYzuQNx2ZIu5ziLXVwSOKHRcuh6ZBiW36977LZg0rvl1O8OeNNV2SwUxfYLY16PF7GNlLQqaZnng05Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769102516; c=relaxed/simple; bh=MsLyfRmAfe4C3jNniNY2lFNJQoio2YovxKjleJiyn/Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IB7FD7JKDbL5o3NgU9BzmhJZjV6MHw/hKB5zavD8jo2CrKz3LttDxSYhuGy5QZkUJiMKrbeawdxFHIsukOoFLh+A7h2JDachP6W4e7rMj4bI6rbDjpUudtuDiIfjOM7Xl6cyTaCrSrMDzZYdC9LsI4sgI+917hhzNgN73NOQkME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d7y26Uz1; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d7y26Uz1" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-352de7a89e1so1174294a91.1 for ; Thu, 22 Jan 2026 09:21:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769102505; x=1769707305; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6uCae6YjFO2GUpcWjOMRLM2rB/k4Vf9uxQYdqxpZxK8=; b=d7y26Uz11v1OZvixhnXIRkusxTSZ2HOccmKfuXlwS+6qpKiPWybhbaORq0arU6IQjF zuOEd2/olEj0HbTQjeol0qpjRFZtMGmj3LimX4p+XqDaGXy7Np/XtAhEkMrED3vkbA5Y Cvsfo+gIRZEY+QszLtocfUnJcAyFYbJax811iP2eE43xm9f6+hcZpcAictYGfbqcVVcb 6DdBHnAmnQHe47brIQ0ktKv8mSU38HvhWtZby+qXmyGr3XDZMFInxiU24hdmkwqFYlXX GA1vQ6uA7pbZh3KgVBk6kl7exIkXgmVSEFS5AJvYAsxdUUMbokYYBCon1LgvC4ypjPQ9 P49g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769102505; x=1769707305; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6uCae6YjFO2GUpcWjOMRLM2rB/k4Vf9uxQYdqxpZxK8=; b=OWVr4R4uZiqNRbAXCJwC6zVc7CgkllfrqRTpjSt+Sf+3xtR7kYAA5JM7wWl/KDHCHX zArDJrN6ZxrZWef50fjFpXEz6/qWbqvDRdc4fv48wh8nHb2RqpcHrm0ceWQ5T2beXExg hxVKRmRfB0/UAfvvD8H6FXXLFqHbwF34ltjAo2JdAUY/aDd7zF/r/EJpGiaP5vFLjXw/ SSmaQRE1akLHB6OcdsXWJRRqz45NJ0m9aOrB/bBH604JnwKHCDpgvxVvojS2SDcNjsNY KXUFShi0vqBC8ZI2c/e0da8ffZbNHTTt6/GIUAp93H0WCZd/ZIOx1yuHz0RX14J/ufzp uZxg== X-Forwarded-Encrypted: i=1; AJvYcCXrRLnOk1UAJ3p9q8isBfvD5mDdLHBLI00TyhJG2l6SpJcK4WZctdj1CRBMh3gnOx49hXUb4LJW3Vn96s8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8qsuzmiNjZ7vqPtIy/im6H7ynvEoiNGEIg/hL2V+YH+fCBlN8 0W7XfFnkLTMxU1m9JXf9olE+lq0X3b00COvXBTjSZex6zOBDyjahKlLTgP3ThWYRJrcm7E4aWM4 kkxxMHw== X-Received: from pjbiz21.prod.google.com ([2002:a17:90a:e795:b0:34b:fe89:512c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4d0b:b0:34c:3501:d118 with SMTP id 98e67ed59e1d1-35367010b69mr222205a91.1.1769102505221; Thu, 22 Jan 2026 09:21:45 -0800 (PST) Date: Thu, 22 Jan 2026 09:21:43 -0800 In-Reply-To: <20260122053551.548229-1-zhiquan_li@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122053551.548229-1-zhiquan_li@163.com> Message-ID: Subject: Re: [PATCH] KVM: selftests: Add -U_FORTIFY_SOURCE to avoid some unpredictable test failures From: Sean Christopherson To: Zhiquan Li Cc: pbonzini@redhat.com, shuah@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Thu, Jan 22, 2026, Zhiquan Li wrote: > Some distributions (such as Ubuntu) configure GCC so that > _FORTIFY_SOURCE is automatically enabled at -O1 or above. This results > in some fortified version of definitions of standard library functions > are included. While linker resolves the symbols, the fortified versions > might override the definitions in lib/string_override.c and reference to > those PLT entries in GLIBC. This is not a problem for the code in host, > but it is a disaster for the guest code. E.g., if build and run > x86/nested_emulation_test on Ubuntu 24.04 will encounter a L1 #PF due to > memset() reference to __memset_chk@plt. Ugh. I'm pretty sure I saw this recently as well (I forget what OS), and I was completely clueless as to why it was failing. Thanks a ton for tracking this down! > The option -fno-builtin-memset is not helpful here, because those > fortified versions are not built-in but some definitions which are > included by header, they are for different intentions. > > In order to eliminate the unpredictable behaviors may vary depending on > the linker and platform, add the "-U_FORTIFY_SOURCE" into CFLAGS to > prevent from introducing the fortified definitions. > > Signed-off-by: Zhiquan Li > --- > tools/testing/selftests/kvm/Makefile.kvm | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm > index ba5c2b643efa..d45bf4ccb3bf 100644 > --- a/tools/testing/selftests/kvm/Makefile.kvm > +++ b/tools/testing/selftests/kvm/Makefile.kvm > @@ -251,6 +251,7 @@ LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include > LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include > CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ > -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ > + -U_FORTIFY_SOURCE \ Is this needed for _all_ code, or would it suffice to only disable fortification when building LIBKVM_STRING_OBJ? From the changelog description, it sounds like we need to disable fortification in the callers to prevent a redirect, but just in case I'm reading that wrong... > -fno-builtin-memcmp -fno-builtin-memcpy \ > -fno-builtin-memset -fno-builtin-strnlen \ > -fno-stack-protector -fno-PIE -fno-strict-aliasing \ > -- > 2.43.0 >