From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gM8ZHipoZGdA/yIAWB0awg (envelope-from ) for ; Thu, 19 Dec 2024 13:38:34 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=njSNejPQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 77EF31E097; Thu, 19 Dec 2024 13:38:34 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 50E3F1E091 for ; Thu, 19 Dec 2024 13:38:33 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2AC2385840D for ; Thu, 19 Dec 2024 18:38:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2AC2385840D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=njSNejPQ Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id C01D43858D21 for ; Thu, 19 Dec 2024 18:37:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C01D43858D21 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C01D43858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::534 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734633448; cv=none; b=HB5bDN9M3oMrFtthnO/g9pXJkd64XAIwlgdnYHTdc18s9NDvuAStSzN6XQ5/5wxBGm8Xg5oqgQExwDqzWCSICAaKn4VgcoO6CF/dnd6M2X7+MxNskUd4HsvW6itR3jeFJbtjUCFGcKFboxoZd/1u+lsgOVkByQ+HWM57KH7pScI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734633448; c=relaxed/simple; bh=Z2plWmec5Gqs7Huq6MQ5w27vpb3pRACNTQAQqPC+aHY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=E2WxIsKrlkqTO1RRSaYlfa222vCrWhx6XAFL5xp1mcH1MB6d1erOC1kBKiYSkyfAkOOh+tpiR87ppfWJDGiD3tIySzWRQF3gnHTAZFYRNFa5EgD7OBzU18HJxJclNYeRe30Fn0urWv5OGPzKE8TVkCMIuOEjQibzjg2qyGyILMA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C01D43858D21 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-7fd2ff40782so936207a12.2 for ; Thu, 19 Dec 2024 10:37:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1734633447; x=1735238247; darn=sourceware.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=APRTRxLKQvrrn1XcRtvSBWSWDmRZyYhzWkBrE5tPnro=; b=njSNejPQbjTlr/rTzzGzmGjNRUQzZLi7nYvE5edGB2YSdYThd8MOlZkKcNpzKhI1Fd yie4dnidm87oQBrhankWEl+8tvsT71UodbuTVk4M7DPNHH45VEr9TJJB6JmEJyBXD2YP XfHV5KzZ2YIaGnWr35WUEbQ/ougjXxo7E6kx4EBGLt2tHRPK+w/Mz1T5q4WOsK1HzgX2 5mCUeZpZpoDIAafkc9q69jiAozKeT4GEwgNU+FBGCssRaCtme8gmE1RZWjedW9u+2725 kRqK/sF+E8MTgk3DTMsqrF3Mq2NVLqZg74/07hL518Bu48JME8CmyRAthdXqUogfWh67 X3iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734633447; x=1735238247; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=APRTRxLKQvrrn1XcRtvSBWSWDmRZyYhzWkBrE5tPnro=; b=kSQ+eq1bdLr8HVBmGvH6ylsJin4MqzDwFdLEC8sXFzj6rynQyd7YV9GKqRb9L3IDBK mie4UEX6BP8hJCHWBsf1mvm/Vl9U0PEXhNrd4+RYFkUV2L8hxhwy1D8shSRIUbJ80s4l NxDiEO2JYYa5QjCqYkfLkQCpoN2BztdYn8uewIqDt4PVaxwdrUab4rzbTl/lZHfRhCoF KEBYsDCMekSVOSjn9bsoC6B+66Qw5f79zDc4/q/ZI8apDfsUuJmhwsokGJDujBINmzpp eBTnruvsJ8Um61Z3Zp0kJJS0PiP0plmoBGoooFEm97f+FsdgMFiOcrajARwtdTTkHTqc fzWQ== X-Forwarded-Encrypted: i=1; AJvYcCVEtMR4nxO3s6BndeHAvasC46SaY+O5rqMEY5ioCp2Ab2ZvgSErkrdIpDP+mcjd48LuwEeo9LWSkzJ9Jg==@sourceware.org X-Gm-Message-State: AOJu0Yx1+t3PYkNDvHGSd55LF3Nqu/IKfvOy4Ll0/mFArLJx2+1aOFOz LlH8YWjELC08ud8msbkVcWRQAcEXfOVZDNBuGbgLCcU+2WLG5V3sTaqMn5TWqFM= X-Gm-Gg: ASbGncuk3zR5/uilgosL7xBYHxc8IgaQeT5VECFQkY+ss3uVnCEqikdhYPzvIMbRWOL uOqOCec+iO1Vxv/3UbEoCElVOnR/fC4DhL3w59xzma4uumQ437y1kpkwfnAUocCW7DPKd+ZdRV0 SjztQd+tB6KGTh8K4DRBvOpBRrbOuAXsEdYXluF67YGqwO9ic99lZ+AQ3xiOfC/lXdm9q91iDji IHofy2Ex1qV2/QyDoV0gMrRNMfYg3eHgG8YTvsI7RX8/DTANceg X-Google-Smtp-Source: AGHT+IEnwe4C8AlufT2czbYnZonnjHzh+rBfOJ+R0odCGc8MsaYfMVvH+IO2o6AeGcxqJuGl3nuiaQ== X-Received: by 2002:a05:6a21:7896:b0:1e0:cf39:846a with SMTP id adf61e73a8af0-1e5e07e79aamr176832637.29.1734633447557; Thu, 19 Dec 2024 10:37:27 -0800 (PST) Received: from ghost ([2601:647:6700:64d0:1e6a:6188:cfff:248e]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8164c7sm1636920b3a.4.2024.12.19.10.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 10:37:26 -0800 (PST) Date: Thu, 19 Dec 2024 10:37:24 -0800 From: Charlie Jenkins To: Nelson Chu Cc: jiawei , gdb-patches , Binutils , Jan Beulich , Andrew Burgess Subject: Re: [PATCH v2] RISC-V: Fix disassembly of partial instructions Message-ID: References: <20241216-fix_objdump_partial_insn-v2-1-8de88a115dbc@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On Fri, Dec 20, 2024 at 01:37:37AM +0800, Nelson Chu wrote: > Some minor GNU coding styles as follows. Also cc Jan and Andrew, hope they > still have time in their busy schedules can help to see if there are some > side effects. > > Thanks > Nelson > > On Tue, Dec 17, 2024 at 6:23 AM Charlie Jenkins > wrote: > > > As of commit e43d8768d909 ("RISC-V: Fix disassemble fetch fail return > > value.") partial instructions are no longer disassembled. While that > > commit fixed the behavior of print_insn_riscv() returning the arbitrary > > status value upon failure, it caused the behavior of dumping > > instructions to change. Allow partial instructions to be disassembled > > once again and only return -1 if no part of the instruction was able to > > be disassembled. > > > > Fixes: e43d8768d909 ("RISC-V: Fix disassemble fetch fail return value.") > > Signed-off-by: Charlie Jenkins > > --- > > When testing linux perf, I noticed that this behavior of objdump has > > changed. Before this patch and running `perf test` on riscv the > > following test fails due to objdump not returning all of the expected > > bytes. > > > > Bytes read differ from those read by objdump > > buf1 (dso): > > 0x97 0xf7 0x11 0x00 0x93 0x87 0xc7 0x7c 0x22 0x85 0x7c 0xec 0xef 0x50 0x80 > > 0x12 > > 0xa6 0x85 0xce 0x86 0x4a 0x86 0x22 0x85 0xef 0x50 0x40 0x40 0xa2 0x84 0x1d > > 0xc9 > > 0x7c 0x58 0x85 0x8b 0x85 0xc3 0x1c 0x40 0xa1 0x8b 0x89 0xcf 0x83 0x27 0x04 > > 0x0c > > 0x63 0x51 0xf0 0x04 0x97 0xf7 0x11 0x00 0x93 0x87 0x07 0x45 0xbe 0x86 0x58 > > 0x70 > > 0x74 0xec 0x7c 0xf3 0xa2 0x70 0x02 0x74 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 > > 0x64 > > 0x45 0x61 0x82 0x80 0x22 0x85 0xef 0x50 0x50 0x52 0x22 0x85 0xef 0x00 0xb1 > > 0x39 > > 0xa2 0x70 0x02 0x74 0x81 0x44 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 0x64 0x45 > > 0x61 > > 0x82 0x80 0x97 0x06 0x12 0x00 0x93 0x86 0xa6 0x8a 0x97 0xf7 0x11 0x00 0x93 > > 0x87 > > > > buf2 (objdump): > > 0x97 0xf7 0x11 0x00 0x93 0x87 0xc7 0x7c 0x22 0x85 0x7c 0xec 0xef 0x50 0x80 > > 0x12 > > 0xa6 0x85 0xce 0x86 0x4a 0x86 0x22 0x85 0xef 0x50 0x40 0x40 0xa2 0x84 0x1d > > 0xc9 > > 0x7c 0x58 0x85 0x8b 0x85 0xc3 0x1c 0x40 0xa1 0x8b 0x89 0xcf 0x83 0x27 0x04 > > 0x0c > > 0x63 0x51 0xf0 0x04 0x97 0xf7 0x11 0x00 0x93 0x87 0x07 0x45 0xbe 0x86 0x58 > > 0x70 > > 0x74 0xec 0x7c 0xf3 0xa2 0x70 0x02 0x74 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 > > 0x64 > > 0x45 0x61 0x82 0x80 0x22 0x85 0xef 0x50 0x50 0x52 0x22 0x85 0xef 0x00 0xb1 > > 0x39 > > 0xa2 0x70 0x02 0x74 0x81 0x44 0x42 0x69 0xa2 0x69 0x26 0x85 0xe2 0x64 0x45 > > 0x61 > > 0x82 0x80 0x97 0x06 0x12 0x00 0x93 0x86 0xa6 0x8a 0x97 0xf7 0x11 0x00 0xad > > 0x00 > > > > ---- end(-1) ---- > > 24: Object code reading : FAILED! > > > > After this patch, this test case no longer fails, as objdump returns the > > expected values. > > --- > > Changes in v2: > > - Fix comment spacing (Jiawei) > > - Link to v1: > > https://lore.kernel.org/r/20241213-fix_objdump_partial_insn-v1-1-7a4963e655d5@rivosinc.com > > --- > > opcodes/riscv-dis.c | 51 > > ++++++++++++++++++++++++++++++++++++++++++++++----- > > 1 file changed, 46 insertions(+), 5 deletions(-) > > > > diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c > > index > > 101380f93aafbd528ba0020371f0c43a85f41bd1..492135d4642a29d86757ba0d2ec8261dab66275f > > 100644 > > --- a/opcodes/riscv-dis.c > > +++ b/opcodes/riscv-dis.c > > @@ -1308,6 +1308,14 @@ riscv_disassemble_data (bfd_vma memaddr > > ATTRIBUTE_UNUSED, > > (*info->fprintf_styled_func) > > (info->stream, dis_style_immediate, "0x%04x", (unsigned) data); > > break; > > + case 3: > > + info->bytes_per_line = 7; > > + (*info->fprintf_styled_func) > > + (info->stream, dis_style_assembler_directive, ".word"); > > + (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t"); > > + (*info->fprintf_styled_func) > > + (info->stream, dis_style_immediate, "0x%06x", (unsigned) data); > > + break; > > case 4: > > info->bytes_per_line = 8; > > (*info->fprintf_styled_func) > > @@ -1360,13 +1368,28 @@ riscv_init_disasm_info (struct disassemble_info > > *info) > > return true; > > } > > > > +/* Fetch an instruction. If only a partial instruction is able to be > > fetched, > > + return the number of accessible bytes. */ > > + > > +static bfd_vma > > +fetch_insn (bfd_vma memaddr, bfd_byte *packet, bfd_vma dump_size, struct > > disassemble_info *info, volatile int *status) > > > > over 80 char per line. > > > > +{ > > + do > > + { > > + *status = (*info->read_memory_func) (memaddr, packet, dump_size, > > info); > > + } > > + while(*status != 0 && dump_size-- > 1); > > > > Need space between while and left '(' > > > > + > > + return dump_size; > > +} > > + > > int > > print_insn_riscv (bfd_vma memaddr, struct disassemble_info *info) > > { > > bfd_byte packet[RISCV_MAX_INSN_LEN]; > > insn_t insn = 0; > > - bfd_vma dump_size; > > - int status; > > + volatile bfd_vma dump_size, bytes_fetched; > > + volatile int status; > > > > Not sure if it needed to be volatile or not. Oh, I didn't mean to commit that... > > > > enum riscv_seg_mstate mstate; > > int (*riscv_disassembler) (bfd_vma, insn_t, const bfd_byte *, > > struct disassemble_info *); > > @@ -1398,24 +1421,42 @@ print_insn_riscv (bfd_vma memaddr, struct > > disassemble_info *info) > > else > > { > > /* Get the first 2-bytes to check the lenghth of instruction. */ > > - status = (*info->read_memory_func) (memaddr, packet, 2, info); > > + bytes_fetched = fetch_insn(memaddr, packet, 2, info, &status); > > > > Need space after the function fetch_insn. > > > > if (status != 0) > > { > > (*info->memory_error_func) (status, memaddr, info); > > return -1; > > } > > + else if (bytes_fetched != 2) > > + { > > + /* Only the first byte was able to be read. Dump the partial > > + instruction. */ > > > > Two spaces after '.' > > > > + dump_size = bytes_fetched; > > + info->bytes_per_chunk = dump_size; > > + riscv_disassembler = riscv_disassemble_data; > > + goto print; > > > > Indent, seems to miss a space. > > > > + } > > insn = (insn_t) bfd_getl16 (packet); > > dump_size = riscv_insn_length (insn); > > riscv_disassembler = riscv_disassemble_insn; > > } > > > > - /* Fetch the instruction to dump. */ > > - status = (*info->read_memory_func) (memaddr, packet, dump_size, info); > > + bytes_fetched = fetch_insn(memaddr, packet, dump_size, info, &status); > > > > Need space after the function fetch_insn. > > > > + > > if (status != 0) > > { > > (*info->memory_error_func) (status, memaddr, info); > > return -1; > > } > > + else if (bytes_fetched != dump_size) > > + { > > + dump_size = bytes_fetched; > > + info->bytes_per_chunk = dump_size; > > + riscv_disassembler = riscv_disassemble_data; > > + } > > + > > +print: > > > > Indent, one space needed for the label. > Thanks for the formatting info, I will make those changes and send another version. - Charlie > > > + > > insn = (insn_t) bfd_get_bits (packet, dump_size * 8, false); > > > > return (*riscv_disassembler) (memaddr, insn, packet, info); > > > > --- > > base-commit: 978324718990b6b371d4eeeba02cfe13a0ebf120 > > change-id: 20241121-fix_objdump_partial_insn-94e236f3db38 > > -- > > - Charlie > > > >