1# Copyright (C) 2002 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 17# This test checks whether MIPS ELF configurations pass the right 18# ABI flags to the assembler. An ABI flag should always be passed 19# unless MEABI is selected. 20 21load_lib gcc-dg.exp 22 23# Only run this test on MIPS ELF targets 24if {![istarget mips*-*-*] || [gcc_target_object_format] != "elf"} { 25 return 26} 27 28# A list of all assembler ABI flags. We should use SGI-compatible 29# flags where possible. 30set asm_abi_flags {-32 -n32 -64 -mabi=o64 -mabi=eabi} 31 32# Return true if the configuration uses MEABI by default. 33proc is_meabi_config {} { 34 return [expr {[istarget mipsisa32*-*-elf*] 35 || [istarget mipsisa32el-*-elf*] 36 || [istarget mipsisa64-*-elf*] 37 || [istarget mipsisa64el-*-elf*] 38 || [istarget mipsisa64sr71k-*-elf*]}] 39} 40 41# Try to assemble mips-abi.s (an empty file), passing -v in order to 42# get the assembler command line. Check whether an appropriate ABI 43# flag is passed. 44# 45# NAME is a name for the pass/fail line. 46# ABIS is a list of acceptable assembler ABI flags, or "" if no 47# ABI flag is expected. 48# FLAGS is a list of options for gcc. 49proc check_mips_abi {name abis flags} { 50 global srcdir subdir asm_abi_flags 51 52 lappend flags "-v" 53 set lines [gcc_target_compile "$srcdir/$subdir/mips-abi.s" \ 54 "mips-abi.o" object \ 55 [list "additional_flags=$flags"]] 56 set good 0 57 set bad 0 58 foreach line [split $lines "\n"] { 59 # Find the assembler command line. 60 if {[string first "$srcdir/$subdir/mips-abi.s" $line] >= 0} { 61 foreach arg [split $line " "] { 62 # Count the number of matching and non-matching 63 # ABI options. 64 if {[lsearch -exact $abis $arg] >= 0} { 65 incr good 66 } elseif {[lsearch -exact $asm_abi_flags $arg] >= 0} { 67 incr bad 68 } 69 } 70 } 71 } 72 if {$good == ($abis != "") && $bad == 0} { 73 pass "mips-abi $name" 74 } else { 75 fail "mips-abi $name" 76 } 77} 78 79# Collect the default target flags. 80set default_flags "" 81set target [target_info name] 82if {[info exists CFLAGS_FOR_TARGET]} { 83 append default_flags " $CFLAGS_FOR_TARGET" 84} 85if {[board_info $target exists cflags]} { 86 append default_flags " [board_info $target cflags]" 87} 88if {[board_info $target exists multilib_flags]} { 89 append default_flags " [board_info $target multilib_flags]" 90} 91 92# See whether the default command line specifies an ABI. 93set default_abi "" 94foreach flag $default_flags { 95 if {[string first "-mabi" $flag] == 0} { 96 set default_abi $flag 97 } 98} 99 100# If the command line does specify an ABI, just check for the 101# appropriate assembler flag. 102switch -- $default_abi { 103 -mabi=meabi { check_mips_abi "MEABI" "" "" } 104 -mabi=eabi { check_mips_abi "EABI" "-mabi=eabi" "" } 105 -mabi=32 { check_mips_abi "o32" "-32" "" } 106 -mabi=n32 { check_mips_abi "n32" "-n32" "" } 107 -mabi=o64 { check_mips_abi "o64" "-mabi=o64" "" } 108 -mabi=64 { check_mips_abi "n64" "-64" "" } 109 "" { 110 # MEABI configs shouldn't pass an ABI flag by default 111 # but the others should. It doesn't seem worthwhile 112 # duplicating the configuration to ABI logic here, 113 # so just accept any ABI. 114 if {[is_meabi_config]} { 115 check_mips_abi "default" "" "" 116 } else { 117 check_mips_abi "default" $asm_abi_flags "" 118 } 119 # See whether passing a -mabi flag does the right thing. 120 # Only try ABIs that the SGI assembler also understands. 121 check_mips_abi "o32" "-32" "-mabi=32" 122 check_mips_abi "n32" "-n32" "-mabi=n32" 123 check_mips_abi "64" "-64" "-mabi=64" 124 } 125} 126