From patchwork Thu Oct 1 16:17:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Remus X-Patchwork-Id: 145117 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A58CD4BAE7F1 for ; Thu, 1 Oct 2026 16:18:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A58CD4BAE7F1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Gi8t4uhQ X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id B00674BAE7EF for ; Thu, 1 Oct 2026 16:17:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B00674BAE7EF Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B00674BAE7EF Authentication-Results: sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790871463; cv=none; b=uZVeojjG4jOJS6SrqLikNA+YIeY3UQLGmBqdr0RXDQydpCMl6CzGjnYrO0CAv+j4X1CiiZCcSku+loo6of5AAnRG28eLIBRspXOtsxbPySOfrPb3sY+3rC+WKbDd6CnXpZ1GDYmRYthsdvbbufyr7jF9u+VBY+9BX5HJ2pVxIUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790871463; c=relaxed/simple; bh=PUDWMWi2SQrfB+eKQfteFQ4OARCS98VjOf43Sd/A1Q8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XdMUI0/Ge3mEpsfK9Ots4ombQ3gNxwipu13Uo/XaN2wCMQ1yRVfdoq+NB3XcoyEB6VjJ5ERqkdj7UrC337n4YJ3YDJgMND/nsKabJYZev71g4ebCTzcFplgo4RckZdyz+LEZpeXFfTIKU49nC9M+kGHemWhdmWvkpbF7F9eSQLY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Gi8t4uhQ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B00674BAE7EF Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 691G5RbC368758; Thu, 1 Oct 2026 16:17:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=rmP+I2pK8lJudeGldZkDxpZqKVXnSh4WwPWZ46G0u IU=; b=Gi8t4uhQYdRzdufNSSgW4IY48fQuxXBaH0ECewYGrcKxDciOl/7MWyoC+ 7fNXJlo93y9NKeo+nYPlvdOSIdKrxQqAnb8BnAUFKuBLZHVOrJ+OirlaCoYPd1c0 TRt0oPmccvDbPP2ItV0lJTkip8+uJDF8B6b1UKI4Gr1++c88ztoBJ/AwMBva6nwN V/+U133xbNuYKHSPcvTIltu12AksZa+VlYJ9N8BgdIDStbQvguy5FkmaR1iNcaH7 x9JO4Jrsrn9BHWRGHP6QPxAdGqKo+6N5s8Lyw87Y1tgsYz51cJThoITvOZ55GnLf 7dZaWHEx/GEVNALk/cHwlR6FAWaiQ== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gx5qrma1e-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 01 Oct 2026 16:17:38 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 691G2kkV1165749; Thu, 1 Oct 2026 16:17:37 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4h0g8e9v1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Oct 2026 16:17:37 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 691GHZVw47776110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Oct 2026 16:17:35 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C49D420043; Thu, 1 Oct 2026 16:17:35 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACA9420040; Thu, 1 Oct 2026 16:17:35 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 1 Oct 2026 16:17:35 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org, Chenghua Xu , Zhensong Liu Cc: Jens Remus Subject: [PATCH] LoongArch: Fix disassembly on big-endian hosts Date: Thu, 1 Oct 2026 18:17:26 +0200 Message-ID: <20261001161725.3812551-2-jremus@linux.ibm.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDAxMDA2NCBTYWx0ZWRfX6ro4UIdyjkcl K/kfem25+WznhvBSnJrzAXosv0jpoOKvHN4cU+hJJbbDizBGcqerfLaJuZOraRVQQ+RA3jgNNK/ hIx8SH3VaZ6/YmD06Jx5m01NQmF6yb7X23PjpiSH8zCdh7ANIKFNNPMJ9ZTk6koL+CkmCWjxu8g e+Rw/DyiORQ8KRS7xFGHC2xs5zir7SxopJmAg5RsRecB7R9h0+dwQP/8jnqZxR2jonoiJhY+Zvp AQ5A7QAMyC9vrVPgHokkai4WVvDXFY8oyO6FaTqWPKDbx+91W3q5oRnE4b0XLEqoF96UQVgGr8+ oe3OW4+JgvQ5ppmZqKJdckg8uG7H2ZNAUEl4Xr54bIL2MORyt0u6LNomIhwipyG7TIBpg2WgRfb eloNJQmbydBTUwixyxApON4R38y2uEaLfjKIk3sQGI0ifdQqQHGi5GuMSPCK5INO5oN76lz1put tIbS8VCWkHAB5YjPgOg== X-Authority-Analysis: v=2.4 cv=SPbXx+vH c=1 sm=1 tr=0 ts=6abe87a2 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=660iZSQnnn4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=aJE4ajjKCUzQh5LsJoIA:9 X-Proofpoint-ORIG-GUID: Q_leq2A_wIrfYccDiZzw2r0c_mFe6zmz X-Proofpoint-Spam-Info: AW1haW4tMjYxMDAxMDA2NCBTYWx0ZWRfXxq6HF++v8z3Z XS8FUlsd13IBjyi5Y9ceytTyBm3ddNw9y+v3bQjMaaCK5lFNy4bRKruku7h0+MrDsQhWi5aern0 1a9WeyR9VwVGxNt2nbHXtYLkqjcOxRM= X-Proofpoint-GUID: Q_leq2A_wIrfYccDiZzw2r0c_mFe6zmz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-10-01_04,2026-10-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 bulkscore=0 impostorscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2610010064 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org The LoongArch disassembler read a 4-byte instruction word directly into insn_t (= uint32_t). On a big-endian host this yields a byte-swapped instruction, causing every decode to fail. Fix this by reading into a bfd_byte buffer and then extracting the value with bfd_getl32(), which always interprets the bytes in little-endian order regardless of host endianness. This resolves all binutils, gas, and ld test failures observed in a cross-build for loongarch64-linux-gnu on s390 64-bit (s390x). opcodes/ * loongarch-dis.c (print_insn_loongarch): Read instruction word into a byte buffer and use bfd_getl32 to convert to host order. Signed-off-by: Jens Remus --- opcodes/loongarch-dis.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/opcodes/loongarch-dis.c b/opcodes/loongarch-dis.c index bdfc6a467e43..181efdfb8f46 100644 --- a/opcodes/loongarch-dis.c +++ b/opcodes/loongarch-dis.c @@ -404,6 +404,7 @@ disassemble_one (insn_t insn, struct disassemble_info *info) int print_insn_loongarch (bfd_vma memaddr, struct disassemble_info *info) { + bfd_byte buffer[4]; insn_t insn; int status; @@ -420,13 +421,15 @@ print_insn_loongarch (bfd_vma memaddr, struct disassemble_info *info) info->insn_info_valid = 1; info->target = memaddr; - if ((status = info->read_memory_func (memaddr, (bfd_byte *) &insn, - sizeof (insn), info)) != 0) + if ((status = info->read_memory_func (memaddr, buffer, sizeof (buffer), + info)) != 0) { info->memory_error_func (status, memaddr, info); return -1; /* loongarch_insn_length (0); */ } + insn = bfd_getl32 (buffer); + disassemble_one (insn, info); return loongarch_insn_length (insn);