Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp247905ybe; Wed, 18 Sep 2019 16:31:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAddN5hr8kvDmj3FrwifOL0jkUtGjLnvMALSlYdsQsZwy08xmbLLnka7GYaA8J307lk+gJ X-Received: by 2002:a17:906:7e56:: with SMTP id z22mr9462716ejr.294.1568849474177; Wed, 18 Sep 2019 16:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568849474; cv=none; d=google.com; s=arc-20160816; b=hGAv57Byrx/kii5skzAiZ6BeKiywUVZYNe3o/DdiKnFIRpj8d+enPgk3JxIA2LYjAd 8fJ4pRyH2lpcrbYcgo0QzC6FSmWGkr0fn/zRUkX+fujtS49glutTmH9atCI/UfQvXlDv 4nifbpBaTKD+D1NOT4CcKEPyV4qBWWRPuNsBFmwUciA9EV1bq4ZFfXQ5EPW8t7vaynse sOc2m84W3gtUSb5dGB4Rz4zkKX2PQf1nOlMazjb3sR7pZyLRzHdGJpHXGUOZbUrWuLeP jCKkduGlq7X0SMrss3tLMRKE3/DbRT08quZC9F4JomeRQ8TxQmG8+VkF2FtrrNPpIDDR zIjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6P902L7LJNPT4ssJNWdrSjXG2av0wc4klnUEBzyUx6c=; b=t5d3aL+DWFW6zJ9jstozudyPxc/jxxoaZbrmK0N5UsfrLgOVs3HNNxTHolqzpdlOR3 raVg8rGBX9/b0o14wser5lbTcxVIbbx2J+Yl5Hy3NJVLJmkoPHM0xI4WQEadbrG4dEbj 8GXiAcHS/tNBpOHPUZ36ojjDd5A6b8oC7fF6vxOMjC5RQ5dF/ahgGcvjIuiVgaEl4UQa wKqvXmphJHk7DoSEY7izXI7p+vcxg4Vy4zkkqN86JfsSu5yXKo0Ccq/scHfaUPnGYIVx oP9ZfPRVCCv9bHJFoI97JILKsS4QXXRA5jKofwWjnGhVYqsfDDlrh7JobAYn20sOV4DY Zp1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I0USsfmH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 22si374945ejz.218.2019.09.18.16.30.50; Wed, 18 Sep 2019 16:31:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I0USsfmH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388027AbfIRVmp (ORCPT + 99 others); Wed, 18 Sep 2019 17:42:45 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:42628 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387521AbfIRVmo (ORCPT ); Wed, 18 Sep 2019 17:42:44 -0400 Received: by mail-qk1-f196.google.com with SMTP id f16so1066160qkl.9; Wed, 18 Sep 2019 14:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6P902L7LJNPT4ssJNWdrSjXG2av0wc4klnUEBzyUx6c=; b=I0USsfmHkX8/IosUABXUcAOvs0CABxoOv10rCj4DZH6xCHdY2L4yQblg6NZYhHguX2 MsA6e++yIPq7eRMJfOF0+5ORua+JGZQPZ35gb1IFeep1EFUYMoo06xlPuVJ4kdRzbTLk PBO+Nl9u2hQIl6+su6TFrtXNe+RqK/AnWBXsfIz6yh08lEsPuswLbY/MT8CNOcd3mAJX sV1GGSl3zT58PUKSY5Z9K8Mw/GTb5W8kR7XzdlCkaOwV7F9ZyBnxDaAD3pIOUJpxNR2O 5aNKuurKLuISXsII48WI+gCkrY1ViQd8AVJ2Sthn0YJEhJNuj3bV3cPWxKw8zLAEOtQv Scbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6P902L7LJNPT4ssJNWdrSjXG2av0wc4klnUEBzyUx6c=; b=UQiTVCu9bpQFlKkwWTehfjJNHfx9mMFhupDSn4g64A2FL8WpjoXpiWk8BzjCOhaq12 YP3wFq3J96mpeCQYclX13Ial7Emig7L4ZI3HAdK6SSKQr99iMs6y8asi8NjmSUdfwXIe VTU6WjPy0zYyC2QZMLvje94oZsPd+J1qMfGZ8RvJjZuRkz6zB3SbZdpaoNOyRsB/AVLu jyDlmZcbA6Va9wJtQDWJ8/PHc8gUSJQCs1JyOeRcySVraHBvgnA6SkUhsipLFM68RjaB k/vt5HIc0y03dcm8bZj5juw0pObqFgwIH0BBkrbwuMgpjss+/GJuACCLtmyagZI21lGG oDgQ== X-Gm-Message-State: APjAAAUb6aFDjWai3TQKhRKTQz5vNiVDyYU6uGAV9nqIG2iZMvSkqTOf n+GH3Nqyu8opZkJ1SdwxgSBawAByqbUFz/FtQ6o= X-Received: by 2002:a37:98f:: with SMTP id 137mr6695305qkj.449.1568842963752; Wed, 18 Sep 2019 14:42:43 -0700 (PDT) MIME-Version: 1.0 References: <20190916105433.11404-1-ivan.khoronzhuk@linaro.org> <20190916105433.11404-12-ivan.khoronzhuk@linaro.org> <20190918110517.GD2908@khorivan> In-Reply-To: <20190918110517.GD2908@khorivan> From: Andrii Nakryiko Date: Wed, 18 Sep 2019 14:42:32 -0700 Message-ID: Subject: Re: [PATCH v3 bpf-next 11/14] libbpf: makefile: add C/CXX/LDFLAGS to libbpf.so and test_libpf targets To: Ivan Khoronzhuk Cc: Alexei Starovoitov , Daniel Borkmann , Yonghong Song , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , john fastabend , open list , Networking , bpf , clang-built-linux@googlegroups.com, sergei.shtylyov@cogentembedded.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 18, 2019 at 4:05 AM Ivan Khoronzhuk wrote: > > On Tue, Sep 17, 2019 at 10:19:22PM -0700, Andrii Nakryiko wrote: > >On Mon, Sep 16, 2019 at 4:00 AM Ivan Khoronzhuk > > wrote: > >> > >> In case of LDFLAGS and EXTRA_CC/CXX flags there is no way to pass them > >> correctly to build command, for instance when --sysroot is used or > >> external libraries are used, like -lelf, wich can be absent in > >> toolchain. This can be used for samples/bpf cross-compiling allowing > >> to get elf lib from sysroot. > >> > >> Signed-off-by: Ivan Khoronzhuk > >> --- > >> tools/lib/bpf/Makefile | 11 ++++++++--- > >> 1 file changed, 8 insertions(+), 3 deletions(-) > >> > >> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile > >> index c6f94cffe06e..bccfa556ef4e 100644 > >> --- a/tools/lib/bpf/Makefile > >> +++ b/tools/lib/bpf/Makefile > >> @@ -94,6 +94,10 @@ else > >> CFLAGS := -g -Wall > >> endif > >> > >> +ifdef EXTRA_CXXFLAGS > >> + CXXFLAGS := $(EXTRA_CXXFLAGS) > >> +endif > >> + > >> ifeq ($(feature-libelf-mmap), 1) > >> override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT > >> endif > >> @@ -176,8 +180,9 @@ $(BPF_IN): force elfdep bpfdep > >> $(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION) > >> > >> $(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN) > >> - $(QUIET_LINK)$(CC) --shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \ > >> - -Wl,--version-script=$(VERSION_SCRIPT) $^ -lelf -o $@ > >> + $(QUIET_LINK)$(CC) $(LDFLAGS) \ > >> + --shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \ > >> + -Wl,--version-script=$(VERSION_SCRIPT) $^ -lelf -o $@ > >> @ln -sf $(@F) $(OUTPUT)libbpf.so > >> @ln -sf $(@F) $(OUTPUT)libbpf.so.$(LIBBPF_MAJOR_VERSION) > >> > >> @@ -185,7 +190,7 @@ $(OUTPUT)libbpf.a: $(BPF_IN) > >> $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ > >> > >> $(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a > >> - $(QUIET_LINK)$(CXX) $(INCLUDES) $^ -lelf -o $@ > >> + $(QUIET_LINK)$(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) $^ -lelf -o $@ > > > >Instead of doing ifdef EXTRA_CXXFLAGS bit above, you can just include > >both $(CXXFLAGS) and $(EXTRA_CXXFLAGS), which will do the right thing > >(and is actually recommended my make documentation way to do this). > It's good practice to follow existent style, I've done similar way as for > CFLAGS + EXTRACFLAGS here, didn't want to verify it can impact on > smth else. And my goal is not to correct everything but embed my > functionality, series tool large w/o it. Alright, we'll have to eventually clean up this Makefile. What we do with EXTRA_CFLAGS is not exactly correct, as in this Makefile EXTRA_CFLAGS are overriding CFLAGS, instead of extending them, which doesn't seem correct to me. BTW, bpftool does += instead of :=. All this is avoided by just keeping CFLAGS and EXTRA_CFLAGS separate and specifying both of them in $(CC)/$(CLANG) invocations. But feel free to ignore this for now. > > > > >But actually, there is no need to use C++ compiler here, > >test_libbpf.cpp can just be plain C. Do you mind renaming it to .c and > >using C compiler instead? > Seems like, will try in next v. Thanks! > > > > >> > >> $(OUTPUT)libbpf.pc: > >> $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ > >> -- > >> 2.17.1 > >> > > -- > Regards, > Ivan Khoronzhuk