Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752493AbdL0TRc (ORCPT ); Wed, 27 Dec 2017 14:17:32 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:47990 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751203AbdL0TR2 (ORCPT ); Wed, 27 Dec 2017 14:17:28 -0500 From: Roman Gushchin To: CC: , , Roman Gushchin , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v3 bpf-next 2/2] tools/bpftool: fix bpftool build with bintutils >= 2.9 Date: Wed, 27 Dec 2017 19:16:29 +0000 Message-ID: <20171227191629.4920-2-guro@fb.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171227191629.4920-1-guro@fb.com> References: <20171227191629.4920-1-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [2620:10d:c092:180::1:bb81] X-ClientProxiedBy: AM5PR0202CA0015.eurprd02.prod.outlook.com (2603:10a6:203:69::25) To BL2PR15MB1075.namprd15.prod.outlook.com (2603:10b6:201:17::9) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 88467ef5-f0ad-42c8-5c9b-08d54d5e675e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060);SRVR:BL2PR15MB1075; X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1075;3:oV+apHt6rszI0TVn0kVzE4nHstMUmeEwmjgcpmJXdvLnxcF+IOw6hZHzfQaIm+Kq6vfgiT+qhBQ3gqRDZbHpuMnHoRApM+YsoCPIRUehA/+I+ZQG03qUW7yr8NxC8h2pURVRbBlw4Cr429qZdGtKT1DM0dwmz8yv/2yM3vL5I3MkP0oz4K+eMlROxuWvqSJ3BxQrrOWcaYaC5tAGTomYe1ENNozTecPteVFEref+oCk7dAfPREBzUt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RcfI1Hv8BokfHuDR3AwZr+MDC7vvtFcSeNhqD+aIqqzGdl6yl7jl+rzp7bQWYkiIn1Qt3KEKrF9sA0IVXE0JcBwo4D1bfIZWCkjMd;4:wJWjz60TwMD8DTKs8AHYvyMD6vmlb6dYBVZ4TzxlDnmQDOBNTT0J5xsKuQ/aPrSWjoSrluKYMILS3BIBkx+829nEh8gxU88k8kdiokK+qC3Jw78N6LCHmDVjP/rTE6B4puXT46d+VDKAWKVZYIvvMTEIo7RKoiYVCZOySEnFRsRFEVtIlx4dnAQ9jL7uenJ9bf6tR9M9C3hHhdhF21475COOrUgmpXSJY8iAti3KJF5NCn9+2ez8HAGIDGfJaKtDK/k7C3VBTlzcVmZvnf5wB7COhY+PF1htjcCWFNhCEEQ4SYAEI3r7yzzTizD02Kc7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231023)(11241501184)(944501075)(3002001)(10201501046)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:BL2PR15MB1075;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BL2PR15MB1075; X-Forefront-PRVS: 0534947130 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(366004)(376002)(39860400002)(346002)(39380400002)(189003)(199004)(106356001)(575784001)(36756003)(1076002)(50466002)(48376002)(6116002)(2906002)(25786009)(6512007)(478600001)(86362001)(97736004)(53936002)(4326008)(6486002)(6506007)(386003)(39060400002)(52396003)(52116002)(51416003)(76176011)(53416004)(7736002)(305945005)(6916009)(6666003)(2950100002)(69596002)(5660300001)(2351001)(81156014)(2361001)(105586002)(8676002)(16586007)(8936002)(81166006)(54906003)(68736007)(47776003)(50226002)(316002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR15MB1075;H:castle.thefacebook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2PR15MB1075;23:4bk2w0GXHSap1Nd62z7axGeH6QP9t8PeY9O6AC25l?= =?us-ascii?Q?xzAO7W0EDQlccxXpL6kYvgsrm+56bHurXUGeVYJ8m/1m6h9IyW1FxFiKA3j0?= =?us-ascii?Q?/QVkbC4vPUMvF1L7BZWa94IYbrc/GY1f9ojOU2ZyzgGLBmO+gFHg2TUG5W0B?= =?us-ascii?Q?4yOpbD2sjoTfZHnxqmp23dTEa0ajUZm0WKyxOcc2zAys6KeXMMsPFV/+9wyB?= =?us-ascii?Q?H1cz0RgaSMSD+rH9UIlWAJ9SeX1XkzBEBz090Vx/Qybxvqq6c8RAHWZGA+t7?= =?us-ascii?Q?5j1tOlyesS+aU+N/U9Uca9B6STbjd+xuBQaGkOAx37nMAaSUOSJDEIPSgS7U?= =?us-ascii?Q?zY60AVbiLDns2wNCcgmt2v7KI7t0SXaveW2w/plKRgr0r0b+x7m4v6kNf06h?= =?us-ascii?Q?Neh8S9HVQFHB6zGvBSMT/dbm82IVzmDtj8ji9u5euwkM6e4eNpNh6NevyVZX?= =?us-ascii?Q?tsX5phIoXDxSIo14R2XgLvewNOv4DCB1qG9gD1f/hyP0JEwImwOxi8aPUFYP?= =?us-ascii?Q?X0nTpfUMhlr/OUz/ktisZ3iOodA0xT2F1OSZ7cD0N7kdE5cj9/Zwa54ZjjaQ?= =?us-ascii?Q?RooSHubTV8q03nMKa+OT+0YMbND4yK4NAvZeL7GGMV4rJ1POriI9/tBmldRJ?= =?us-ascii?Q?FITLOUE3Dzt0Fean3qnmFvdgjWwUS1Xt0gxvcTa2Ln3gVuOOsiWxz6DykD1M?= =?us-ascii?Q?9gTnO6S8xFQB8Srty7SYPbgCibY6d64pBet+5wM+zEZrfdhhzZx/X4UOp+ev?= =?us-ascii?Q?8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q+N7CsVevIEaq53x4jQF5RZtIU7c5q1vt5IRzj+P8PWWiHBCrssPxkySCR0ycF6hb86OPZ7EhvGo80AosmVTiuDiI2OGUltqk5/oINIA=;24:HAdeBGMjuw7Va0iW7d4te6kCmgwFL9Z7Ob2cIYRt2wtVGjmlbkS3xTWj3WnPL8o4lYABE5+P+HzYsBpg0wxUYVo799ISqGn4or8cFPT6wag=;7:6ww3Q4OMiGeNtdw9NnXY9CuevIlr+dUqb+FPfVaf57D7RAqLhCib5bIHUDgHA2H3TiOrXH5KwO2otOc8OPDvfNAdmQ98O5L+HVkopBgXttuX8PbDTes89oshYvgv9uL9jTHJsuXkZ5eEtSvTBqaPNuwtOK9Ne7pFT/OglM386dBGKUj6PZBHYbPhyGfnNKSIXQj/N34rUE0r4kTiXL9gRZyBI1pP1bS+wMWs/9J20fqbP/lW0jN4AQChCI3e9QuD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB1075;20:cgl8rIIdd8aGB5T7xNaGKBGmg/6BUm8L7rNFELDmdTfAnC0UvX8BZIEmtao8kC1AglKu/WyuxHYwMEBcRA2OiYV4DQBN7Vu6N5qXv5bZrU7Gi0s+Zb5ub4QMqHmnwkaADPOSwoVJXeMcrFfChVFIX0U5pbsUAnGeTzMRX7AG6cw= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Dec 2017 19:16:58.7576 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88467ef5-f0ad-42c8-5c9b-08d54d5e675e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR15MB1075 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-27_12:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5508 Lines: 181 Bpftool build is broken with binutils version 2.29 and later. The cause is commit 003ca0fd2286 ("Refactor disassembler selection") in the binutils repo, which changed the disassembler() function signature. Fix this by adding a new "feature" to the tools/build/features infrastructure and make it responsible for decision which disassembler() function signature to use. Signed-off-by: Roman Gushchin Cc: Jakub Kicinski Cc: Alexei Starovoitov Cc: Daniel Borkmann --- tools/bpf/Makefile | 29 +++++++++++++++++++++++ tools/bpf/bpf_jit_disasm.c | 7 ++++++ tools/bpf/bpftool/Makefile | 24 +++++++++++++++++++ tools/bpf/bpftool/jit_disasm.c | 7 ++++++ tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-disassembler-four-args.c | 15 ++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 tools/build/feature/test-disassembler-four-args.c diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile index 07a6697466ef..c8ec0ae16bf0 100644 --- a/tools/bpf/Makefile +++ b/tools/bpf/Makefile @@ -9,6 +9,35 @@ MAKE = make CFLAGS += -Wall -O2 CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include +ifeq ($(srctree),) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +endif + +FEATURE_USER = .bpf +FEATURE_TESTS = libbfd disassembler-four-args +FEATURE_DISPLAY = libbfd disassembler-four-args + +check_feat := 1 +NON_CHECK_FEAT_TARGETS := clean bpftool_clean +ifdef MAKECMDGOALS +ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) + check_feat := 0 +endif +endif + +ifeq ($(check_feat),1) +ifeq ($(FEATURES_DUMP),) +include $(srctree)/tools/build/Makefile.feature +else +include $(FEATURES_DUMP) +endif +endif + +ifeq ($(feature-disassembler-four-args), 1) +CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE +endif + %.yacc.c: %.y $(YACC) -o $@ -d $< diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c index 75bf526a0168..30044bc4f389 100644 --- a/tools/bpf/bpf_jit_disasm.c +++ b/tools/bpf/bpf_jit_disasm.c @@ -72,7 +72,14 @@ static void get_asm_insns(uint8_t *image, size_t len, int opcodes) disassemble_init_for_target(&info); +#ifdef DISASM_FOUR_ARGS_SIGNATURE + disassemble = disassembler(info.arch, + bfd_big_endian(bfdf), + info.mach, + bfdf); +#else disassemble = disassembler(bfdf); +#endif assert(disassemble); do { diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index f8f31a8d9269..2237bc43f71c 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -46,6 +46,30 @@ LIBS = -lelf -lbfd -lopcodes $(LIBBPF) INSTALL ?= install RM ?= rm -f +FEATURE_USER = .bpftool +FEATURE_TESTS = libbfd disassembler-four-args +FEATURE_DISPLAY = libbfd disassembler-four-args + +check_feat := 1 +NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall +ifdef MAKECMDGOALS +ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) + check_feat := 0 +endif +endif + +ifeq ($(check_feat),1) +ifeq ($(FEATURES_DUMP),) +include $(srctree)/tools/build/Makefile.feature +else +include $(FEATURES_DUMP) +endif +endif + +ifeq ($(feature-disassembler-four-args), 1) +CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE +endif + include $(wildcard *.d) all: $(OUTPUT)bpftool diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c index 1551d3918d4c..57d32e8a1391 100644 --- a/tools/bpf/bpftool/jit_disasm.c +++ b/tools/bpf/bpftool/jit_disasm.c @@ -107,7 +107,14 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes) disassemble_init_for_target(&info); +#ifdef DISASM_FOUR_ARGS_SIGNATURE + disassemble = disassembler(info.arch, + bfd_big_endian(bfdf), + info.mach, + bfdf); +#else disassemble = disassembler(bfdf); +#endif assert(disassemble); if (json_output) diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 96982640fbf8..17f2c73fff8b 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -13,6 +13,7 @@ FILES= \ test-hello.bin \ test-libaudit.bin \ test-libbfd.bin \ + test-disassembler-four-args.bin \ test-liberty.bin \ test-liberty-z.bin \ test-cplus-demangle.bin \ @@ -188,6 +189,9 @@ $(OUTPUT)test-libpython-version.bin: $(OUTPUT)test-libbfd.bin: $(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl +$(OUTPUT)test-disassembler-four-args.bin: + $(BUILD) -lbfd -lopcodes + $(OUTPUT)test-liberty.bin: $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty diff --git a/tools/build/feature/test-disassembler-four-args.c b/tools/build/feature/test-disassembler-four-args.c new file mode 100644 index 000000000000..45ce65cfddf0 --- /dev/null +++ b/tools/build/feature/test-disassembler-four-args.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +int main(void) +{ + bfd *abfd = bfd_openr(NULL, NULL); + + disassembler(bfd_get_arch(abfd), + bfd_big_endian(abfd), + bfd_get_mach(abfd), + abfd); + + return 0; +} -- 2.14.3