aarch64: Add fallback if ARM_CC_FOR_TARGET not set
authorPedro Alves <pedro@palves.net>
Tue, 7 Jun 2022 19:11:32 +0000 (20:11 +0100)
committerPedro Alves <pedro@palves.net>
Wed, 8 Jun 2022 13:06:38 +0000 (14:06 +0100)
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
gdb/testsuite/gdb.multi/multi-arch.exp
gdb/testsuite/lib/gdb.exp

index a1496fb5571b216ddb0993925708476ad8e80a7f..a8e81e29ee9a64387c5c6eeeecbe5cbb0d92af41 100644 (file)
@@ -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"
index e5c2d9cc16188e80f2435ee13ea07071d46c7b32..b564e6caf25f06478fd7ac4f96191d5d8ed19f1f 100644 (file)
@@ -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
index 402450152acedfff1a903f111b46ed6ff0930e98..6a3fed110a865d8b8169ffe2382598f14651bb87 100644 (file)
@@ -8666,5 +8666,60 @@ 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} {
+               return $compiler
+           }
+       }
+    }
+
+    return ""
+}
+
 # Always load compatibility stuff.
 load_lib future.exp