file-format.exp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright (C) 1999-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # gcc-bugs@gcc.gnu.org
  17. # This file defines a proc for determining the file format in use by the
  18. # target. This is useful for tests that are only supported by certain file
  19. # formats. This procedure is defined in a separate file so that it can be
  20. # included by other expect library files.
  21. proc gcc_target_object_format { } {
  22. global gcc_target_object_format_saved
  23. global tool
  24. if [info exists gcc_target_object_format_saved] {
  25. verbose "gcc_target_object_format returning saved $gcc_target_object_format_saved" 2
  26. } elseif { [istarget *-*-darwin*] } {
  27. # Darwin doesn't necessarily have objdump, so hand-code it.
  28. set gcc_target_object_format_saved mach-o
  29. } elseif { [istarget hppa*-*-hpux*] } {
  30. # HP-UX doesn't necessarily have objdump, so hand-code it.
  31. if { [istarget hppa*64*-*-hpux*] } {
  32. set gcc_target_object_format_saved elf
  33. } else {
  34. set gcc_target_object_format_saved som
  35. }
  36. } elseif { [istarget *-*-aix*] } {
  37. # AIX doesn't necessarily have objdump, so hand-code it.
  38. set gcc_target_object_format_saved coff
  39. } else {
  40. set objdump_name [find_binutils_prog objdump]
  41. set open_file [open objfmtst.c w]
  42. puts $open_file "void foo(void) { }"
  43. close $open_file
  44. ${tool}_target_compile objfmtst.c objfmtst.o object ""
  45. file delete objfmtst.c
  46. set output [remote_exec host "$objdump_name" "--file-headers objfmtst.o"]
  47. set output [lindex $output 1]
  48. file delete objfmtst.o
  49. if ![ regexp "file format (.*)arch" $output dummy objformat ] {
  50. verbose "Could not parse objdump output" 2
  51. set gcc_target_object_format_saved unknown
  52. } else {
  53. switch -regexp $objformat {
  54. elf {
  55. set gcc_target_object_format_saved elf
  56. }
  57. ecoff {
  58. set gcc_target_object_format_saved ecoff
  59. }
  60. coff {
  61. set gcc_target_object_format_saved coff
  62. }
  63. a\.out {
  64. set gcc_target_object_format_saved a.out
  65. }
  66. pe {
  67. set gcc_target_object_format_saved pe
  68. }
  69. som {
  70. set gcc_target_object_format_saved som
  71. }
  72. default {
  73. verbose "Unknown file format: $objformat" 3
  74. set gcc_target_object_format_saved unknown
  75. }
  76. }
  77. verbose "gcc_target_object_format returning $gcc_target_object_format_saved" 2
  78. }
  79. }
  80. return $gcc_target_object_format_saved
  81. }