Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp494416pxa; Wed, 19 Aug 2020 07:11:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPGwkDfPgvaWq+VTgXhAN8GD3kE+8oQxEdwPGayI7tgwxs4RPT20RSQRdHbVGzB/3Qn6Gy X-Received: by 2002:a17:906:7d6:: with SMTP id m22mr24348875ejc.229.1597846306214; Wed, 19 Aug 2020 07:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597846306; cv=none; d=google.com; s=arc-20160816; b=xsvIll0r4KYBNILvmtp4s2cMoJdc2Q0FkwjkcG/X614lE4+9WSzHW6TcO48gkl6L+7 zjPn+KxWfU6N+VG6s+h852GUti1gfMfadrmVVfLgtUJvBTK/Hj+gh0J9y3mY1vDGAr19 g7Xt81lP0LV7cS6BWTFT4MvRLP7JpnACl6Z8HExkWdGzloquF9l2cGH4RBjJ8xTKOfPa v5rNu6ZFUzOGI58J0CUvLPA4J+1dMhRftyb7iE5B1DECyX5y01VqWl69NMt9vHvijsnH yGdLRtl5Hfuv+RSATZaVQvnuAhYwF76KhFANYW2Sb4wM95jaCEWF48uhrW3TjjP2SLtf 9w0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RV6pBQZ9MRlDByHN1h5rkzmXbG7Gch7l2dQUZjdYLUM=; b=kJQ9vyBCYjnf8q0BGug++aZKQDBML2d3IxhqGTjdLXxlCcIrFDdWH0LYCjGcn23Va4 Lvi3sVmj5DwS1k8gQRHGmrLtCKyN7RAe7i4/BRMAzOOFMW7hpEVgWs0H07ddsaTykAU4 OIQZsKJv//4v7xAhJVFf5t9KXZPMUtew6US6Yw6Tv39H8xcY7ZcIlvsYQBdAzOF1QkC6 lluArod6lXQXQ9vhi/sopCsZJSkuqnVryFDCLNz3Ca70tW2k6+xJ0dzXW/oSYIzlpn2X Xny4NJGweyQMPg2h8q3YhFDVH/l/fm3NPE+6rEP/2sDVZnxTz09UJGP9Z1j4Ih91FCNz klVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si15340042edx.491.2020.08.19.07.11.21; Wed, 19 Aug 2020 07:11:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbgHSOI2 (ORCPT + 99 others); Wed, 19 Aug 2020 10:08:28 -0400 Received: from mail-qv1-f66.google.com ([209.85.219.66]:43153 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727854AbgHSOIU (ORCPT ); Wed, 19 Aug 2020 10:08:20 -0400 Received: by mail-qv1-f66.google.com with SMTP id l13so11265696qvt.10 for ; Wed, 19 Aug 2020 07:08:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RV6pBQZ9MRlDByHN1h5rkzmXbG7Gch7l2dQUZjdYLUM=; b=Ov5HisfNHCKHGzrQbjy3GkCQdMRAXFSCnIhK643itZsU6MV6I5S/YvTQmaJeP+fSxR ZqraXO6DLID8+dDGqNjApVaGEP+DJ0PN4FlVc9dn4JwkZhAiBpumc+hyUFeYDTAwwCp8 IHaQeE+UIDcySa1yt3z+GE2ykOveCDBCa4XXxvY1fyIwTOrjheUPh5nJaCh2K0un34bt 3xR4LQ4UtbjjVzeFc/Hsd9MbgoaA51FW5Vdd93d8N+7E5zcZUNEkpx4tLtKEYOMCyEfZ paI5JprgTPUJ+ixcsgpMPcyvV8MbqoUHlKkaZn6DydB+sni5KebH/Gj1v/O39IJAaA98 cEoA== X-Gm-Message-State: AOAM5324NI5MajSg8367Yy5NHZaQCasY7Droj7R0mZBkkoUgY3h6n0iV 2iwlaOxt2vpFddF32cIqqRs= X-Received: by 2002:ad4:4984:: with SMTP id t4mr24046002qvx.110.1597846098109; Wed, 19 Aug 2020 07:08:18 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id v2sm26975641qte.25.2020.08.19.07.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 07:08:16 -0700 (PDT) From: Arvind Sankar To: Andrew Morton , Linus Torvalds Cc: Nick Desaulniers , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH v2] lib/string.c: Use freestanding environment Date: Wed, 19 Aug 2020 10:08:16 -0400 Message-Id: <20200819140816.3807604-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gcc can transform the loop in a naive implementation of memset/memcpy etc into a call to the function itself. This optimization is enabled by -ftree-loop-distribute-patterns. This has been the case for a while (see eg [0]), but gcc-10.x enables this option at -O2 rather than -O3 as in previous versions. Add -ffreestanding, which implicitly disables this optimization with gcc. It is unclear whether clang performs such optimizations, but hopefully it will also not do so in a freestanding environment. [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 Signed-off-by: Arvind Sankar --- lib/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Makefile b/lib/Makefile index e290fc5707ea..a4a4c6864f51 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -15,11 +15,16 @@ KCOV_INSTRUMENT_debugobjects.o := n KCOV_INSTRUMENT_dynamic_debug.o := n KCOV_INSTRUMENT_fault-inject.o := n +# string.o implements standard library functions like memset/memcpy etc. +# Use -ffreestanding to ensure that the compiler does not try to "optimize" +# them into calls to themselves. +CFLAGS_string.o := -ffreestanding + # Early boot use of cmdline, don't instrument it ifdef CONFIG_AMD_MEM_ENCRYPT KASAN_SANITIZE_string.o := n -CFLAGS_string.o := -fno-stack-protector +CFLAGS_string.o += -fno-stack-protector endif # Used by KCSAN while enabled, avoid recursion. -- 2.26.2