Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp805410imn; Sat, 30 Jul 2022 03:56:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbZl9EX2czSjsEOGQX3Vzw1YX8QTE+bS+/BAbuG9T9H784v0SZf+nqM7QvK8N8dIQaKq5l X-Received: by 2002:a05:6a00:114c:b0:528:2c7a:6302 with SMTP id b12-20020a056a00114c00b005282c7a6302mr7440121pfm.37.1659178594433; Sat, 30 Jul 2022 03:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659178594; cv=none; d=google.com; s=arc-20160816; b=LJKsl3FWK3X/H5iHtNuNd6Mwqua+mVZ2aETyUbu3fd14nmoGvDv0e9ZnjCr7/LTtQF cm+BuCQQ9au2hE1fBd4glgzw9hNmNwC2tKJ4D1v8ycW20Lj+d6TAaxdF7+nCtFXTbkPW jQI3pmMThpVDixA5YQ1y1qdDkgqFopkzrOMekZUnQ2ZFjbYb/Mzh3U3NhvnMbxxqsEBt NsofG87cTKkjpQgMrrFb8fqSZOJBqnitiGW6x8zJjR2JBgPbmYMluVGc+Rvv2Ce3YjQU /BdynnP9AT0iM5Vj4nmaJbG8cJQSJAvEs5CKE1oEMSvkKUFeqi+Cz378oSh1gvOJJOQa qzMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=S0gKLYqzzAAh1CTI+Pepxg4xmoPLFMy2NgeWfn6HfAk=; b=p7Gyhqpxt6eqq6pTqCRDKIG5Aphy/TGl+GhSm2pabKk73ivbyVMypVY1FWuRJlNSqk sr6E3sgXrOk2x5jnPcdFFTBKqHZW2AZop2Awys59YyyGAEpgux4mh026d06soEsl8r+v KXUOfb49uA7fTy/QVKJ4AE5tvkw/AMhcMYitvrnkHZso5KrJa4qb8VwFeBnSkME79aRO WR2K9lj5Z6F60w/SjPPfXHWALBNmyIqWlCww1y1R3A/6uZ47mgoTz4q6hvuj2GeQ3+C3 ToGih1TnzfnV99FQYoeKkmDwOx382QoEqjL1d9VRtvnpYln+jruOW3X8SxSWCZUVr+tF qusQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QF+6eONP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a4-20020a637044000000b0040512c0ebfcsi7410944pgn.297.2022.07.30.03.56.04; Sat, 30 Jul 2022 03:56:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QF+6eONP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233428AbiG3KjM (ORCPT + 99 others); Sat, 30 Jul 2022 06:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiG3KjK (ORCPT ); Sat, 30 Jul 2022 06:39:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF20A2CDEF for ; Sat, 30 Jul 2022 03:39:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 825BB60C40 for ; Sat, 30 Jul 2022 10:39:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2DBCC433B5 for ; Sat, 30 Jul 2022 10:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659177548; bh=ccWN+UJr8e9XwHdVFz0LM15EpLwV+jaB+5qiit7JIVY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QF+6eONP/pe/8pH/OTVVlCLH6AFY6nKQwfu9MRB7JaGDVpS6+V7PUdInaBhosdxXP GJRI+e4laH6ZdCS0YZwPnKcGMT1/l19HytWf6q21GczIFfWYSyAZExGhU/F4CIQmiI 3ls2vWzGhYIIE7CXHOoLnv+Ka58QPB7ozCl+dWMSuFDwWfgJ4KiPq8fsTWgmYk4B0z ONirkePV/JHrcJKvl5cQ3n6Y6jVZVKPS48jwiNo+LlsoExoEwEsLKkrcopmyF6UBhV RXMCaO2+094qAy3TbWq1C+xX6ap81tntamHgC86FaCX/g7XW2zXFlkj+rocIRqaSII 1hmEE84DVog5g== Received: by mail-vs1-f41.google.com with SMTP id 66so6831028vse.4 for ; Sat, 30 Jul 2022 03:39:08 -0700 (PDT) X-Gm-Message-State: AJIora8R5hx707e4LpClPKCcqWbZJoE928F8XxxPYG24VLtXGTvcuI4M 5ja/d2yL9iq3W1e80bfoUfY0tcpHxUo16xqx3ZU= X-Received: by 2002:a67:d495:0:b0:357:688d:f65c with SMTP id g21-20020a67d495000000b00357688df65cmr2936127vsj.59.1659177547759; Sat, 30 Jul 2022 03:39:07 -0700 (PDT) MIME-Version: 1.0 References: <32a74a218c76611f897fd1df1ad0059068621133.camel@xry111.site> <0179679b736aea7258981dec2d83107cce74dfc1.camel@xry111.site> <6b5d2188f93ed72b67a4bbb7116113f833fe1ee5.camel@xry111.site> <7cad6e78014168a8906e130e1cf3809077d2bda7.camel@xry111.site> <1d0783b87bda3e454a111862fcc5b5faffcb16b0.camel@xry111.site> <00eede4b1380888a500f74b1e818bb25a550632b.camel@xry111.site> <674cb3e9-d820-016b-a210-afd37ed6e25e@loongson.cn> <5233653cceab9c2baf6510bd712cd53ef63e3aac.camel@xry111.site> In-Reply-To: <5233653cceab9c2baf6510bd712cd53ef63e3aac.camel@xry111.site> From: Huacai Chen Date: Sat, 30 Jul 2022 18:38:53 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 0/4] LoongArch: Support new relocation types To: Xi Ruoyao Cc: Lulu Cheng , Youling Tang , loongarch@lists.linux.dev, LKML , WANG Xuerui , Jinyang He Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 30, 2022 at 5:51 PM Xi Ruoyao wrote: > > On Sat, 2022-07-30 at 14:44 +0800, Lulu Cheng wrote: > > > > If addr_global is rejected or not implemented (for example, building the > > > > kernel with GCC 12), *I expect* the following hack to work (I've not > > > > tested it because I'm AFK now). Using visibility in kernel seems > > > > strange, but I think it may make some sense because the modules are some > > > > sort of similar to an ELF shared object being dlopen()'ed, and our way > > > > to inject per-CPU symbols is analog to ELF interposition. > > > > > > > Sadly, I don't know what visibility is, does it have something to do > > > with __visible in include/linux/compiler_attributes.h? > > They are different definitions of visibility and mostly unrelated. > Unfortunately humans do not have enough words in the language to > disambiguate those different concepts :). > > -fvisibility and __attribute__((visibility)) are for ELF shared objects. > Kernel developers usually do not need to take care of them (unless > working on VDSO). > > -fvisibility=default (yes, it's the default) makes the symbol "possible > to be interposed" while -fPIC. Say > > $ cat main.c > extern int f(void); > extern int printf(const char *, ...); > int x = 1; > int main() { printf("%d\n", f()); } > $ cat shared.c > int x = 42; > int f(void) { return x; } > $ cc shared.c -fPIC -shared -o libshared.so > $ cc main.c -L. -Wl,-rpath,. -lshared > $ ./a.out > 1 > > You may think it strange but it's so-called "symbol interposition" > mandated by ELF spec. To make it work, the compiler has to use GOT > access for "x" instead of PC-relative access. > > OTOH, a "hidden" visibility disallows interposition: > > $ cat shared-1.c > __attribute__((visbility("hidden"))) int x = 42; > int f(void) { return x; } > $ cc shared-1.c -fPIC -shared -o libshared.so > $ ./a.out > 42 > > Now the compiler will use PC-relative access for "x" in "f". > > In my hack the combination of "-fPIC" and > "__attribute__((visibility("default")))" for per-CPU symbols makes per- > CPU symbols accessed via GOT, and "-fvisibility=hidden" keeps normal > symbols accessed via PC-relative within a TU. > > Note that the visibility of a symbol is also recorded in the symtab, and > ld.so will refuse to access a hidden symbol in one shared object from > another. But the kernel module loader just doesn't care the visibility > field in symtab so it won't affect us. > > Basically the hack just uses visibility options & attributes *in a way > they are not designed for* to trick the compiler to emit GOT accesses > for per-CPU symbols. A new attribute ("get_through_got"/"movable" or > whatever) is definitely wanted to avoid such a tricky approach, but the > hack can be used if we want modular kernel able to be built with GCC 12. So it has nothing to do with __visible in include/linux/compiler_attributes.h? Or __visible is a similar thing that used by Linux kernel? Huacai > -- > Xi Ruoyao > School of Aerospace Science and Technology, Xidian University