lto.exp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. # Copyright (C) 2009-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. # Contributed by Diego Novillo <dnovillo@google.com>
  16. # Prune messages that aren't useful.
  17. proc lto_prune_warns { text } {
  18. verbose "lto_prune_warns: entry: $text" 2
  19. # Many tests that use visibility will still pass on platforms that don't support it.
  20. regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
  21. # Allow mixed-language LTO tests to pass with make check-c++0x
  22. regsub -all "(^|\n)\[^\n\]*: warning: command line option '-std=\[^\n\]*" $text "" text
  23. # And any stray location lines.
  24. regsub -all "(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
  25. regsub -all "(^|\n)In file included from \[^\n\]*" $text "" text
  26. regsub -all "(^|\n)\[ \t\]*from \[^\n\]*" $text "" text
  27. # Sun ld warns about common symbols with differing sizes. Unlike GNU ld
  28. # --warn-common (off by default), they cannot be disabled.
  29. regsub -all "(^|\n)ld: warning: symbol \[`'\]\[^\n\]*' has differing sizes:" $text "" text
  30. regsub -all "(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
  31. regsub -all "(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
  32. verbose "lto_prune_warns: exit: $text" 2
  33. return $text
  34. }
  35. # lto_init -- called at the start of each subdir of tests
  36. proc lto_init { args } {
  37. global LTO_OPTIONS
  38. if {[info exists args] && $args == "no-mathlib"} {
  39. global board_info
  40. global saved_mathlib
  41. set dest [target_info name]
  42. if [board_info $dest exists mathlib] {
  43. set saved_mathlib [board_info $dest mathlib]
  44. }
  45. set board_info($dest,mathlib) " "
  46. }
  47. # Each test is run with the compiler options from this list.
  48. # The default option lists can be overridden by LTO_OPTIONS="[list
  49. # {opts_1} {opts_2}... {opts_n}]" where opts_i are lists of options.
  50. # You can put this in the environment before site.exp is written or
  51. # add it to site.exp directly.
  52. if ![info exists LTO_OPTIONS] {
  53. if [check_linker_plugin_available] {
  54. set LTO_OPTIONS [list \
  55. {-O0 -flto -flto-partition=none -fuse-linker-plugin} \
  56. {-O2 -flto -flto-partition=none -fuse-linker-plugin -fno-fat-lto-objects } \
  57. {-O0 -flto -flto-partition=1to1 -fno-use-linker-plugin } \
  58. {-O2 -flto -flto-partition=1to1 -fno-use-linker-plugin } \
  59. {-O0 -flto -fuse-linker-plugin -fno-fat-lto-objects } \
  60. {-O2 -flto -fuse-linker-plugin} \
  61. ]
  62. } else {
  63. set LTO_OPTIONS [list \
  64. {-O0 -flto -flto-partition=none } \
  65. {-O2 -flto -flto-partition=none } \
  66. {-O0 -flto -flto-partition=1to1 } \
  67. {-O2 -flto -flto-partition=1to1 } \
  68. {-O0 -flto } \
  69. {-O2 -flto} \
  70. ]
  71. }
  72. }
  73. }
  74. #
  75. # lto_finish -- called at the end of each subdir of tests if mathlib is
  76. # changed.
  77. #
  78. proc lto_finish { } {
  79. global board_info
  80. global saved_mathlib
  81. set dest [target_info name]
  82. if [info exists saved_mathlib] {
  83. set board_info($dest,mathlib) $saved_mathlib
  84. } elseif [board_info $dest exists mathlib] {
  85. unset board_info($dest,mathlib)
  86. }
  87. }
  88. # Subsets of tests can be selectively disabled by members of this list:
  89. # - ATTRIBUTE: disable all tests using the __attribute__ extension,
  90. # - COMPLEX: disable all tests using the complex types feature,
  91. # - COMPLEX_INT: disable all tests using the complex integral types extension,
  92. # - VA: disable all tests using the variable number of arguments feature,
  93. # - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
  94. # structure members extension,
  95. # - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
  96. # The default skip lists can be overriden by
  97. # LTO_SKIPS="[list {skip_1}...{skip_n}]"
  98. # where skip_i are skip identifiers. You can put this in the environment
  99. # before site.exp is written or add it to site.exp directly.
  100. if ![info exists LTO_SKIPS] {
  101. set LTO_SKIPS [list {}]
  102. }
  103. global lto_skip_list
  104. set lto_skip_list $LTO_SKIPS
  105. load_lib dg.exp
  106. load_lib gcc-dg.exp
  107. load_lib gcc.exp
  108. # lto-obj -- compile to an object file
  109. #
  110. # SOURCE is the source file
  111. # DEST is the object file
  112. # OPTALL is the list of compiler options to use with all tests
  113. # OPTFILE is the list of compiler options to use with this file
  114. # OPTSTR is the options to print with test messages
  115. # XFAILDATA is the xfail data to be passed to the compiler
  116. proc lto-obj { source dest optall optfile optstr xfaildata } {
  117. global testcase
  118. global tool
  119. global compiler_conditional_xfail_data
  120. global lto_skip_list
  121. # Add the skip specifiers.
  122. foreach skip $lto_skip_list {
  123. if { ![string match $skip ""] } {
  124. lappend optall "-DSKIP_$skip"
  125. }
  126. }
  127. # Set up the options for compiling this file.
  128. set options ""
  129. lappend options "additional_flags=$optall $optfile"
  130. set compiler_conditional_xfail_data $xfaildata
  131. # Allow C source files to mix freely with other languages
  132. if [ string match "*.c" $source ] then {
  133. set comp_output [gcc_target_compile "$source" "$dest" object $options]
  134. } else {
  135. set comp_output [${tool}_target_compile "$source" "$dest" object $options]
  136. }
  137. # Prune unimportant visibility warnings before checking output.
  138. set comp_output [lto_prune_warns $comp_output]
  139. ${tool}_check_compile "$testcase $dest assemble" $optstr $dest $comp_output
  140. }
  141. # lto-link-and-maybe-run -- link the object files and run the executable
  142. # if compile_type is set to "run"
  143. #
  144. # TESTNAME is the mixture of object files to link
  145. # OBJLIST is the list of object files to link
  146. # DEST is the name of the executable
  147. # OPTALL is a list of compiler and linker options to use for all tests
  148. # OPTFILE is a list of compiler and linker options to use for this test
  149. # OPTSTR is the list of options to list in messages
  150. proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
  151. global testcase
  152. global tool
  153. global compile_type
  154. global board_info
  155. # Check that all of the objects were built successfully.
  156. foreach obj [split $objlist] {
  157. if ![file_on_host exists $obj] then {
  158. unresolved "$testcase $testname link $optstr"
  159. unresolved "$testcase $testname execute $optstr"
  160. return
  161. }
  162. }
  163. # Set up the options for linking this test.
  164. set options ""
  165. lappend options "additional_flags=$optall $optfile"
  166. set target_board [target_info name]
  167. set relocatable 0
  168. # Some LTO tests do relocatable linking. Some target boards set
  169. # a linker script which can't be used for relocatable linking.
  170. # Use the default linker script instead.
  171. if { [lsearch -exact [split "$optall $optfile"] "-r"] >= 0 } {
  172. set relocatable 1
  173. }
  174. if { $relocatable } {
  175. set saved_ldscript [board_info $target_board ldscript]
  176. set board_info($target_board,ldscript) ""
  177. }
  178. # Link the objects into an executable.
  179. set comp_output [${tool}_target_compile "$objlist" $dest executable \
  180. "$options"]
  181. if { $relocatable } {
  182. set board_info($target_board,ldscript) $saved_ldscript
  183. }
  184. # Prune unimportant visibility warnings before checking output.
  185. set comp_output [lto_prune_warns $comp_output]
  186. if ![${tool}_check_compile "$testcase $testname link" $optstr \
  187. $dest $comp_output] then {
  188. unresolved "$testcase $testname execute $optstr"
  189. return
  190. }
  191. # Return if we only needed to link.
  192. if { ![string compare "link" $compile_type] } {
  193. return
  194. }
  195. # Run the self-checking executable.
  196. if ![string match "*/*" $dest] then {
  197. set dest "./$dest"
  198. }
  199. set result [${tool}_load $dest "" ""]
  200. set status [lindex $result 0]
  201. if { $status == "pass" } then {
  202. file_on_host delete $dest
  203. }
  204. $status "$testcase $testname execute $optstr"
  205. }
  206. # lto-get-options-main -- get target requirements for a test and
  207. # options for the primary source file and the test as a whole
  208. #
  209. # SRC is the full pathname of the primary source file.
  210. proc lto-get-options-main { src } {
  211. global compile_type
  212. global dg-extra-ld-options
  213. global dg-suppress-ld-options
  214. set dg-extra-ld-options ""
  215. set dg-suppress-ld-options ""
  216. # dg-options sets a variable called dg-extra-tool-flags.
  217. set dg-extra-tool-flags ""
  218. # dg-options sets a variable called tool_flags.
  219. set tool_flags ""
  220. # dg-require-* sets dg-do-what.
  221. upvar dg-do-what dg-do-what
  222. upvar dg-final-code dg-final-code
  223. set dg-final-code ""
  224. set tmp [dg-get-options $src]
  225. verbose "getting options for $src: $tmp"
  226. foreach op $tmp {
  227. set cmd [lindex $op 0]
  228. verbose "cmd is $cmd"
  229. if { [string match "dg-skip-if" $cmd] \
  230. || [string match "dg-require-*" $cmd] } {
  231. set status [catch "$op" errmsg]
  232. if { $status != 0 } {
  233. perror "src: $errmsg for \"$op\"\n"
  234. unresolved "$src: $errmsg for \"$op\""
  235. return
  236. }
  237. } elseif { [string match "dg-lto-options" $cmd] } {
  238. set op [lreplace $op 0 0 "dg-options"]
  239. set status [catch "$op" errmsg]
  240. if { $status != 0 } {
  241. perror "src: $errmsg for \"$op\"\n"
  242. unresolved "$src: $errmsg for \"$op\""
  243. return
  244. }
  245. } elseif { ![string compare "dg-xfail-if" $cmd] \
  246. || ![string compare "dg-options" $cmd] } {
  247. warning "lto.exp does not support $cmd in primary source file"
  248. } elseif { ![string compare "dg-lto-do" $cmd] } {
  249. if { [llength $op] > 3 } {
  250. set kw [lindex [lindex $op 3] 0]
  251. if [string match "target" $kw] {
  252. perror "$src: dg-lto-do does not support \"target\""
  253. } elseif [string match "xfail" $kw] {
  254. perror "$src: dg-lto-do does not support \"xfail\""
  255. } else {
  256. perror "$src: dg-lto-do takes a single argument"
  257. }
  258. }
  259. set dgdo [lindex $op 2]
  260. verbose "dg-lto-do command for \"$op\" is $dgdo"
  261. if { ![string compare "assemble" $dgdo] } {
  262. set compile_type "assemble"
  263. } elseif { ![string compare "run" $dgdo] } {
  264. set compile_type "run"
  265. } elseif { ![string compare "link" $dgdo] } {
  266. set compile_type "link"
  267. } else {
  268. warning "lto.exp does not support dg-lto-do $dgdo"
  269. }
  270. } elseif { ![string compare "dg-extra-ld-options" $cmd] } {
  271. if { [llength $op] > 4 } {
  272. error "[lindex $op 0]: too many arguments"
  273. } else {
  274. if { [llength $op] == 3
  275. || ([llength $op] > 3
  276. && [dg-process-target [lindex $op 3]] == "S") } {
  277. set dg-extra-ld-options [lindex $op 2]
  278. verbose \
  279. "dg-extra-ld-options for main is ${dg-extra-ld-options}"
  280. }
  281. }
  282. } elseif { ![string compare "dg-suppress-ld-options" $cmd] } {
  283. if { [llength $op] > 4 } {
  284. error "[lindex $op 0]: too many arguments"
  285. } else {
  286. if { [llength $op] == 3
  287. || ([llength $op] > 3
  288. && [dg-process-target [lindex $op 3]] == "S") } {
  289. set dg-suppress-ld-options [lindex $op 2]
  290. verbose \
  291. "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
  292. }
  293. }
  294. } elseif { ![string compare "dg-final" $cmd] } {
  295. if { [llength $op] > 3 } {
  296. error "[lindex $op 0]: too many arguments"
  297. } else {
  298. append dg-final-code "[lindex $op 2]\n"
  299. }
  300. } else {
  301. # Ignore unrecognized dg- commands, but warn about them.
  302. warning "lto.exp does not support $cmd"
  303. }
  304. }
  305. # Return flags to use for compiling the primary source file and for
  306. # linking.
  307. verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
  308. return ${dg-extra-tool-flags}
  309. }
  310. # lto-get-options -- get special tool flags to use for a secondary
  311. # source file
  312. #
  313. # SRC is the full pathname of the source file.
  314. # The result is a list of options to use.
  315. #
  316. # This code is copied from proc dg-test in dg.exp from DejaGNU.
  317. proc lto-get-options { src } {
  318. # dg-options sets a variable called dg-extra-tool-flags.
  319. set dg-extra-tool-flags ""
  320. # dg-xfail-if sets compiler_conditional_xfail_data.
  321. global compiler_conditional_xfail_data
  322. set compiler_conditional_xfail_data ""
  323. # dg-xfail-if needs access to dg-do-what.
  324. upvar dg-do-what dg-do-what
  325. set tmp [dg-get-options $src]
  326. foreach op $tmp {
  327. set cmd [lindex $op 0]
  328. if { ![string compare "dg-options" $cmd] \
  329. || ![string compare "dg-xfail-if" $cmd] } {
  330. set status [catch "$op" errmsg]
  331. if { $status != 0 } {
  332. perror "src: $errmsg for \"$op\"\n"
  333. unresolved "$src: $errmsg for \"$op\""
  334. return
  335. }
  336. } elseif { [string match "dg-require-*" $cmd] } {
  337. warning "lto.exp does not support $cmd in secondary source files"
  338. } else {
  339. # Ignore unrecognized dg- commands, but warn about them.
  340. warning "lto.exp does not support $cmd in secondary source files"
  341. }
  342. }
  343. return ${dg-extra-tool-flags}
  344. }
  345. # lto-execute -- compile multi-file tests
  346. #
  347. # SRC1 is the full pathname of the main file of the testcase.
  348. # SID identifies a test suite in the names of temporary files.
  349. proc lto-execute { src1 sid } {
  350. global srcdir tmpdir
  351. global lto_option_list
  352. global tool
  353. global verbose
  354. global testcase
  355. global gluefile
  356. global compiler_conditional_xfail_data
  357. global dg-do-what-default
  358. global compile_type
  359. global dg-extra-ld-options
  360. global dg-suppress-ld-options
  361. global LTO_OPTIONS
  362. global dg-final-code
  363. global testname_with_flags
  364. # Get extra flags for this test from the primary source file, and
  365. # process other dg-* options that this suite supports. Warn about
  366. # unsupported flags.
  367. verbose "lto-execute: $src1" 1
  368. set compile_type "run"
  369. set dg-do-what [list ${dg-do-what-default} "" P]
  370. set extra_flags(0) [lto-get-options-main $src1]
  371. set compile_xfail(0) ""
  372. # If the main file defines dg-options, those flags are used to
  373. # overwrite the default lto_option_list taken from LTO_OPTIONS.
  374. if { [string length $extra_flags(0)] > 0 } {
  375. set lto_option_list $extra_flags(0)
  376. set extra_flags(0) ""
  377. } else {
  378. set lto_option_list $LTO_OPTIONS
  379. }
  380. # Set up the names of the other source files.
  381. set dir [file dirname $src1]
  382. set base [file rootname $src1]
  383. set base [string range $base [string length $dir] end]
  384. regsub "_0" $base "" base
  385. regsub "/" $base "" base
  386. set src_list $src1
  387. set i 1
  388. set done 0
  389. while { !$done } {
  390. set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
  391. if { [llength ${names}] > 1 } {
  392. warning "lto-execute: more than one file matched ${dir}/${base}_${i}.*"
  393. }
  394. if { [llength ${names}] == 1 } {
  395. lappend src_list [lindex ${names} 0]
  396. incr i
  397. } else {
  398. set num_srcs ${i}
  399. set done 1
  400. }
  401. }
  402. # Use the dg-options mechanism to specify extra flags for each
  403. # of the secondary files.
  404. # The extra flags in each file are used to compile that file, and the
  405. # extra flags in *_0.* are also used for linking.
  406. verbose "\tsrc_list is: $src_list"
  407. for {set i 1} {$i < $num_srcs} {incr i} {
  408. set extra_flags($i) [lto-get-options [lindex $src_list $i]]
  409. set compile_xfail($i) $compiler_conditional_xfail_data
  410. }
  411. # Define the names of the object files.
  412. set obj_list ""
  413. for {set i 0} {$i < $num_srcs} {incr i} {
  414. lappend obj_list "${sid}_${base}_${i}.o"
  415. }
  416. # Get the base name of this test, for use in messages.
  417. set testcase [lindex ${src_list} 0]
  418. # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
  419. # be possible to use "regsub" here, if we were careful to escape
  420. # all regular expression characters in $srcdir and $tmpdir, but
  421. # that would be more complicated that this approach.)
  422. if {[string first "$srcdir/" "${testcase}"] == 0} {
  423. set testcase [string range "${testcase}" [string length "$srcdir/"] end]
  424. }
  425. if {[string first "$tmpdir/" "$testcase"] == 0} {
  426. set testcase [string range "$testcase" [string length "$tmpdir/"] end]
  427. set testcase "tmpdir-$testcase"
  428. }
  429. # If we couldn't rip $srcdir out of `src1' then just do the best we can.
  430. # The point is to reduce the unnecessary noise in the logs. Don't strip
  431. # out too much because different testcases with the same name can confuse
  432. # `test-tool'.
  433. if [string match "/*" $testcase] then {
  434. set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
  435. }
  436. # Check whether this test is supported for this target.
  437. if { [lindex ${dg-do-what} 1 ] == "N" } {
  438. unsupported "$testcase"
  439. verbose "$testcase not supported on this target, skipping it" 3
  440. return
  441. }
  442. # Should be safe for non-fortran too but be paranoid..
  443. if {$sid eq "f_lto"} {
  444. list-module-names $src_list
  445. }
  446. regsub "_0.*" $testcase "" testcase
  447. # Set up the base name of executable files so they'll be unique.
  448. regsub -all "\[./\]" $testcase "-" execbase
  449. # Loop through all of the option lists used for this test.
  450. set count 0
  451. foreach option $lto_option_list {
  452. verbose "Testing $testcase, $option"
  453. # There's a unique name for each executable we generate.
  454. set execname "${execbase}-${count}1.exe"
  455. incr count
  456. file_on_host delete $execname
  457. # Compile pieces with the compiler under test.
  458. set i 0
  459. foreach src $src_list obj $obj_list {
  460. lto-obj $src $obj $option $extra_flags($i) $option \
  461. $compile_xfail($i)
  462. incr i
  463. }
  464. # Link (using the compiler under test), run, and clean up tests.
  465. if { ![string compare "run" $compile_type] \
  466. || ![string compare "link" $compile_type] } {
  467. # Filter out any link options we were asked to suppress.
  468. set reduced {}
  469. foreach x [split $option] {
  470. if {[lsearch ${dg-suppress-ld-options} $x] == -1} {
  471. lappend reduced $x
  472. }
  473. }
  474. set filtered [join $reduced " "]
  475. lto-link-and-maybe-run \
  476. "[lindex $obj_list 0]-[lindex $obj_list end]" \
  477. $obj_list $execname $filtered ${dg-extra-ld-options} \
  478. $filtered
  479. }
  480. # Are there any further tests to perform?
  481. # Note that if the program has special run-time requirements, running
  482. # of the program can be delayed until here. Ditto for other situations.
  483. # It would be a bit cumbersome though.
  484. if ![string match ${dg-final-code} ""] {
  485. regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
  486. # Note that the use of `args' here makes this a varargs proc.
  487. proc dg-final-proc { args } ${dg-final-code}
  488. verbose "Running dg-final tests." 3
  489. verbose "dg-final-proc:\n[info body dg-final-proc]" 4
  490. if [catch "dg-final-proc $src1" errmsg] {
  491. perror "$src1: error executing dg-final: $errmsg"
  492. # ??? The call to unresolved here is necessary to clear
  493. # `errcnt'. What we really need is a proc like perror that
  494. # doesn't set errcnt. It should also set exit_status to 1.
  495. unresolved "$src1: error executing dg-final: $errmsg"
  496. }
  497. }
  498. # Clean up object files.
  499. set files [glob -nocomplain ${sid}_*.o]
  500. if { $files != "" } {
  501. foreach objfile $files {
  502. if { ![info exists gluefile] || $objfile != $gluefile } {
  503. eval "file_on_host delete $objfile"
  504. }
  505. }
  506. }
  507. # Clean up after -save-temps. The LTO tests don't use dg-test, so
  508. # testname-for-summary needs to be defined explicitly for each
  509. # file that needs to be removed.
  510. set testname_with_flags $execname
  511. eval "cleanup-saved-temps"
  512. for {set i 0} {$i < $num_srcs} {incr i} {
  513. set testname_with_flags "${base}_${i}"
  514. eval "cleanup-saved-temps"
  515. set testname_with_flags "${sid}_${base}_${i}"
  516. eval "cleanup-saved-temps"
  517. }
  518. unset testname_with_flags
  519. if { ![string compare "run" $compile_type] \
  520. || ![string compare "link" $compile_type] } {
  521. file_on_host delete $execname
  522. }
  523. # Should be safe for non-fortran too but be paranoid..
  524. if {$sid eq "f_lto"} {
  525. cleanup-modules ""
  526. }
  527. }
  528. }
  529. # Utility for scanning a symbol in the final executable, invoked via dg-final.
  530. # Call pass if pattern is present, otherwise fail.
  531. #
  532. # Argument 0 is the regexp to match.
  533. # Argument 1 handles expected failures and the like
  534. proc scan-symbol { args } {
  535. global nm
  536. global base_dir
  537. upvar 2 execname execname
  538. if { [llength $args] >= 2 } {
  539. switch [dg-process-target [lindex $args 1]] {
  540. "S" { }
  541. "N" { return }
  542. "F" { setup_xfail "*-*-*" }
  543. "P" { }
  544. }
  545. }
  546. # Find nm like we find g++ in g++.exp.
  547. if ![info exists nm] {
  548. set nm [findfile $base_dir/../../../binutils/nm \
  549. $base_dir/../../../binutils/nm \
  550. [findfile $base_dir/../../nm $base_dir/../../nm \
  551. [findfile $base_dir/nm $base_dir/nm \
  552. [transform nm]]]]
  553. verbose -log "nm is $nm"
  554. }
  555. set output_file "[glob -nocomplain $execname]"
  556. if { $output_file == "" } {
  557. fail "scan-symbol $args: dump file does not exist"
  558. return
  559. }
  560. set fd [open "| $nm $output_file" r]
  561. set text [read $fd]
  562. close $fd
  563. if [regexp -- [lindex $args 0] $text] {
  564. pass "scan-symbol $args"
  565. } else {
  566. fail "scan-symbol $args"
  567. }
  568. }
  569. # Call pass if object readelf is ok, otherwise fail.
  570. # example: /* { dg-final { object-readelf Tag_ABI_enum_size int} } */
  571. proc object-readelf { args } {
  572. global readelf
  573. global base_dir
  574. upvar 2 execname execname
  575. if { [llength $args] < 2 } {
  576. error "object-readelf: too few arguments"
  577. return
  578. }
  579. if { [llength $args] > 3 } {
  580. error "object-readelf: too many arguments"
  581. return
  582. }
  583. if { [llength $args] >= 3 } {
  584. switch [dg-process-target [lindex $args 2]] {
  585. "S" { }
  586. "N" { return }
  587. "F" { setup_xfail "*-*-*" }
  588. "P" { }
  589. }
  590. }
  591. # Find size like we find g++ in g++.exp.
  592. if ![info exists readelf] {
  593. set readelf [findfile $base_dir/../../../binutils/readelf \
  594. $base_dir/../../../binutils/readelf \
  595. [findfile $base_dir/../../readelf $base_dir/../../readelf \
  596. [findfile $base_dir/readelf $base_dir/readelf \
  597. [transform readelf]]]]
  598. verbose -log "readelf is $readelf"
  599. }
  600. set what [lindex $args 0]
  601. set with [lindex $args 1]
  602. if ![file_on_host exists $execname] {
  603. verbose -log "$execname does not exist"
  604. unresolved "object-readelf $what "
  605. return
  606. }
  607. set output [remote_exec host "$readelf -A" "$execname"]
  608. set status [lindex $output 0]
  609. if { $status != 0 } {
  610. verbose -log "object-readelf: $readelf failed"
  611. unresolved "object-readelf $what $execname"
  612. return
  613. }
  614. set text [lindex $output 1]
  615. set lines [split $text "\n"]
  616. set done 0
  617. set i 0
  618. while { !$done } {
  619. set line_tex [lindex $lines $i]
  620. if { [llength ${line_tex}] > 1} {
  621. incr i
  622. if [regexp -- $what $line_tex] {
  623. set match [regexp -- $with $line_tex]
  624. set done 1
  625. }
  626. } else {
  627. set done 1
  628. }
  629. }
  630. verbose -log "$what size is $with;"
  631. if { $match == 1 } {
  632. pass "object-readelf $what size is correct."
  633. } else {
  634. fail "object-readelf $what size is incorrect."
  635. }
  636. }