From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB482C433EF for ; Fri, 29 Apr 2022 07:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iunJOh84Is+wntd8tMLtA2v68K8G21n2hsnySjFFh6E=; b=idO+7X5Z6om0zCWfyoWascEyMM 07/nZ0DFbHueP4rOvaB/qyB1xKZ7aGk+JDzWD4tYDj95gWyTgiye/BfACqHfkvDUgC6rT3yZDvEG9 RtdtUnybXcTR6c9RBf0NBPGu/625yAgZZgHobVKvI1638JOcXMVe+hi2kxA9DxlntrVyoZa62sRSC jVKcXXlNQ0Lxvwx2AZ8jyg/NyFqP5PEkFoTw3DlcusAhlJDYX7V/NSL/VpfOhVoL+HcqaMSXoqBGw YVnB2EgNZFmgZRlYCaw576Rb1q+TZdLNG2nJBck8lYTv4s8W+mci4F3PCqzuHOiM3wN55bsfEoEZ5 YDs0tVuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkLRq-00A1xS-Ft; Fri, 29 Apr 2022 07:53:54 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkLRn-00A1wF-EO for linux-arm-kernel@lists.infradead.org; Fri, 29 Apr 2022 07:53:52 +0000 Received: by mail-pj1-x1029.google.com with SMTP id iq2-20020a17090afb4200b001d93cf33ae9so9834066pjb.5 for ; Fri, 29 Apr 2022 00:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=boCUD4eqK+wVfLrpWleuh2ZQ1/jep/RypYnq45tS3eA=; b=hY6H/CJgSJfOx+5JATqRxSx98LLZwIDFNr9opzqkpErXOyjJZSuSTzt7f+t+gs9U06 etkXC4Ugni6YAKnAS8fQVXOegV3T1hwzFfnD9Go+/yKqINhT1SJttq4WAlRZYBLTjYCW cwfhPlXBT9VQb/qmNlI5ZRs+87BvsdoSSWBSoyllqq2GoBo01AIdjRoHfighuHIw+CxI In0NRzt0Sx3IZA/olpssN8ZxB+m+2lyvGzaf7+AfF88wHWnZZf6LXMlfhtypTr4nCAAG wEL6yGsGaEJqRDCd073komPhVeN4AoP3wrWpEV+s04z/za2mHXzFf8autG/X6pzvVsgD vO/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=boCUD4eqK+wVfLrpWleuh2ZQ1/jep/RypYnq45tS3eA=; b=G7WM2jg13rx3/j694cgEonCefWbx4lFq6IB/oBEXOeWRxx3Cz5yMO67vIvbr4mfFKv ViCf5AFKbwF36v9p+/LwUb0LbHA6utLj91lsjxccC6T1vpgQjlhEhDjnEOkDfapsIWY6 XU8jJb5JIxnJ/HezftvwBhpL9lLKZeRDbwSQzN99DReGOcx7Z1325Eo7QJ30LTBhLMlL DXILg1Lx32wol/rUhipwdGY+fvjRnGnUm+VRKFj2LzMhIei1HSQi4WZJYQAQ0vp3fONg xi8aYO9wbtnIPTqTtd8j0Y051IW6DF6rFg+VYb3qSpUA2CCBXpcxF0j7wOThZSeNh+qu /5Iw== X-Gm-Message-State: AOAM531ZX3e+1quLDjaJzhQcCiN6NbL25GmKcH4ah1mgwK6ewCg+ECts /G0SAmBXTV5DYLbnVA6ZszgUV9iOJPINPOfW X-Google-Smtp-Source: ABdhPJxZN8bjtDcSueedi51SPGow8XGuubh/U0XDoB2CNCmOSSdIebfgH9Egaz/GU/Hm5kmszGXVlA== X-Received: by 2002:a17:90b:3e83:b0:1d2:edd3:5639 with SMTP id rj3-20020a17090b3e8300b001d2edd35639mr2497945pjb.183.1651218828855; Fri, 29 Apr 2022 00:53:48 -0700 (PDT) Received: from google.com ([2620:15c:2ce:200:fb4f:b611:3fdd:bd70]) by smtp.gmail.com with ESMTPSA id b22-20020a63cf56000000b003c1a1f44736sm2077614pgj.90.2022.04.29.00.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 00:53:48 -0700 (PDT) Date: Fri, 29 Apr 2022 00:53:44 -0700 From: Fangrui Song To: Ard Biesheuvel Cc: Nick Desaulniers , Linux ARM , clang-built-linux , Will Deacon , Catalin Marinas , Kees Cook , Mark Rutland , Nathan Chancellor , Sami Tolvanen Subject: Re: [RFC PATCH 2/2] arm64: kernel: switch to PIE code generation for relocatable kernels Message-ID: <20220429075344.mhvytqhqmplh2stf@google.com> References: <20220427171241.2426592-1-ardb@kernel.org> <20220427171241.2426592-3-ardb@kernel.org> <20220428024030.gwxb746c5gwvcnw6@google.com> <20220428065742.rl3w5rz2ni2fhngl@google.com> <20220429070318.iwj3j5lpfkw4t7g2@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_005351_525456_15EB182E X-CRM114-Status: GOOD ( 22.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2022-04-29, Ard Biesheuvel wrote: >On Fri, 29 Apr 2022 at 09:03, Fangrui Song wrote: >> >> On 2022-04-28, Ard Biesheuvel wrote: >> >On Thu, 28 Apr 2022 at 20:53, Nick Desaulniers wrote: >> >> >> >> On Wed, Apr 27, 2022 at 11:57 PM Fangrui Song wrote: >> >> > >> >> > On 2022-04-28, Ard Biesheuvel wrote: >> >> > >On Thu, 28 Apr 2022 at 04:40, Fangrui Song wrote: >> >> > >> >> >> > >> On 2022-04-27, Ard Biesheuvel wrote: >> >> > >> >Fortunately, we can convince the compiler to handle this in a way that >> >> > >> >is a bit more suitable for freestanding binaries such as the kernel, by >> >> > >> >setting the 'hidden' visibility #pragma, which informs the compiler that >> >> > >> >symbol preemption or CoW footprint are of no concern to us, and so >> >> > >> >PC-relative references that are resolved at link time are perfectly >> >> > >> >fine. >> >> > >> >> >> > >> Agree >> >> > >> >> >> > > >> >> > >The only unfortunate thing is that -fvisibility=hidden does not give >> >> > >us the behavior we want, and we are forced to use the #pragma instead. >> >> > >> >> > Right. For a very long time there had been no option controlling the >> >> > access mode for undefined symbols (-fvisibility= is for defined >> >> > symbols). >> >> > >> >> > I added -fdirect-access-external-data to Clang which supports >> >> > many architectures (x86, aarch64, arm, riscv, ...). >> >> > GCC's x86 port added -mdirect-extern-access in 2022-02 (not available on aarch64). >> >> > >> >> > The use of `#pragma GCC visibility push(hidden)` looks good as a >> >> > portable solution. >> >> >> >> Portable, sure, which is fine for now. >> >> >> >> But there's just something about injecting a header into ever TU via >> >> -include in order to set a pragma and that there's such pragmas >> >> effecting codegen that makes my skin crawl. >> >> >> >> Perhaps we can come up with a formal feature request for toolchain >> >> vendors for an actual command line flag? >> >> >> >> Does the pragma have the same effect as >> >> `-fdirect-access-external-data`/`-mdirect-extern-access`, or wvisould >> >> this feature request look like yet another distinct flag? >> >> `#pragma GCC visibility push(hidden)` is very similar to >> -fvisibility=hidden -fdirect-access-external-data with Clang. >> In Clang there are only two differences: >> >> // TLS initial-exec model with -fdirect-access-external-data; >> // TLS local-exec model with `#pragma GCC visibility push(hidden)` >> extern __thread int var; >> int foo() { return var; } >> >> // hidden visibility suppresses -fno-plt. >> // -fdirect-access-external-data / GCC -mdirect-extern-access doesn't suppress -fno-plt. >> extern int bar(); >> int foo() { return bar() + 2; } >> >> >> The kernel uses neither TLS nor -fno-plt, so -fvisibility=hidden >> -fdirect-access-external-data can replace `#pragma GCC visibility >> push(hidden)`. >> > >OK. But you mentioned that GCC does not implement >-mdirect-extern-access for AArch64, right? So for now, the pragma is >the only portable option we have. Right. >> >I agree that this is rather nasty. What I don't understand is why >> >-fvisibility=hidden gives different behavior to begin with, or why >> >-ffreestanding -fpie builds don't default to hidden visibility for >> >symbol declarations as well as definitions. >> >> -ffreestanding doesn't mean there is no DSO. A libc implementation (e.g. >> musl) may use -ffreestanding to avoid libc dependencies from the host >> environment. It may ship several shared objects and export multiple symbols. >> Implied -fvisibility=hidden will get in the way. >> >> There is a merit to make options orthogonal. > >Fair enough. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel