Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6222570ybe; Tue, 17 Sep 2019 23:14:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwSFJr6vaKrS63b2tFAtFGPWREhgxJSZhvUF4YlRX0g5SjwXM2FFvsVQvB7iHUunQ/2JQw X-Received: by 2002:a17:906:3294:: with SMTP id 20mr7983461ejw.19.1568787287870; Tue, 17 Sep 2019 23:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568787287; cv=none; d=google.com; s=arc-20160816; b=uX+9xthvhJ2ZFzuLjJN96CFx196f5bWzp0R6PuwwiQcH1wltK8IqpKaadd2n6zRWzv MbJBUIXBKWJ10hB/ol7XDwOCZZQwbnwtqEHzPxb3V39uIor3/EssmCnabGgWDzMNVhvq Li1x5nHscWsuKWQ6GAzRP+P2Nc7RJI1EF7wdEKzStJ2Qw7zG5lEKhsU3g86zAqIoNQcX kwzO9yv8w4zmAofwX2Ph4cYLQ2Yhh9Ca8zrcaEOT7O1t8JzeVe2sYAwZtX/B/pr3unqm FIfr+1SCH9p/qe8h7zybI7TdHgHr2A+tUdCMBtV+OMYmbrM1acX/5w0gXhvERHSU1o4W A82A== 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=Xo9zYrCJEPVHMiv3h+aCm77vZarT+/8uPX2EY63h768=; b=icA88rCSOw4DwkJVp1kca5Z097b+1BFJAp8QDCuExG0BCJ81ZVJ5Y3FSdMIj2t8j3+ ToT7Kt+VaP95DIR71xbyN0l4dg+k8hcKB17SqfNvBaHbwp1tuTEnchbiKzt6y946mdeb EooOsVUfy77itJfzdXi0Wqvddrlul1wNZtx8sIFlKb2tXetzj0WnhYo9ShkdGD5VoxKs mpRn0zlwhxy9/gJWCvaYwhej+UzR3RMtIBHBk3Gi6wFAj76Cj+QgUVRHXvEBNuE2QcBB WCU4YwM4hFvsUxrpG4FiHbHUWcI2FdAQorMgnU3QTFHjCG2UVSDE5k1LGa/ByOYs45fI 9gAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bcPs6Rjq; 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 v53si2936743edc.378.2019.09.17.23.14.25; Tue, 17 Sep 2019 23:14:47 -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=bcPs6Rjq; 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 S1727369AbfIRFTe (ORCPT + 99 others); Wed, 18 Sep 2019 01:19:34 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:32961 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfIRFTe (ORCPT ); Wed, 18 Sep 2019 01:19:34 -0400 Received: by mail-qt1-f194.google.com with SMTP id r5so7457589qtd.0; Tue, 17 Sep 2019 22:19:33 -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=Xo9zYrCJEPVHMiv3h+aCm77vZarT+/8uPX2EY63h768=; b=bcPs6RjqrMrXV/QavjfJADE8CxKAVMNOM1fCm10VeGTuw1fF0b8O0tpuxry+vAiGnO zF7e/HTdlCYstizqK6PL2uObrtp+TfxLA4XZloQqoymLLeggkHtgLZOkchh6hSyE5GkC +EoHk9Q9pjmP3cSWHMznOLFoAawTTSW92+auoT1pb6EXuoi5BBU1AlmXQ1b+3HK9WLh2 p5PJeEqKlp0pce/bsV34qYfeu7Bi78zKouoO5IBjNJUvldSFgI3/TFNlwlN9j4gRzQNq pI7dQCrNj3+Yuj2/1VjTh2Vw1HRZzUsGKZA0xRWKBi+wPa9btMl83JSYtWwQ/6LDjV1G dMzg== 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=Xo9zYrCJEPVHMiv3h+aCm77vZarT+/8uPX2EY63h768=; b=EX/FWRFw/8YgrxSEHWVNBN0HcT9vtS0wnlgq6TIzHXum+KOgZfFwj1Ae4YAHdBLEck 8JvrHegBYAQB4pEPYQoFThHz27vuWNtL120E3FK3E4I+oR9Y0/FvcFClEHmYmWfM/BlD t0Cf2/mAxb+NYNBuyaagNr0HdCe1vQAahlDSD1RyoA7nQAJtLceIgNuIOz2MXouL7ZQD HXMwhs0i1gkrSsMDSVKPd9KNDWBbFmMeg05fhSiXi/h9wzNj6EgHNeDRb814v6SbZS8j pIeHZGDqFU8zKl4uSWiUYAL6VEuHeTFCmxN8tLKQgs0Xr3A+ISN/QsGrIPPwMm25VD1p twsw== X-Gm-Message-State: APjAAAW2FXraM6LHbaw5xyrDe9c6bQbi/lppvI2CYTfG3lWIZ653VzSs wjdO0Z7oj/N8SJXtErd9fstElLDq5lYq56swS3g= X-Received: by 2002:a0c:88f0:: with SMTP id 45mr1845990qvo.78.1568783973290; Tue, 17 Sep 2019 22:19:33 -0700 (PDT) MIME-Version: 1.0 References: <20190916105433.11404-1-ivan.khoronzhuk@linaro.org> <20190916105433.11404-12-ivan.khoronzhuk@linaro.org> In-Reply-To: <20190916105433.11404-12-ivan.khoronzhuk@linaro.org> From: Andrii Nakryiko Date: Tue, 17 Sep 2019 22:19:22 -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 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). 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? > > $(OUTPUT)libbpf.pc: > $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ > -- > 2.17.1 >