From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by sourceware.org (Postfix) with ESMTPS id 1BA83396D839 for ; Wed, 8 Jun 2022 11:20:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BA83396D839 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f41.google.com with SMTP id o37-20020a05600c512500b0039c4ba4c64dso5203739wms.2 for ; Wed, 08 Jun 2022 04:20:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:references:in-reply-to :content-transfer-encoding; bh=NEV5vX0C/4dk08jC/cA6ELluDRr2zYxiLIcIdXP/7y0=; b=jrE8clfVSv/8V/snsEJ2KiD4rwSXwPiOB78a/+TrojuXbdd9BggV3JtrsfF5q7j4EI L77iqE4eYCmIrNuxy7eZSvMpOkqLVq2G41JUQSuNZaozZUde7btIgv0pG+DSYfos+QNt 7Yis69EkzrgoDOyFH1QS335a2JfgLizkuF6fwZR5CeVsWa3QVWOsZtC+jiIFaTRTU/C1 kdPaancQGvVeU9uOrl0/1SEHa5OF1awVLM5kGk1uAjwxWwS2qvqYAQtQXTA09g3Tj0Ey L8cOHNkJViYPJFYrmgE6I+xwYWvsEkEgc+Vg9YCEQEInK3OOLYSPn+DEa/LRrMsnSt7F G8Lg== X-Gm-Message-State: AOAM53242dif3PrzFLMCokCwDlT924LQWT5XSAqqflPBft209E9VuO7Q NY1qUwyEVv4Fe77Q/CI3ti8= X-Google-Smtp-Source: ABdhPJzYvGqjFZU2fN7aE8eDANufWK62aDqSQvMVnCLCjGSfuj8zuBZVkMvBmLzFHG+hKXMRFprnNA== X-Received: by 2002:a05:600c:3b96:b0:397:485a:f5c5 with SMTP id n22-20020a05600c3b9600b00397485af5c5mr33338966wms.185.1654687211894; Wed, 08 Jun 2022 04:20:11 -0700 (PDT) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c425500b0039c41686421sm15797827wmm.17.2022.06.08.04.20.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jun 2022 04:20:10 -0700 (PDT) Message-ID: <755636d3-b2b5-9eeb-1b23-6f9830e3edbb@palves.net> Date: Wed, 8 Jun 2022 12:20:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: [PATCH v2] aarch64: Add fallback if ARM_CC_FOR_TARGET not set (was: Re: [PATCH 5/5] gdb: native target invalid architecture detection) Content-Language: en-US From: Pedro Alves To: Luis Machado , Andrew Burgess , John Baldwin , gdb-patches@sourceware.org References: <71a986a5-2cfa-543e-4034-70f3af7dfecf@FreeBSD.org> <87ee09d4rt.fsf@redhat.com> <09afe250-9573-45e1-993b-a2f911f03630@arm.com> <87ilpdhn73.fsf@redhat.com> <87ee01hed4.fsf@redhat.com> <12c3913e-186d-b676-fe52-cc3322b00926@arm.com> <5c316bab-c2d3-309e-f938-7480e861b444@palves.net> <9c711ccb-a558-8225-524b-5a1fa93fcee9@arm.com> <22be6164-79d7-c0f7-1b1b-c633be452e81@palves.net> In-Reply-To: <22be6164-79d7-c0f7-1b1b-c633be452e81@palves.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 11:20:15 -0000 On 2022-06-08 11:12, Pedro Alves wrote: > On 2022-06-08 08:54, Luis Machado wrote: > A 64-bit program can always exec a 32-bit program. Likewise the other way around. That should be > debuggable with a single gdb. > > As you say, it's supported. So, better test it routinely. Not testing it doesn't gain us anything, > other than leading to bitrot, as has happened. > >>> >>> Maybe it would be possible to come up with a way to default ARM_CC_FOR_TARGET to >>> something that works for most people when testing aarch64, somehow. >> The problem is that a compiler is not enough to make things run fine. If you have an aarch64 >> Ubuntu, for example, you'd need to add armhf as an architecture option and install both the >> compiler and the libraries (libc6:armhf mostly). > > That is not an issue specific to aarch64. On x86-64, you need to install extra runtime > packages to test -m32 too, just the compiler isn't enough, and those packages aren't installed > by default. > >> >> Another problem is that not every processor/kernel supports running a 32-bit process in a >> 64-bit environment. This makes things more complicated. >> > > Why "more complicated"? If you're worried about FAILs in the testsuite, then we can e.g. make it run > the 32-bit program once outside gdb to check that running 32-bits works. If that fails, then > we don't run the test. Seems simple, not complicated. Here's a new version of the patch, doing that. This version also moves the ARM_CC_FOR_TARGET fallback discovery to lib/gdb.exp so it can be used by gdb.multi/multi-arch-exec.exp as well. I've now tested this on gcc80 on the GCC compile farm (an aarch64 ubuntu 18.04 machine), and confirmed that it works. As in, we pick the right compiler (turns out it is arm-linux-gnueabihf-gcc, the third fallback compiler, so the try-to-run code is exercised). Of course, the testcases actually FAIL, due to 32-bit support bitrot in gdb itself. >From 689671e40f88f1bf29af2433c7b6c7662c8f38c6 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 7 Jun 2022 20:11:32 +0100 Subject: [PATCH] aarch64: Add fallback if ARM_CC_FOR_TARGET not set On Aarch64, you can set ARM_CC_FOR_TARGET to point to the 32-bit compiler to use when testing gdb.multi/multi-arch.exp and gdb.multi/multi-arch-exec.exp. If you don't set it, then those testcases don't run. I guess that approximately nobody remembers to set ARM_CC_FOR_TARGET. This commit adds a fallback. If ARM_CC_FOR_TARGET is not set, and testing for Linux, try arm-linux-gnueabi-gcc, arm-none-linux-gnueabi-gcc, arm-linux-gnueabihf-gcc as 32-bit compilers, making sure that the produced executable runs on the target machine before claiming that the compiler produces useful executables. Change-Id: Iefe5865d5fc84b4032eaff7f4c5c61582bf75c39 --- gdb/testsuite/gdb.multi/multi-arch-exec.exp | 4 +- gdb/testsuite/gdb.multi/multi-arch.exp | 4 +- gdb/testsuite/lib/gdb.exp | 57 +++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.multi/multi-arch-exec.exp b/gdb/testsuite/gdb.multi/multi-arch-exec.exp index a1496fb5571..a8e81e29ee9 100644 --- a/gdb/testsuite/gdb.multi/multi-arch-exec.exp +++ b/gdb/testsuite/gdb.multi/multi-arch-exec.exp @@ -62,8 +62,8 @@ proc append_arch2_options {options_var} { upvar 1 $options_var options if { [istarget "aarch64*-*-*"] } { - if {[info exists ARM_CC_FOR_TARGET]} { - lappend options "compiler=${ARM_CC_FOR_TARGET}" + if {[arm_cc_for_target] != ""} { + lappend options "compiler=[arm_cc_for_target]" return 1 } else { unsupported "ARM compiler is not known" diff --git a/gdb/testsuite/gdb.multi/multi-arch.exp b/gdb/testsuite/gdb.multi/multi-arch.exp index e5c2d9cc161..b564e6caf25 100644 --- a/gdb/testsuite/gdb.multi/multi-arch.exp +++ b/gdb/testsuite/gdb.multi/multi-arch.exp @@ -60,8 +60,8 @@ if { [build_executable "failed to prepare" ${exec1} "${srcfile1}" \ set options [list debug] if [istarget "aarch64*-*-*"] { - if {[info exists ARM_CC_FOR_TARGET]} { - lappend options "compiler=${ARM_CC_FOR_TARGET}" + if {[arm_cc_for_target] != ""} { + lappend options "compiler=[arm_cc_for_target]" } else { unsupported "ARM compiler is not known" return -1 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 402450152ac..ac01a31655f 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -8666,5 +8666,62 @@ proc get_set_option_choices {set_cmd} { return $values } +# Return the compiler that can generate 32-bit ARM executables. Used +# when testing biarch support on aarch64. If ARM_CC_FOR_TARGET is +# set, use that. If not, try a few common compiler names, making sure +# that the executable they produce can run. + +gdb_caching_proc arm_cc_for_target { + if {[info exists ARM_CC_FOR_TARGET]} { + # If the user specified the compiler explicitly, then don't + # check whether the resulting binary runs outside GDB. Assume + # that it does, and if it turns out it doesn't, then the user + # should get loud FAILs, instead of UNSUPPORTED. + return $ARM_CC_FOR_TARGET + } + + # Fallback to a few common compiler names. Also confirm the + # produced binary actually runs on the system before declaring + # we've found the right compiler. + + if [istarget "*-linux*-*"] { + set compilers { + arm-linux-gnueabi-gcc + arm-none-linux-gnueabi-gcc + arm-linux-gnueabihf-gcc + } + } else { + set compilers {} + } + + foreach compiler $compilers { + if {![is_remote host] && [which $compiler] == 0} { + # Avoid "default_target_compile: Can't find + # $compiler." warning issued from gdb_compile. + continue + } + + set src { int main() { return 0; } } + if {[gdb_simple_compile aarch64-32bit \ + $src \ + executable [list compiler=$compiler]]} { + + set result [remote_exec target $obj] + set status [lindex $result 0] + set output [lindex $result 1] + + file delete $obj + + if { $output != "" || $status != 0} { + continue + } + + return $compiler + } + } + + return "" +} + # Always load compatibility stuff. load_lib future.exp base-commit: bcdbf606bc054bd1fa9a1c8978f2d3a57e42adf4 -- 2.36.0