Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5554908ybe; Tue, 10 Sep 2019 05:41:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0Kkh28F8b8PDrSSWPPvUoLzw1cCr0YxKnkU6rDomKQUQn0sPfk955wVTtCTLE//lWU5Pf X-Received: by 2002:a17:906:6bd0:: with SMTP id t16mr25194336ejs.189.1568119291858; Tue, 10 Sep 2019 05:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568119291; cv=none; d=google.com; s=arc-20160816; b=Xwy24TZnTGucG/AEPTolHEB3VLuGoA/HXEySKl5SgTeN/7NCvt3rZQw9kIt7B2jSSj +GqY91FBt8Ph7z62w+BvAiY8ue7gwO0Nuc2oVlVfR9cpCfxiLiyLsfZHzQDTHFs+XixR gqtmTJCcJP/cdYiSCSi4M3pOM3Jce84hghMokYd8zO7xGopEVPXsR91ygRAVaPw/k1LF ymE+WgefBHUUyTCxa4NmzUVjB/vVqErNwpogw6omySTKR3QKnwUmGBxPvGP58BIHYyok WfrYILai29P7BqhuEDS7Mgl1w9O+Cckj6biVupfYx1gnI0hrTr/dkhf7L0xoBe3C/Fx0 9UFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=DyCC3oN5QH71JUakHHjEAPConBRmS2tSFKyztM41paE=; b=LnJ0f4lrAdd5iZdc1Ku1L5crfpH2BEaKyjtMi2cICLSzDWUSD+SLXbTSNvoA6SoALc RCVdwHi2lzI4GDLoriSucwW8ujw/gJ6MxqjoRaQJVF9+rom0V2Bp77qRsl2eqtAGSXCI H2RmcFeOBf6L+6gJAWCB4WCnJPpqQP2bjzWnstWsfasbRxRbg8ZBX72ylHP7Nlycs+Va vA46spBl9ziZczqovBCppEdU0gSeSLTeUuHhVYrBp9QSXFSGsujCwMCKPVT9xr+jM6TL S09hesp4KVf3LbtQhAACKPxs9WTaaOpi9um4pYFU1anJ2qb8wqNohKmUdY4RahwKTVVD 0egA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FhMAYukP; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si10852306edb.56.2019.09.10.05.41.08; Tue, 10 Sep 2019 05:41:31 -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=@linaro.org header.s=google header.b=FhMAYukP; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393845AbfIJKjH (ORCPT + 99 others); Tue, 10 Sep 2019 06:39:07 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37282 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406095AbfIJKiv (ORCPT ); Tue, 10 Sep 2019 06:38:51 -0400 Received: by mail-lj1-f195.google.com with SMTP id y5so5078153lji.4 for ; Tue, 10 Sep 2019 03:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DyCC3oN5QH71JUakHHjEAPConBRmS2tSFKyztM41paE=; b=FhMAYukPpvDv7/gtjvzMVffNFIcDir8P7lhYYYuvZqn4IPk+26vo++/gi2+Fav2lWS 2w0rg43pR85xehveQr2y20Sf/xWGy45hcqxm7n5KfvKC2PdHKZ6azaDS0+iYJZHWv1/+ zMwP5U8nJdDKd8kvKct4XQscyL1qzi10v+C7XVeZ/0iF69+cTYXeXEAhfbRNBY468TnA VezYYJjJ+KsPBLPpikBZqQ6oUaHLKB+BF6InRcmk7Ytt+iqa3y4EEVs9FZpRxH5cotkr 7Ef3YwV3rL6+eb+gar6COnTsoDiKOZ25XOCDZqnqyhZkiIwjkVECAFNb9X0bDFAcZPXG yNFg== 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; bh=DyCC3oN5QH71JUakHHjEAPConBRmS2tSFKyztM41paE=; b=AnNVIGdBpPSvq1RSUV89ImrOj9iO6riL2saoD4THCIpO506GL/H0OY5kIFxm2o6vZn woo7IIMZIIJgr4JQWd0guOKP+/f4WrjHi7z87PC4mKn/Jh+r5Vish61nfdzoJ+J+k7kW xTebzZodfgb9YP8nZ6mEd9EEmm6cEfqKLyUxCpgnbcg7zC9j8xLfkAR5gj5c4ByBq3pj UYK7ZaBO9iYEfPEzC5O07tsjKvr0v7tBvj60zLMu45oHrOwqTyS4tKdsER9agaDC00uY eh6jMrIOUwe73ChKaJ5V7amcGfO8+3AOayuWpg8Bluw3ygxyJO+vekMIIhP+rk1Jrr+b l+JA== X-Gm-Message-State: APjAAAU+nAH4xKQGBUqrdGfHtyrFfCoU7JAnbXQuFqtoN4PJl+9oW9YT oi0o/AFErim+uau3Ualf6YLjPQ== X-Received: by 2002:a2e:88c6:: with SMTP id a6mr19550313ljk.39.1568111929860; Tue, 10 Sep 2019 03:38:49 -0700 (PDT) Received: from localhost.localdomain (168-200-94-178.pool.ukrtel.net. [178.94.200.168]) by smtp.gmail.com with ESMTPSA id g5sm4005563lfh.2.2019.09.10.03.38.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 03:38:49 -0700 (PDT) From: Ivan Khoronzhuk To: ast@kernel.org, daniel@iogearbox.net, yhs@fb.com, davem@davemloft.net, jakub.kicinski@netronome.com, hawk@kernel.org, john.fastabend@gmail.com Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, clang-built-linux@googlegroups.com, Ivan Khoronzhuk Subject: [PATCH bpf-next 10/11] libbpf: makefile: add C/CXX/LDFLAGS to libbpf.so and test_libpf targets Date: Tue, 10 Sep 2019 13:38:29 +0300 Message-Id: <20190910103830.20794-11-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org> References: <20190910103830.20794-1-ivan.khoronzhuk@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 is used for samples/bpf cross-compiling allowing to get elf lib from sysroot. Signed-off-by: Ivan Khoronzhuk --- samples/bpf/Makefile | 8 +++++++- tools/lib/bpf/Makefile | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 79c9aa41832e..4edc5232cfc1 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -186,6 +186,10 @@ ccflags-y += -I$(srctree)/tools/perf ccflags-y += $(D_OPTIONS) ccflags-y += -Wall ccflags-y += -fomit-frame-pointer + +EXTRA_CXXFLAGS := $(ccflags-y) + +# options not valid for C++ ccflags-y += -Wmissing-prototypes ccflags-y += -Wstrict-prototypes @@ -252,7 +256,9 @@ clean: $(LIBBPF): FORCE # Fix up variables inherited from Kbuild that tools/ build system won't like - $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O= + $(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(PROGS_CFLAGS)" \ + EXTRA_CXXFLAGS="$(EXTRA_CXXFLAGS)" LDFLAGS=$(PROGS_LDFLAGS) \ + srctree=$(BPF_SAMPLES_PATH)/../../ O= $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE $(call filechk,offsets,__SYSCALL_NRS_H__) 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 $@ $(OUTPUT)libbpf.pc: $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ -- 2.17.1