From patchwork Tue Sep 12 13:50:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 138199 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp428602vqx; Tue, 12 Sep 2023 07:03:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBhi81QTTcLAXFeb+qdA4zRwdK5WBeYbpEvhWkE3hdWPs1iBfKNPZooh9PJnZg0sqtxQUY X-Received: by 2002:a05:6870:c69a:b0:1d5:5a83:22b7 with SMTP id cv26-20020a056870c69a00b001d55a8322b7mr16399851oab.51.1694527430983; Tue, 12 Sep 2023 07:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694527430; cv=none; d=google.com; s=arc-20160816; b=jodWvLYLx1kLdtqn/79RdxuNGjSp/SdavyeAgtfpzPtaxLH83EfF5EB5COVI1z3Jnh uubSTUCskra7rLSX9PLx7zacLxDf54dYYsx8J9UcoUTETRjqO9Hw0Ps2gdCIbKZRdu1/ juIFPUYVEoqOR3f/2x7fwtqXr6y0BJkTGx90FhgVQsohAke6cMBFSwN1ikkkPhimEKcD P3bhD4KS2u5Vc4G736BX8X4NT4hzhznOj6cIhlg4YYqT4vrMQNT3s1jeBocGWTB02Lb3 +K2v9Sx48vvcyZqh4IieDaEj9tjyA+V9VaeAeBCCUTV62PJYQLTnYh84Jc284B98lAtB hJPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ZdZyE7xmMz3yoOr0M/WWhbY5bqgBQLJn9PBVAU5cttc=; fh=515GHDHrT7Yck3rK+j8HVtQyQJzw1wrcOsUoL7+fYAM=; b=zi+McNZD7NIu4tcUtzht0HJcLoUv0EaP8xIBNvMOOyD6JjVjmwPIxVHMiTGwyTS4cZ l82UQrqKORaMKIEojSodiXQlnExOy9iIr+E+E8q0tCtnwOTTMkZ9dmGmI49Y+luzc/+5 6quuSj7OMYDSgXN8ow64pvVl0Jw/SSFtqcRLlWwZccmmasjLJKsI28lsRYdGURsb/R41 OPgW/qO7BzUZRwXteCYKtrrjWvKiwO/PjYJUXk3QKJRq4qd49Qv2v1QhBZ8jTqlXZLkV hDZHOCfrK8aHxnYRmd6hVODbz8UBHso9H8rNR1La1oicxg/nDj23Iodkj2DlFfgE16Or YEnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p21-20020a634f55000000b0057404ce2fc8si7730741pgl.529.2023.09.12.07.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 07:03:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4314684A3D95; Tue, 12 Sep 2023 06:52:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235709AbjILNvz (ORCPT + 37 others); Tue, 12 Sep 2023 09:51:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235673AbjILNvD (ORCPT ); Tue, 12 Sep 2023 09:51:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E4EFD10D7; Tue, 12 Sep 2023 06:50:58 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C146EC15; Tue, 12 Sep 2023 06:51:35 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 642633F5A1; Tue, 12 Sep 2023 06:50:56 -0700 (PDT) From: Ryan Roberts To: Shuah Khan , Tom Rix , kernel test robot , Andrew Morton , Mark Brown , David Hildenbrand , Florent Revest , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Peter Xu Cc: Ryan Roberts , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, oe-lkp@lists.linux.dev, lkp@intel.com Subject: [PATCH v1] selftests: Link libasan statically for tests with -fsanitize=address Date: Tue, 12 Sep 2023 14:50:48 +0100 Message-Id: <20230912135048.1755771-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 06:52:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776840795612700875 X-GMAIL-MSGID: 1776840795612700875 When dynamically linking, Address Sanitizer requires its library to be the first one to be loaded; this is apparently to ensure that every call to malloc is intercepted. If using LD_PRELOAD, those listed libraries will be loaded before the libraries listed in the program's ELF and will therefore violate this requirement, leading to the below failure and output from ASan. commit 58e2847ad2e6 ("selftests: line buffer test program's stdout") modified the kselftest runner to force line buffering by forcing the test programs to run through `stdbuf`. It turns out that stdbuf implements line buffering by injecting a library via LD_PRELOAD. Therefore selftests that use ASan started failing. Fix this by statically linking libasan in the affected test programs, using the `-static-libasan` option. Note this is already the default for Clang, but not got GCC. Test output sample for failing case: TAP version 13 1..3 # timeout set to 300 # selftests: openat2: openat2_test # ==4052==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD. not ok 1 selftests: openat2: openat2_test # exit=1 # timeout set to 300 # selftests: openat2: resolve_test # ==4070==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD. not ok 2 selftests: openat2: resolve_test # exit=1 Signed-off-by: Ryan Roberts Fixes: 58e2847ad2e6 ("selftests: line buffer test program's stdout") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202309121342.97e2f008-oliver.sang@intel.com --- tools/testing/selftests/fchmodat2/Makefile | 2 +- tools/testing/selftests/openat2/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/tools/testing/selftests/fchmodat2/Makefile b/tools/testing/selftests/fchmodat2/Makefile index 20839f8e43f2..71ec34bf1501 100644 --- a/tools/testing/selftests/fchmodat2/Makefile +++ b/tools/testing/selftests/fchmodat2/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later -CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined $(KHDR_INCLUDES) +CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined -static-libasan $(KHDR_INCLUDES) TEST_GEN_PROGS := fchmodat2_test include ../lib.mk diff --git a/tools/testing/selftests/openat2/Makefile b/tools/testing/selftests/openat2/Makefile index 843ba56d8e49..254d676a2689 100644 --- a/tools/testing/selftests/openat2/Makefile +++ b/tools/testing/selftests/openat2/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later -CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined +CFLAGS += -Wall -O2 -g -fsanitize=address -fsanitize=undefined -static-libasan TEST_GEN_PROGS := openat2_test resolve_test rename_attack_test include ../lib.mk