From patchwork Thu Oct 29 15:11:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 316035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23630C4363A for ; Thu, 29 Oct 2020 15:12:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA33220723 for ; Thu, 29 Oct 2020 15:12:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D2D7Hs26" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbgJ2PMW (ORCPT ); Thu, 29 Oct 2020 11:12:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43787 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728122AbgJ2PMT (ORCPT ); Thu, 29 Oct 2020 11:12:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603984337; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8yXg8GBRC3KQm8TIwzNWSAA5c5aI10yuXVMvwbMl8jQ=; b=D2D7Hs267/T35ZCny5IN4J/5DNaOebL1uAyd7HzDgLQX7V7qXTz9DNTMFbd/kyq+woDZRL /Raq2ASH1EdRdpxsXBOPHN9XjyuuHpZPpWuk7yyVqLanWyBraCOEbuyUZ15IKyfK99X7id HY57l5qpyZBTLdeuvsq6GkHIbAzqfYM= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-jkNSuBxZMx-a6uavGNkSWQ-1; Thu, 29 Oct 2020 11:12:14 -0400 X-MC-Unique: jkNSuBxZMx-a6uavGNkSWQ-1 Received: by mail-pg1-f200.google.com with SMTP id u4so2312922pgg.14 for ; Thu, 29 Oct 2020 08:12:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8yXg8GBRC3KQm8TIwzNWSAA5c5aI10yuXVMvwbMl8jQ=; b=m0vhPmDjwN8STxpbwvmJ9nOyeg2UL7G7qXakXEy780r8Gyt80xSiE3hCuwV3dYXqIe bLrwigCu+m4csbPKgr380vw0ZSSYWiJnhvqM+bE68gfGkLX+lmt3tbWTFpsAOY+QlHvZ E8USJiYXbFyu58GDW/tcBC9if/Bk816hF2wcIrzH+fl508u8qktabgFWdjodMUAKvBp1 1aA9ZKmJwBn8wY6ZnKyCMz8oizPxOVXnWoQMnUxcd47yrs/45OeouwrMLelW31Ct4fOt IOp92if2FrAtCSqUrekMuPLb4XZC9VBtGtUyW1rW00MBa8EJs/ir20aN7PRdgYaaPxDE oOaQ== X-Gm-Message-State: AOAM530UxXKxQybcox3DDZxv9S2J+06I0haqaErWkkmbMenPplGPpqGw glzEJ5O719pO5Ixu/S+/ue318q27w51fIFVSAl7YpkVvy7L/ERpzKzw2n3j6EDMjArU9gv82bEc tGEIDnmHE/bZG2bg= X-Received: by 2002:a17:902:82c8:b029:d5:af76:e447 with SMTP id u8-20020a17090282c8b02900d5af76e447mr4522654plz.42.1603984333260; Thu, 29 Oct 2020 08:12:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwraKY2zYjg/36Q/sRro4/67gXgpcUIi2epbNWb6q9PHHSU54xissIzzblfsvoCuCO8XJVZCw== X-Received: by 2002:a17:902:82c8:b029:d5:af76:e447 with SMTP id u8-20020a17090282c8b02900d5af76e447mr4522624plz.42.1603984333014; Thu, 29 Oct 2020 08:12:13 -0700 (PDT) Received: from localhost.localdomain.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id 3sm3305435pfv.92.2020.10.29.08.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 08:12:12 -0700 (PDT) From: Hangbin Liu To: Stephen Hemminger , Daniel Borkmann , David Ahern , Alexei Starovoitov Cc: Martin KaFai Lau , Song Liu , Yonghong Song , David Miller , Jesper Dangaard Brouer , netdev@vger.kernel.org, bpf@vger.kernel.org, Jiri Benc , Andrii Nakryiko , =?utf-8?q?Toke_H=C3=B8ila?= =?utf-8?q?nd-J=C3=B8rgensen?= , Hangbin Liu Subject: [PATCHv3 iproute2-next 1/5] configure: add check_libbpf() for later libbpf support Date: Thu, 29 Oct 2020 23:11:42 +0800 Message-Id: <20201029151146.3810859-2-haliu@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201029151146.3810859-1-haliu@redhat.com> References: <20201028132529.3763875-1-haliu@redhat.com> <20201029151146.3810859-1-haliu@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds a check to see if we support libbpf. By default the system libbpf will be used, but static linking against a custom libbpf version can be achieved by passing LIBBPF_DIR to configure. FORCE_LIBBPF can be set to force configure to abort if no suitable libbpf is found, which is useful for automatic packaging that wants to enforce the dependency. Signed-off-by: Hangbin Liu Reviewed-by: Toke Høiland-Jørgensen --- v3: Check function bpf_program__section_name() separately and only use it on higher libbpf version. v2: No update --- configure | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/configure b/configure index 307912aa..58a7176e 100755 --- a/configure +++ b/configure @@ -240,6 +240,97 @@ check_elf() fi } +have_libbpf_basic() +{ + cat >$TMPDIR/libbpf_test.c < +int main(int argc, char **argv) { + bpf_program__set_autoload(NULL, false); + bpf_map__ifindex(NULL); + bpf_map__set_pin_path(NULL, NULL); + bpf_object__open_file(NULL, NULL); + return 0; +} +EOF + + $CC -o $TMPDIR/libbpf_test $TMPDIR/libbpf_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS >/dev/null 2>&1 + local ret=$? + + rm -f $TMPDIR/libbpf_test.c $TMPDIR/libbpf_test + return $ret +} + +have_libbpf_sec_name() +{ + cat >$TMPDIR/libbpf_sec_test.c < +int main(int argc, char **argv) { + void *ptr; + bpf_program__section_name(NULL); + return 0; +} +EOF + + $CC -o $TMPDIR/libbpf_sec_test $TMPDIR/libbpf_sec_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS >/dev/null 2>&1 + local ret=$? + + rm -f $TMPDIR/libbpf_sec_test.c $TMPDIR/libbpf_sec_test + return $ret +} + +check_force_libbpf() +{ + # if set FORCE_LIBBPF but no libbpf support, just exist the config + # process to make sure we don't build without libbpf. + if [ -n "$FORCE_LIBBPF" ]; then + echo "FORCE_LIBBPF set, but couldn't find a usable libbpf" + exit 1 + fi +} + +check_libbpf() +{ + if ! ${PKG_CONFIG} libbpf --exists && [ -z "$LIBBPF_DIR" ] ; then + echo "no" + check_force_libbpf + return + fi + + if [ $(uname -m) == x86_64 ]; then + local LIBSUBDIR=lib64 + else + local LIBSUBDIR=lib + fi + + if [ -n "$LIBBPF_DIR" ]; then + LIBBPF_CFLAGS="-I${LIBBPF_DIR}/include -L${LIBBPF_DIR}/${LIBSUBDIR}" + LIBBPF_LDLIBS="${LIBBPF_DIR}/${LIBSUBDIR}/libbpf.a -lz -lelf" + else + LIBBPF_CFLAGS=$(${PKG_CONFIG} libbpf --cflags) + LIBBPF_LDLIBS=$(${PKG_CONFIG} libbpf --libs) + fi + + if ! have_libbpf_basic; then + echo "no" + echo " libbpf version is too low, please update it to at least 0.1.0" + check_force_libbpf + return + else + echo "HAVE_LIBBPF:=y" >>$CONFIG + echo 'CFLAGS += -DHAVE_LIBBPF ' $LIBBPF_CFLAGS >> $CONFIG + echo 'LDLIBS += ' $LIBBPF_LDLIBS >>$CONFIG + fi + + # bpf_program__title() is deprecated since libbpf 0.2.0, use + # bpf_program__section_name() instead if we support + if have_libbpf_sec_name; then + echo "HAVE_LIBBPF_SECTION_NAME:=y" >>$CONFIG + echo 'CFLAGS += -DHAVE_LIBBPF_SECTION_NAME ' $LIBBPF_CFLAGS >> $CONFIG + fi + + echo "yes" +} + check_selinux() # SELinux is a compile time option in the ss utility { @@ -385,6 +476,9 @@ check_setns echo -n "SELinux support: " check_selinux +echo -n "libbpf support: " +check_libbpf + echo -n "ELF support: " check_elf