Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp3064986lqt; Tue, 23 Apr 2024 09:22:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRpEDu30EFGRxPdwkuJJfWNXRgGaSqvKiO6yxacPC9JSWf50t0MaxMBm58sNmL7bDyolZ3DYB2yyKeXgPi+nTNypcGfbOjsENSnuBAFw== X-Google-Smtp-Source: AGHT+IGkbKZMBgAyfRwIfF+X1A/YIlonlYQ7VphrwdxedE/T1QLcODkaHtu2DcgF/SLc1zM3d9Jx X-Received: by 2002:ac2:4887:0:b0:519:5acc:b114 with SMTP id x7-20020ac24887000000b005195accb114mr14911lfc.45.1713889363458; Tue, 23 Apr 2024 09:22:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713889363; cv=pass; d=google.com; s=arc-20160816; b=GZneVDaW8FOX8A5tJzcPOemJN9k2oouQqYiH+yxDu3r3DpUykK1DOtyY+vFhPcb5VM eAS2dH+wu4k26EarLdcz6XgBDMEA9rVvAkgizPgI6MZgochmSXFqI6gAJnkiB/SBEC25 qUoB6uZjKlPs7hKSFxD0APd7SnwJe4Z4p64fiYpUPx7YjtEAk/P2nBbmT6RMTSPTwdCp +Q/wM3QvcKY4uOws4u7YtSbMkHS5vOPW/T2kZpJnvDWLAyUa1AK/MEaDHHeThva4IbEV bZirtS7/vbvZD3JgPgV4zkEd+r1RKu+/4KOhF6cbE9RId0zTFRrxZ2i6GwzpehqDaP6k PKaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=yw5POrru6JiUCdnoO6CZWCODghzSHrzzW0L6AAe5rcg=; fh=tRK11I9XotBCbSfyRIIJ2dBIawKVEtDLcouPkDeyIHg=; b=sUP6XhVCFnY7cr3cpaP7IpqCNpmB63rTtRYmJ4NU0tD1NMOoyYjG80tW4CDSPd+Itp dL85+4rLCCAnU8ZcwgaPKi3FWNB4O5hAXAO58aexkDY6R3k3BsCQYcFArSRmAChZ05dR JPWKmIDMllU+5XR0ER3Fu1yVpODofELseM+cJYUnqPgWudYX15D/kxQxW9RWF2QmeG7m U/02NVWWnrOfK5HeXB237NgCJXQTD5jUE4qYHD7H6axexbvIe2wSHxAMChWDB/+Ud2EF fQ/OmWt2pLLt/fZJpbZTVzWq33VYM+vcHIMM53XUncyyraL/CfAzpxwXyO2IlNoQggf+ OobQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LUPSdfuW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-155547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qf3-20020a1709077f0300b00a55ba05eae0si2581904ejc.382.2024.04.23.09.22.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 09:22:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LUPSdfuW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-155547-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155547-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 30EA91F242FE for ; Tue, 23 Apr 2024 16:22:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45E8213D50C; Tue, 23 Apr 2024 16:22:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LUPSdfuW" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63A3913D2B6; Tue, 23 Apr 2024 16:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713889344; cv=none; b=FWJdl3H/iA1NkZFENWZE3y53zMUPmU0vyNt+hfMVlJlfyvNlTXlS8ZcOhc1NCKKrDfLQ02k7bSCXXNEspczRd7K7SEzq+ft7g3bX75D2zbg3FkNk/SngkVua6Ge2t1UKmnzkywwfvLDfe7aRSFdrrs9ZpZzcvQer5APEJ/aaSP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713889344; c=relaxed/simple; bh=oJzUEgPOfRz4FVU7f4MkDckgyDNtgFaj6AoyVUoITHg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=dKFNSyzGsvwWErxRr9g1d0UOsX/Yf2xeT0iSHGVHNC38b2SkOuoyrPuVy5vHBGL2z2QSKqxzs3TkjGURmKMZCi0APYlyiUB2jsl/jxlFh3O2qL83vc8eurgLu/sbr6ij5eLmUYHw/PqWmduHidgzl/ireLvOcKdRvR0EitXekG8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LUPSdfuW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDD67C32783; Tue, 23 Apr 2024 16:22:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713889344; bh=oJzUEgPOfRz4FVU7f4MkDckgyDNtgFaj6AoyVUoITHg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LUPSdfuWswat2YbontFlrpuaSPEp5kZTyppwr/svANpYziPuvV9/9qN/T2RaeE4vh oGanM8CiaH4JeMTrw2KAtTpzUYtZB298/wq6ScbcPihG8jTIxHKMO2bfpL/9VsshmX AJt43koJwYmBY1ippurWAn7CiuVrKeye7ZFUWkheGdmnSwCJcEwgb97TV8u541sx+o gp4k0/eLgS1pD3/crkwg7h2cH2RSnPcPhIlEEYgZNbEHPvzfDvyK4mU/jz/vKsP1sC e3fbV56QrIr/DMPDnkw0cdJVf0jo1FY55AB3nh/GA8KxkX6xLFjQjh4PYhhRYLx4KA U5obh+beqlvQg== Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2db6f5977e1so78363541fa.2; Tue, 23 Apr 2024 09:22:23 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXbIecXI85x+s+m1F4UjopU5zcrto7wT2VaRrUVuJFrjQ3qeMdc10f93Y/mxy9M9odFf2X3zvNcpE4Sy5YhIRF8YDHO/t8rTrfeC4ViFIRHExSYm2UT9ll5R/jBDw5TXnoD2X6KTjU+dP0G X-Gm-Message-State: AOJu0Yx3iJeaEL/VVsr42P8AdHXjhde33Ct+vCGGsvAa71D55LiHWx3Y XxsRr90y+660NpoNjCUtoefz9PWS84JwIrhma+q1xDxnJZ9/udfLrByakPXl70qs1YugLl31ePG 3ZBh+MakAKMxsCX3E1ESX9D8tAHs= X-Received: by 2002:a2e:84d5:0:b0:2d4:37ca:92d1 with SMTP id q21-20020a2e84d5000000b002d437ca92d1mr8064840ljh.42.1713889342313; Tue, 23 Apr 2024 09:22:22 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240420145303.238068-2-ardb+git@google.com> <9fda72fa-e5e5-4d45-b268-dd98d28fb5a1@linaro.org> In-Reply-To: <9fda72fa-e5e5-4d45-b268-dd98d28fb5a1@linaro.org> From: Ard Biesheuvel Date: Tue, 23 Apr 2024 18:22:10 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5] kallsyms: Avoid weak references for kallsyms symbols To: Konrad Dybcio Cc: Masahiro Yamada , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Nick Desaulniers , Kees Cook , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 23 Apr 2024 at 18:01, Konrad Dybcio wrot= e: > > > > On 4/22/24 18:02, Masahiro Yamada wrote: > > On Sat, Apr 20, 2024 at 11:53=E2=80=AFPM Ard Biesheuvel wrote: > >> > >> From: Ard Biesheuvel > >> > >> kallsyms is a directory of all the symbols in the vmlinux binary, and = so > >> creating it poses somewhat of a chicken-and-egg problem, as its non-ze= ro > >> size affects the layout of the binary, and therefore the values of the > >> symbols. > >> > >> For this reason, the kernel is linked more than once, and the first pa= ss > >> does not include any kallsyms data at all. For the linker to accept > >> this, the symbol declarations describing the kallsyms metadata are > >> emitted as having weak linkage, so they can remain unsatisfied. During > >> the subsequent passes, the weak references are satisfied by the kallsy= ms > >> metadata that was constructed based on information gathered from the > >> preceding passes. > >> > >> Weak references lead to somewhat worse codegen, because taking their > >> address may need to produce NULL (if the reference was unsatisfied), a= nd > >> this is not usually supported by RIP or PC relative symbol references. > >> > >> Given that these references are ultimately always satisfied in the fin= al > >> link, let's drop the weak annotation on the declarations, and instead, > >> provide fallback definitions with weak linkage. This informs the > >> compiler that ultimately, the reference will always be satisfied. > >> > >> While at it, drop the FRV specific annotation that these symbols resid= e > >> in .rodata - FRV is long gone. > >> > >> Cc: Masahiro Yamada > >> Cc: linux-kbuild@vger.kernel.org > >> Acked-by: Nick Desaulniers > >> Acked-by: Kees Cook > >> Acked-by: Arnd Bergmann > >> Link: https://lore.kernel.org/all/20240415075837.2349766-5-ardb+git@go= ogle.com > >> Signed-off-by: Ard Biesheuvel > >> --- > >> v5: - avoid PROVIDE() in the linker script, use weak definitions inste= ad > >> - drop tested-by, replace reviewed-by with acked-by > >> > > > > Applied to linux-kbuild. Thanks. > > Hi, this commit seems to break call traces, resulting in output like: > > [ 2.777006] Call trace: > [ 2.777007] _text+0x89e7e8/0x39e0000 > [ 2.777008] _text+0x89e82c/0x39e0000 > [ 2.777009] _text+0x2b940cc/0x2bd2a90 > [ 2.777011] _text+0x2b941a4/0x2bd2a90 > [ 2.777012] _text+0x145dc/0x39e0000 > [ 2.777014] _text+0x2b51184/0x2bd2a90 > [ 2.777016] _text+0x18fc6a4/0x39e0000 > [ 2.777018] _text+0x15644/0x39e0000 > [ 2.777019] ---[ end trace 0000000000000000 ]--- > This patch triggers an issue in the compiler, which appears to perform constant propagation on variables defined as weak, and this is definitely a compiler bug. (A weak variable can be superseded by another instance from a different object at link time, so the compiler cannot make assumptions based on the version of the variable it observes at compile time) It has already been dropped from the kbuild tree.