Comments
Patch
===================================================================
@@ -315,6 +315,90 @@ proc scan-assembler-dem-not { args } {
}
}
+# Call pass if symbol size is ok, otherwise fail.
+# example: /* { dg-final { object-symbol-size main <= 54 } } */
+proc object-symbol-size { args } {
+ global nm
+ global base_dir
+
+ if { [llength $args] < 3 } {
+ error "object-symbol-size: too few arguments"
+ return
+ }
+ if { [llength $args] > 4 } {
+ error "object-symbol-size: too many arguments"
+ return
+ }
+ if { [llength $args] >= 4 } {
+ switch [dg-process-target [lindex $args 1]] {
+ "S" { }
+ "N" { return }
+ "F" { setup_xfail "*-*-*" }
+ "P" { }
+ }
+ }
+
+ # Find nm like we find g++ in g++.exp.
+ if ![info exists nm] {
+ set nm [findfile $base_dir/../../../binutils/nm \
+ $base_dir/../../../binutils/nm \
+ [findfile $base_dir/../../nm $base_dir/../../nm \
+ [findfile $base_dir/nm $base_dir/nm \
+ [transform nm]]]]
+ verbose -log "nm is $nm"
+ }
+
+ upvar 2 name testcase
+ set testcase [lindex $testcase 0]
+ set output_file "[file rootname [file tail $testcase]].o"
+ set output [remote_exec host "$nm" "-S $output_file"]
+ set status [lindex $output 0]
+ if { $status != 0 } {
+ error "object-symbol-size: $nm failed"
+ return
+ }
+ set text [lindex $output 1]
+
+ set symbol [lindex $args 0]
+ set match [lsearch -all $text $symbol]
+ if { [llength $match] != 1 } {
+ error "object-symbol-size: number of matches for $symbol: [llength $match]"
+ return
+ }
+
+ set type [lindex $text [expr $match - 1]]
+ if ![regexp {^[a-zA-Z\-\?]$} $type] {
+ error "object-symbol-size: type field for $symbol not as expected: $type"
+ return
+ }
+
+ set hex [lindex $text [expr $match - 2]]
+ set actual [expr "0x$hex"]
+ if ![string is integer $actual ] {
+ error "object-symbol-size: size field for $symbol not as expected: $hex"
+ return
+ }
+ verbose -log "$symbol size is $actual"
+
+ set cmp [lindex $args 1]
+ if { [lsearch { < > <= >= == != } $cmp] == -1 } {
+ error "object-symbol-size: illegal argument: $cmp"
+ return
+ }
+
+ set with [lindex $args 2]
+ if ![string is integer $with ] {
+ error "object-symbol-size: illegal argument: $with"
+ return
+ }
+
+ if [expr $actual $cmp $with] {
+ pass "$testcase object-symbol-size $symbol $cmp $with"
+ } else {
+ fail "$testcase object-symbol-size $symbol $cmp $with"
+ }
+}
+
# Utility for testing that a function is defined on the current line.
# Call pass if so, otherwise fail. Invoked directly; the file must
# have been compiled with -g -dA.