Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2154864iof; Tue, 7 Jun 2022 21:35:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHlBC91ZUlKzsRxjCWylWllmx6AdG1ZtZkXj8a9DHwKeuZLXU+hjWNBiVptRQjFV0YryD3 X-Received: by 2002:a17:902:8693:b0:161:e28f:f85f with SMTP id g19-20020a170902869300b00161e28ff85fmr32660211plo.17.1654662918903; Tue, 07 Jun 2022 21:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654662918; cv=none; d=google.com; s=arc-20160816; b=F2SW14PECPuTvOTVKXqf2RD5sMUHX0J3pJKgzOeDK98wI3F9u8YJVd9KsytRPSHKvF 57VIQMocjsADxDnxPgH7qHPZHx1YV/PcznsDRnLBuEbuHTzgXcaP+Vvda80GWmInsEj7 UA0veVUCogBQDh4liULf0qu/0gEQHMrVkYbenwzMboSUKRx8E2sARQ4sNLitnA/jjx1Z CTnMu88bQpWsTQqS0bphKt/PLgb7sfhTLKS4SbCBVQikD3dnXlR5skhMCapiBlfwRtnw 1yta0ukeGafuwsUxNgrIRRVpDQGjsgX5xbBWNE9dSPjebAJ/HqgkXBDYvsH6uH3E9wqz zC3w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/nit7NKq0tbrVXXqBZEooST6/PEMWoOMkM7udbWZN20=; b=Qg1UbfFNh1XUHW55BBMah1IgxzJ3G+mPaci3wxWOhWiE7ThRGYnst4InLBawU1o/Z7 21q8An6mr79/pb1umQRhIYbC8RdCJznCEmWfZwNIvNR9FKMLLiJr7FnQxoxfA8ysA/CD R0YjpmMkSacBLSenr2MnsrJwtFcuqrXLcz+k2RvDgGTMPuzc8sHelxVnzhZUiJNL8Xx2 CyzWxtlW2I4nvJXp1E8wPqURJGXJ9jjKtkhotph7MEVfO49BPD4lluaNjnpZIRMzOFYs wEgGjXanzrDPNuHJcd8vymmOuFcKSxr3s73WOqZ0UXbjfw18tSLqvzbkwzGDZUF/I1pr 4q4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sUprCX9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m6-20020a637106000000b0039cb8fe4bddsi18399795pgc.259.2022.06.07.21.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:35:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sUprCX9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B81A62309AB; Tue, 7 Jun 2022 21:03:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384523AbiFGWZp (ORCPT + 99 others); Tue, 7 Jun 2022 18:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381510AbiFGVRt (ORCPT ); Tue, 7 Jun 2022 17:17:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CFC82236A0; Tue, 7 Jun 2022 11:59:06 -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 ams.source.kernel.org (Postfix) with ESMTPS id E5ED7B8220B; Tue, 7 Jun 2022 18:59:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5751CC385A5; Tue, 7 Jun 2022 18:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628341; bh=ogeVAfImOn1qB2VO8Ou/l8PWkEnS53s0tsZgViK52kQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUprCX9jG5soXtKTESTkbgjdDaTft17pvxRXhi8CUnUEJ16WoDRkS5egIaunSKfUK Yo3bANFfJm4LkdiKxOM4RThEIjpKuHY/MWvTcMjQGNh7adYKazw4JyZHfzzcGjddCO pSYtpyq0oXhpNzdJD3LP41gGx0uf+WDukJYVqiTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.18 295/879] libbpf: Dont error out on CO-RE relos for overriden weak subprogs Date: Tue, 7 Jun 2022 18:56:53 +0200 Message-Id: <20220607165011.410424283@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Andrii Nakryiko [ Upstream commit e89d57d938c8fa80c457982154ed6110804814fe ] During BPF static linking, all the ELF relocations and .BTF.ext information (including CO-RE relocations) are preserved for __weak subprograms that were logically overriden by either previous weak subprogram instance or by corresponding "strong" (non-weak) subprogram. This is just how native user-space linkers work, nothing new. But libbpf is over-zealous when processing CO-RE relocation to error out when CO-RE relocation belonging to such eliminated weak subprogram is encountered. Instead of erroring out on this expected situation, log debug-level message and skip the relocation. Fixes: db2b8b06423c ("libbpf: Support CO-RE relocations for multi-prog sections") Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220408181425.2287230-2-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index dabf9a1451c3..7af6805a863d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -5665,10 +5665,17 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path) insn_idx = rec->insn_off / BPF_INSN_SZ; prog = find_prog_by_sec_insn(obj, sec_idx, insn_idx); if (!prog) { - pr_warn("sec '%s': failed to find program at insn #%d for CO-RE offset relocation #%d\n", - sec_name, insn_idx, i); - err = -EINVAL; - goto out; + /* When __weak subprog is "overridden" by another instance + * of the subprog from a different object file, linker still + * appends all the .BTF.ext info that used to belong to that + * eliminated subprogram. + * This is similar to what x86-64 linker does for relocations. + * So just ignore such relocations just like we ignore + * subprog instructions when discovering subprograms. + */ + pr_debug("sec '%s': skipping CO-RE relocation #%d for insn #%d belonging to eliminated weak subprogram\n", + sec_name, i, insn_idx); + continue; } /* no need to apply CO-RE relocation if the program is * not going to be loaded -- 2.35.1