From patchwork Mon Feb 26 19:46:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 26074 Received: (qmail 27278 invoked by alias); 26 Feb 2018 19:50:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 27249 invoked by uid 89); 26 Feb 2018 19:50:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: 9pmail.ess.barracuda.com Received: from 9pmail.ess.barracuda.com (HELO 9pmail.ess.barracuda.com) (64.235.150.225) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Feb 2018 19:49:59 +0000 Received: from MIPSMAIL01.mipstec.com (mailrelay.mips.com [12.201.5.28]) by mx29.ess.sfj.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Mon, 26 Feb 2018 19:49:56 +0000 Received: from [10.20.78.94] (10.20.78.94) by mips01.mipstec.com (10.20.43.31) with Microsoft SMTP Server id 14.3.361.1; Mon, 26 Feb 2018 11:46:50 -0800 Date: Mon, 26 Feb 2018 19:46:40 +0000 From: "Maciej W. Rozycki" To: Subject: [committed 2/2] MIPS: Don't use a 32-bit BFD architecture with a 64-bit ABI In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-BESS-ID: 1519674595-637139-10615-130873-5 X-BESS-VER: 2018.2-r1802232356 X-BESS-Apparent-Source-IP: 12.201.5.28 X-BESS-Outbound-Spam-Score: 0.00 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.190449 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.00 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Select `bfd_mach_mips4000', which corresponds to the MIPS III ISA, the earlies with 64-bit support, whenever a 32-bit BFD architecture has been chosen to use with a 64-bit ABI. The situation can happen in a few cases: 1. When the user has used `set architecture' or `set mips abi' commands to override automatic selection and then starts a debug session by requesting to run, attach or connect to a target. 2. In native debugging when reattaching to a previously debugged process where the program to be debugged has been since discarded, as observed with: FAIL: gdb.base/attach.exp: attach2, with no file (GDB internal error) in n32 and n64 regression testing. 3. In remote debugging with a non-XML debug stub when discarding the program to be debugged while connected to the remote target, as observed with: FAIL: gdb.base/break-unload-file.exp: cmdline: always-inserted on: break: file (GDB internal error) in n32 and n64 regression testing. In the latter two cases the ABI, quite rightfully, is retained while the program to be debugged is discarded. This is because in that case the ABI previously determined is carried over along with `gdbarch' in use, which is retained. The BFD architecture is however discarded and the default then applies, because it is not attached to `gdbarch'. In all these cases we trip with an internal error message as follows: .../gdb/mips-tdep.c:766: internal-error: bad register size A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n This is a bug, please report it. For instructions, see: . coming from `mips_pseudo_register_read', because the raw register width inferred from the BFD architecture turns out to be 4 for the general registers while the cooked register width inferred from the ABI in effect is 8. We do not hit this internal error in remote debugging with an XML debug stub, because in that case raw register width information is passed by the stub along with the XML target description. Ultimately I think we ought to make the BFD architecture sticky like the ABI, however in the interim this simple fix will do, removing the error across all three cases. The case where the user has used `set mips abi' or `set architecture' commands has to be handled anyway, and although a more sophisticated solution could be envisaged, such as reporting an error with the respective `set' command, I think this is too much of a corner case to bother. gdb/ * mips-tdep.c (mips_gdbarch_init): Don't use a 32-bit BFD architecture with a 64-bit ABI. --- gdb/mips-tdep.c | 8 ++++++++ 1 file changed, 8 insertions(+) gdb-mips-gdbarch-init-arches-isa-from-abi.diff Index: binutils/gdb/mips-tdep.c =================================================================== --- binutils.orig/gdb/mips-tdep.c 2017-12-14 10:32:34.439700558 +0000 +++ binutils/gdb/mips-tdep.c 2017-12-14 10:34:14.003034347 +0000 @@ -8185,6 +8185,14 @@ mips_gdbarch_init (struct gdbarch_info i fprintf_unfiltered (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n", mips_abi); + /* Make sure we don't use a 32-bit architecture with a 64-bit ABI. */ + if (mips_abi != MIPS_ABI_EABI32 + && mips_abi != MIPS_ABI_O32 + && info.bfd_arch_info != NULL + && info.bfd_arch_info->arch == bfd_arch_mips + && info.bfd_arch_info->bits_per_word < 64) + info.bfd_arch_info = bfd_lookup_arch (bfd_arch_mips, bfd_mach_mips4000); + /* Determine the default compressed ISA. */ if ((elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0 && (elf_flags & EF_MIPS_ARCH_ASE_M16) == 0)