On 04/04/2011 02:22 PM, Rainer Orth wrote:
> Richard Guenther <richard.guent...@gmail.com> writes:
> 
>> On Sun, Apr 3, 2011 at 9:34 PM, Sergey Ostanevich <sergos....@gmail.com> 
>> wrote:
>>> I would recommend to use 'nm -S a.out' that gives
>>>
>>> [...]
>>> 00000000004004a4 0000000000000054 T main
>>> [...]
>>>
>>> then you can provide a name for the routine you want to test for the size.
>>
>> That also sounds reasonable.  Is nm -S more portable than size?
> 
> Neither Solaris nor IRIX nm have it.  size isn't particularly portable,
> either: there are many variations in output format.
> 
>       Rainer
> 

In case we ever need it, here's a patch to access nm -S.

Thanks,
- Tom
2011-04-05  Tom de Vries  <t...@codesourcery.com>

	* lib/scanasm.exp (object-symbol-size): New proc.
Index: gcc/testsuite/lib/scanasm.exp
===================================================================
--- gcc/testsuite/lib/scanasm.exp (revision 170556)
+++ gcc/testsuite/lib/scanasm.exp (working copy)
@@ -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.

Reply via email to