Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp26134pxv; Fri, 30 Jul 2021 17:34:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7upJOWrBl5cue4OvcOc5MXn56a7G4vYJqm3aZ4ikdN8dDPC2JdhOpQBO2W6JT1Ksqn5H2 X-Received: by 2002:a17:906:1f8b:: with SMTP id t11mr5388882ejr.131.1627691661896; Fri, 30 Jul 2021 17:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627691661; cv=none; d=google.com; s=arc-20160816; b=y+2WlNdxsEp1Z8Bj6mGVUD06Vblz4Tky8rqPHbhTBW9apdUQt6v7OPcHYDqzKXolM3 RvQ8lSKVh+0GEKtzy0s9MEtHpVMbi+1UoxuZAvrbGRqM+sEiCUnUn9HFwRUVHgsVzfAD TM7/99dseQSnqd1gD7HNcyH/wLEnwUTEiWxajvUFzfqgaCJCZvlAEXFQEGcwENgxhzuY vciC8EG/05v4SweIp7VeZTsGynngfG5MIKVuSJZ6yy8qIiFXy2VM1+7BcOOzcnt3TMTu IwNJ7xVT+p2jUlKeq00B6WoBHLX4T0N+K0WPOzTdB2owXsANAk/WIp8VVbgIlDlhrhP+ vQdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=BfrLQHN2E9bM7oTxBZbgAR5WOEvY8Bj1JCo88Xnr2Pw=; b=MrfzA/jNznIhsj06ZssoFrDHdvedecptCK8zi+DXSzUb2gZGQAzi+rkObMImeDsrlq WwAxbZpL6ZLH1RSv4ZLg3TlEBUE6reksTdmDriU2kWuH1jAUv7rV5JOuUjktM1LBIvBs K6YbSUWmZQMOnbc6gZGrpwe31aVYpGeOzK/Hk3Y5hs/j5QkJwIf2qUqUzZAW+4wBGf9M /Z5gthTrSuKuW4J80Qdk2UWptrMWrE9S1jXrFHfW/GnsbNFV+uXnQyAAfiaYTSGXMJ7+ PGbnGuBCCE/lMaKVY6xZLAebyECBdBYImO0tLd6IgLQBhg1OVRgfUjM7Ui+WAdwxm8+Z dgWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fob9LrC7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd3si3415674ejb.632.2021.07.30.17.33.58; Fri, 30 Jul 2021 17:34:21 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fob9LrC7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234385AbhGaAcl (ORCPT + 99 others); Fri, 30 Jul 2021 20:32:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:48794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234448AbhGaAck (ORCPT ); Fri, 30 Jul 2021 20:32:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E0A260FE7; Sat, 31 Jul 2021 00:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627691555; bh=o+PLNhrJjYzJClkCiD1x2ngH38naHAhxH0uspRMZAk0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Fob9LrC7lLW8/Nupz+JnUcvUWuJy7rdK6mqt5l6vB9mpv9tbhBMqv5bfxWvURlr30 5lIc/NL9RSkw9Yq4Bw6ak54rXQL1e1dj7ZFX1ltvJZSNqYl8S7GCfOub7XDUQzEspn cgsvmB0nKl1fUej7/1Ycak74kHxKaGDHrlRlEIxrpr0BLvvK3B2tIiaVkdiqDfRqSC AHyBHuqGs3vBL5G07jo9fgiKBmpFxO3DoolQonsPYsczpYTlS3fakoJnJjzct+qs5S WQxiXn+VNJbA9JTOiFyLZd7CSR6jddfaTUukpSu3cXq0Kkp75O+App2GDM3hZ+KY5E CUJ9C95gyztiw== Subject: Re: [PATCH] vmlinux.lds.h: Handle clang's module.{c,d}tor sections To: Fangrui Song Cc: Nick Desaulniers , Kees Cook , Arnd Bergmann , Marco Elver , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, clang-built-linux@googlegroups.com, stable@vger.kernel.org References: <20210730223815.1382706-1-nathan@kernel.org> <20210730225936.ce3hcjdg2sptvbh7@google.com> From: Nathan Chancellor Message-ID: Date: Fri, 30 Jul 2021 17:32:33 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210730225936.ce3hcjdg2sptvbh7@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/30/2021 3:59 PM, Fangrui Song wrote: > On 2021-07-30, Nick Desaulniers wrote: >> On Fri, Jul 30, 2021 at 3:38 PM Nathan Chancellor >> wrote: >>> >>> A recent change in LLVM causes module_{c,d}tor sections to appear when >>> CONFIG_K{A,C}SAN are enabled, which results in orphan section warnings >>> because these are not handled anywhere: >>> >>> ld.lld: warning: >>> arch/x86/pci/built-in.a(legacy.o):(.text.asan.module_ctor) is being >>> placed in '.text.asan.module_ctor' >>> ld.lld: warning: >>> arch/x86/pci/built-in.a(legacy.o):(.text.asan.module_dtor) is being >>> placed in '.text.asan.module_dtor' >>> ld.lld: warning: >>> arch/x86/pci/built-in.a(legacy.o):(.text.tsan.module_ctor) is being >>> placed in '.text.tsan.module_ctor' >> >> ^ .text.tsan.* > > I was wondering why the orphan section warning only arose recently. > Now I see: the function asan.module_ctor has the SHF_GNU_RETAIN flag, so > it is in a separate section even with -fno-function-sections (default). Thanks for the explanation, I will add this to the commit message. > It seems that with -ffunction-sections the issue should have been caught > much earlier. > >>> >>> Place them in the TEXT_TEXT section so that these technologies continue >>> to work with the newer compiler versions. All of the KASAN and KCSAN >>> KUnit tests continue to pass after this change. >>> >>> Cc: stable@vger.kernel.org >>> Link: https://github.com/ClangBuiltLinux/linux/issues/1432 >>> Link: >>> https://github.com/llvm/llvm-project/commit/7b789562244ee941b7bf2cefeb3fc08a59a01865 >>> >>> Signed-off-by: Nathan Chancellor >>> --- >>>  include/asm-generic/vmlinux.lds.h | 1 + >>>  1 file changed, 1 insertion(+) >>> >>> diff --git a/include/asm-generic/vmlinux.lds.h >>> b/include/asm-generic/vmlinux.lds.h >>> index 17325416e2de..3b79b1e76556 100644 >>> --- a/include/asm-generic/vmlinux.lds.h >>> +++ b/include/asm-generic/vmlinux.lds.h >>> @@ -586,6 +586,7 @@ >>> >>> NOINSTR_TEXT                                            \ >>> >>> *(.text..refcount)                                      \ >>> >>> *(.ref.text)                                            \ >>> +               *(.text.asan >>> .text.asan.*)                              \ >> >> Will this match .text.tsan.module_ctor? No, I forgot to test CONFIG_KCSAN with this version, rather than the prior one I had on GitHub so I will send v2 shortly. > asan.module_ctor is the only function AddressSanitizer synthesizes in > the instrumented translation unit. > There is no function called "asan". > > (Even if a function "asan" exists due to -ffunction-sections > -funique-section-names, TEXT_MAIN will match .text.asan, so the > .text.asan pattern will match nothing.) Sounds good, I will update it to remove the .text.asan and replace it with .text.tsan.* >> Do we want to add these conditionally on >> CONFIG_KASAN_GENERIC/CONFIG_KCSAN like we do for SANITIZER_DISCARDS? I do not think there is a point in doing so but I can if others feel strongly. Thank you both for the comments for the comments! Cheers, Nathan