From patchwork Sun Jul 30 20:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 128281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp1657414vqg; Sun, 30 Jul 2023 13:47:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlFkDg8AwFk51USHJG0WyKSPuYeRGv9WSpeiesrD2TrbS3l1eBoMAoQn8s30EfKcvmTgTZdX X-Received: by 2002:a2e:988d:0:b0:2b6:ded8:6fc1 with SMTP id b13-20020a2e988d000000b002b6ded86fc1mr4622134ljj.25.1690750052632; Sun, 30 Jul 2023 13:47:32 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fi1-20020a170906da0100b00987ae307f0dsi2223223ejb.587.2023.07.30.13.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 13:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=LzWsK5pT; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FC5F385840B for ; Sun, 30 Jul 2023 20:47:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FC5F385840B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690750051; bh=jBwN+2z9J0TRgUyPXJ3XTkN8fFOt4Tu6/aFRH6mNbLI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LzWsK5pTlPHaIm3XhCFFeSZTnpUsGbni6nOFXlArojDoTnmUulnY+7vfNSvAhq836 cvtra0gpv831ld7uwjEWemJjKKBvYWYLxGH9kYxyAZpmHtMwScGvMcJTqCpZ1x9MIg WgRSPkaisPptXeaxowaA70cJfREcg+Pxn+sVK2WQ= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 204443858D35 for ; Sun, 30 Jul 2023 20:47:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 204443858D35 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36UKANcA009109 for ; Sun, 30 Jul 2023 20:47:20 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s4ttd1dqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 30 Jul 2023 20:47:20 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 36UJjOaT033592 for ; Sun, 30 Jul 2023 20:47:19 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3s4s73stk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 30 Jul 2023 20:47:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XOLS4FhulXaRxocwKCt6Yo4b37C3/Uw94xeuK/2fV3PvsjnyVkgouzTwBnaO7SGkXECxf2NaDKf4EskQjXGRxK/UvP4Xvg33osXExZcxgHVHdiikrNVtwMPSa1+VHI12nDeBhPKr+GsQj/4SeWPGCr5l88mOA/oFanU0jmB6sRTfOeVgRMeL3R+8g9DZq3jwXhAoA99dkV2ObiwXSzvdHpnQA2L3gN1oqTyf4CeIdKqO2bcgTuxQQ3cHY5lSLRHRUvNHZ8xjgCgBOty5SlcIR9HBjaQ1NEx7S2fDGxN9POrrbeSaZnI9DEGIQm7joUQ2gCwJAIecGrMsT10xZfG+tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jBwN+2z9J0TRgUyPXJ3XTkN8fFOt4Tu6/aFRH6mNbLI=; b=Jq03EqUPct1042Z7UsOO2bk92OQmPYbs/OSGdfn0SiNon4QMT9sbEwv6SyBCKSobDLpyF4ShFC3aRBwx84ySQBfx7KFMJlEN0Hocw/D5s7Sre6951jK7+SJOWo7e3+NZxuY1nB0kvLjSNza8jinOECKU7hb7w79P9iVHRkLW4R8a+EuYRh+e8OnPJ3gKiy6lerBUCBl5+19WFlBNYhDQZDR23qzkIBK+4gpJFaQgdjOfBtWlB1GKOlyPUmc6PLCno0CEkzT8mxmLSjnxW5XdRfgRG3LyLrIn1XvlHmlZaQMIkParwUxdlMaPKuat2nxoyRP66Tm427TH5u/nh0WhOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from DM6PR10MB2890.namprd10.prod.outlook.com (2603:10b6:5:71::31) by PH0PR10MB7027.namprd10.prod.outlook.com (2603:10b6:510:280::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.39; Sun, 30 Jul 2023 20:47:16 +0000 Received: from DM6PR10MB2890.namprd10.prod.outlook.com ([fe80::c495:8d34:80c7:d66f]) by DM6PR10MB2890.namprd10.prod.outlook.com ([fe80::c495:8d34:80c7:d66f%6]) with mapi id 15.20.6631.026; Sun, 30 Jul 2023 20:47:16 +0000 To: binutils@sourceware.org Subject: [COMMITTED] bpf: include, bfd, opcodes: add EF_BPF_CPUVER ELF header flags Date: Sun, 30 Jul 2023 22:47:12 +0200 Message-Id: <20230730204712.10563-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: FR2P281CA0073.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9a::15) To DM6PR10MB2890.namprd10.prod.outlook.com (2603:10b6:5:71::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB2890:EE_|PH0PR10MB7027:EE_ X-MS-Office365-Filtering-Correlation-Id: 454eb099-118f-4c2b-7d01-08db913e28c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HR5FMWgmj7DZ8SU75QFwq0GE05NP/xKFEKE2mgnrx2q5fINWJtrZa9RImkX3UhavjnzogsIfEmbgLl8N/8cmEbIOcCPBnZ0CvLI/M5S62z5U+W5QwNbCCSXdATR+yykAHGqAoufirG5jppixiF4xPKV6KnUMerTqYtjrpS0ytx5xzwIrggIjqmEgpdCJyFCUWjk9WCDFoRAVFn1q9tPRdFbULPr1uLNOQBGdz8ukEOM8UhNMVL2XRqdTkVnQwiaKTcN0VspFYGGvzWEB5+BWkC09OAV9nop3cvjtcmj3qTEKsq9N2Cr+y1+1qqjhWohQKIxjOyNzpAr0SexpslUwut6/XpfBUQcs4viiBlpU4JMu1/+Iid3bH5T0fgpnNxUdScxgYQnDL4ciFTwYfJf3EjZb7SEyqK/sm2YHE85M62NYSSDjOQewwIz4+E9YWFslvUr5ZgXL/zqFu2+cPhnBM3e1iftmTSUFrl3quFpOxRfYbAfIitObWozkMzjd9LZXMp6TFLAM/aYBc2USD3xCz/9nGPIPsI2/rEmoeTNnfSEuINSLVXDP0uZ6BSGci3JUoqGRLI29CX9HvUThhktyao2mTErtmVxRUsGGQhmt8PA= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB2890.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(366004)(39860400002)(376002)(346002)(396003)(136003)(451199021)(6512007)(6486002)(36756003)(2616005)(6506007)(1076003)(26005)(83380400001)(186003)(66946007)(66556008)(41300700001)(86362001)(66476007)(316002)(5660300002)(6916009)(8936002)(8676002)(38100700002)(2906002)(6666004)(478600001)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F+L265JyM8jEemhkqKyRNWaGSpwNuF7Zj2h4V8QUE6lVvaEchnHfJGl53yFE4f7km0fmMnYnntvxnKWet6JX1BB83cWhhfuCJqmaco98n+gya4Ppcu5yGd79v08jJnl2ik7LP1t8WzevwedlKSQD6R8fKWdk6or54WSfoQGmaJXramL+fFBxFxfJ/TkDEuWT4+5Qd8qXFumv9sWQINtoxA6RDJomUpId1eVuKh6IdIP3exKN6qMKP2fbAyCi7k+qZ20QCZVtljz7dh5LiTXlC/dL7bgfydA6bm4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AjlWSgiyNDdRHh1Z07jezoNnixoiKuzecUoGCLhp X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 454eb099-118f-4c2b-7d01-08db913e28c0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB2890.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2023 20:47:16.2393 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: N9FqRKH53LbAkDgF8gJpAHlGvkjAwmXn5n2pBZGsBTZKfHO30G2OvdfShCFaW2Vx8U0Upjhcp2AfGU1cqJlPcLtJcHz22lp0iRssozA+/B0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB7027 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-27_10,2023-07-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307300194 X-Proofpoint-GUID: JKSLBARhwdWp6NVp1WvUL5d-tbtjeuji X-Proofpoint-ORIG-GUID: JKSLBARhwdWp6NVp1WvUL5d-tbtjeuji X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Jose E. Marchesi via Binutils" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772879927071904267 X-GMAIL-MSGID: 1772879927071904267 This patch adds support for EF_BPF_CPUVER bits in the ELF machine-dependent header flags. These bits encode the BPF CPU version for which the object file has been compiled for. The BPF assembler is updated so it annotates the object files it generates with these bits. The BPF disassembler is updated so it honors EF_BPF_CPUVER to use the appropriate ISA version if the user didn't specify an explicit ISA version in the command line. Note that a value of zero in EF_BPF_CPUVER is interpreted by the disassembler as "use the later supported version" (the BPF CPU versions start with v1.) The readelf utility is updated to pretty print EF_BPF_CPUVER when it prints out the ELF header: $ readelf -h a.out ELF Header: ... Flags: 0x4, CPU Version: 4 Tested in bpf-unknown-none. include/ChangeLog: 2023-07-30 Jose E. Marchesi * elf/bpf.h (EF_BPF_CPUVER): Define. * opcode/bpf.h (BPF_XBPF): Change from 0xf to 0xff so it fits in EF_BPF_CPUVER. binutils/ChangeLog: 2023-07-30 Jose E. Marchesi * readelf.c (get_machine_flags): Recognize and pretty print BPF machine flags. opcodes/ChangeLog: 2023-07-30 Jose E. Marchesi * bpf-dis.c: Initialize asm_bpf_version to -1. (print_insn_bpf): Set BPF ISA version from the cpu version ELF header flags if no explicit version set in the command line. * disassemble.c (disassemble_init_for_target): Remove unused code. gas/ChangeLog: 2023-07-30 Jose E. Marchesi * config/tc-bpf.h (elf_tc_final_processing): Define. * config/tc-bpf.c (bpf_elf_final_processing): New function. --- binutils/ChangeLog | 5 +++++ binutils/readelf.c | 6 ++++++ gas/ChangeLog | 5 +++++ gas/config/tc-bpf.c | 9 +++++++++ gas/config/tc-bpf.h | 3 +++ gas/config/tc-sparc.c | 1 + include/ChangeLog | 6 ++++++ include/elf/bpf.h | 5 +++++ include/opcode/bpf.h | 2 +- opcodes/ChangeLog | 7 +++++++ opcodes/bpf-dis.c | 30 +++++++++++++++++++++++++++++- opcodes/disassemble.c | 20 -------------------- 12 files changed, 77 insertions(+), 22 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index cfd4d1ad45e..65cff807bec 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,8 @@ +2023-07-30 Jose E. Marchesi + + * readelf.c (get_machine_flags): Recognize and pretty print BPF + machine flags. + 2023-07-24 Johannes Schauer Marin Rodrigues * doc/binutils.texi (objcopy): Document change in behaviour of diff --git a/binutils/readelf.c b/binutils/readelf.c index bb488ef2a5e..4ecff4c3933 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -168,6 +168,7 @@ #include "elf/xtensa.h" #include "elf/z80.h" #include "elf/loongarch.h" +#include "elf/bpf.h" #include "getopt.h" #include "libiberty.h" @@ -4191,6 +4192,11 @@ get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) strcat (buf, ", no delay"); break; + case EM_BPF: + sprintf (buf + strlen (buf), ", CPU Version: %u", + e_flags & EF_BPF_CPUVER); + break; + case EM_SPARCV9: if (e_flags & EF_SPARC_32PLUS) strcat (buf, ", v8+"); diff --git a/gas/ChangeLog b/gas/ChangeLog index ab139a9257b..26d7dc1623b 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,8 @@ +2023-07-30 Jose E. Marchesi + + * config/tc-bpf.h (elf_tc_final_processing): Define. + * config/tc-bpf.c (bpf_elf_final_processing): New function. + 2023-07-30 Jose E. Marchesi * config/tc-bpf.c (signed_overflow): Copy function from diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c index 7e1bd5d40b8..b4566d89ddf 100644 --- a/gas/config/tc-bpf.c +++ b/gas/config/tc-bpf.c @@ -1679,3 +1679,12 @@ bpf_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char *str ATTRIBUTE_UNUSED) return 0; } + +/* Some special processing for a BPF ELF file. */ + +void +bpf_elf_final_processing (void) +{ + /* Annotate the BPF ISA version in the ELF flag bits. */ + elf_elfheader (stdoutput)->e_flags |= (isa_spec & EF_BPF_CPUVER); +} diff --git a/gas/config/tc-bpf.h b/gas/config/tc-bpf.h index d57a66fe460..9fb71eddd14 100644 --- a/gas/config/tc-bpf.h +++ b/gas/config/tc-bpf.h @@ -53,3 +53,6 @@ #define TC_EQUAL_IN_INSN(c, s) bpf_tc_equal_in_insn ((c), (s)) extern bool bpf_tc_equal_in_insn (int, char *); + +#define elf_tc_final_processing bpf_elf_final_processing +extern void bpf_elf_final_processing (void); diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c index eada5e5a0da..c273bd75c08 100644 --- a/gas/config/tc-sparc.c +++ b/gas/config/tc-sparc.c @@ -4992,3 +4992,4 @@ sparc_cfi_emit_pcrel_expr (expressionS *exp, unsigned int nbytes) emit_expr_with_reloc (exp, nbytes, "disp"); sparc_no_align_cons = 0; } + diff --git a/include/ChangeLog b/include/ChangeLog index 11c1c09306b..4d407403944 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,9 @@ +2023-07-30 Jose E. Marchesi + + * elf/bpf.h (EF_BPF_CPUVER): Define. + * opcode/bpf.h (BPF_XBPF): Change from 0xf to 0xff so it fits in + EF_BPF_CPUVER. + 2023-07-24 Jose E. Marchesi * opcode/bpf.h (BPF_IMM32_BSWAP16): Define. diff --git a/include/elf/bpf.h b/include/elf/bpf.h index d0fad08c24a..e4d416290a7 100644 --- a/include/elf/bpf.h +++ b/include/elf/bpf.h @@ -37,4 +37,9 @@ START_RELOC_NUMBERS (elf_bpf_reloc_type) RELOC_NUMBER (R_BPF_GNU_64_16, 256) END_RELOC_NUMBERS (R_BPF_max) +/* Processor specific flags for the ELF header e_flags field. */ + +/* Version of the BPF ISA used in the file. */ +#define EF_BPF_CPUVER 0x0000000f + #endif /* _ELF_BPF_H */ diff --git a/include/opcode/bpf.h b/include/opcode/bpf.h index 20e323a065b..6decae4a9a3 100644 --- a/include/opcode/bpf.h +++ b/include/opcode/bpf.h @@ -44,7 +44,7 @@ typedef uint64_t bpf_insn_word; #define BPF_V2 0x2 #define BPF_V3 0x3 #define BPF_V4 0x4 -#define BPF_XBPF 0xff +#define BPF_XBPF 0xf /* Masks for the several instruction fields in a BPF instruction. These assume big-endian BPF instructions. */ diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index f611ec5bb0f..9d33da21627 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,10 @@ +2023-07-30 Jose E. Marchesi + + * bpf-dis.c: Initialize asm_bpf_version to -1. + (print_insn_bpf): Set BPF ISA version from the cpu version ELF + header flags if no explicit version set in the command line. + * disassemble.c (disassemble_init_for_target): Remove unused code. + 2023-07-26 Jose E. Marchesi * bpf-opc.c (bpf_opcodes): Fix BPF_INSN_NEGR to not use a src diff --git a/opcodes/bpf-dis.c b/opcodes/bpf-dis.c index 4fe0efc2f96..a8cb9e8e6db 100644 --- a/opcodes/bpf-dis.c +++ b/opcodes/bpf-dis.c @@ -24,6 +24,8 @@ #include "libiberty.h" #include "opintl.h" #include "opcode/bpf.h" +#include "elf-bfd.h" +#include "elf/bpf.h" #include #include @@ -42,7 +44,7 @@ enum bpf_dialect /* Global configuration for the disassembler. */ static enum bpf_dialect asm_dialect = BPF_DIALECT_NORMAL; -static int asm_bpf_version = BPF_V4; +static int asm_bpf_version = -1; static int asm_obase = 10; /* Print BPF specific command-line options. */ @@ -141,6 +143,32 @@ print_insn_bpf (bfd_vma pc, disassemble_info *info) info->disassembler_options = NULL; } + /* Determine what version of the BPF ISA to use when disassembling. + If the user didn't explicitly specify an ISA version, then derive + it from the CPU Version flag in the ELF header. A CPU version of + 0 in the header means "latest version". */ + if (asm_bpf_version == -1) + { + struct bfd *abfd = info->section->owner; + Elf_Internal_Ehdr *header = elf_elfheader (abfd); + int cpu_version = header->e_flags & EF_BPF_CPUVER; + + switch (cpu_version) + { + case 0: asm_bpf_version = BPF_V4; break; + case 1: asm_bpf_version = BPF_V1; break; + case 2: asm_bpf_version = BPF_V2; break; + case 3: asm_bpf_version = BPF_V3; break; + case 4: asm_bpf_version = BPF_V4; break; + case 0xf: asm_bpf_version = BPF_XBPF; break; + default: + /* xgettext:c-format */ + opcodes_error_handler (_("unknown BPF CPU version %u\n"), + cpu_version); + break; + } + } + /* Print eight bytes per line. */ info->bytes_per_chunk = 1; info->bytes_per_line = 8; diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c index a5cb396badb..8aac42ec96c 100644 --- a/opcodes/disassemble.c +++ b/opcodes/disassemble.c @@ -680,27 +680,7 @@ disassemble_init_for_target (struct disassemble_info * info) #endif #ifdef ARCH_bpf case bfd_arch_bpf: - /* XXX option for dialect */ info->created_styled_output = true; -#if 0 - info->endian_code = BFD_ENDIAN_LITTLE; - if (!info->private_data) - { - info->private_data = cgen_bitset_create (ISA_MAX); - if (info->endian == BFD_ENDIAN_BIG) - { - cgen_bitset_set (info->private_data, ISA_EBPFBE); - if (info->mach == bfd_mach_xbpf) - cgen_bitset_set (info->private_data, ISA_XBPFBE); - } - else - { - cgen_bitset_set (info->private_data, ISA_EBPFLE); - if (info->mach == bfd_mach_xbpf) - cgen_bitset_set (info->private_data, ISA_XBPFLE); - } - } -#endif break; #endif #ifdef ARCH_pru