Patchwork [PR43920,1/9] ARM specific part.

login
register
mail settings
Submitter Tom de Vries
Date April 5, 2011, 1:35 p.m.
Message ID <4D9B1A9D.50605@codesourcery.com>
Download mbox | patch
Permalink /patch/89863/
State New
Headers show

Comments

Tom de Vries - April 5, 2011, 1:35 p.m.
On 04/04/2011 02:22 PM, Rainer Orth wrote:
> Richard Guenther <richard.guenther@gmail.com> writes:
> 
>> On Sun, Apr 3, 2011 at 9:34 PM, Sergey Ostanevich <sergos.gnu@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
Rainer Orth - May 3, 2011, 6:18 p.m.
Tom,

>>> 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.
[...]
> In case we ever need it, here's a patch to access nm -S.

sorry for the very late response, but a couple of comments.

> +# Call pass if symbol size is ok, otherwise fail.
> +# example: /* { dg-final { object-symbol-size main <= 54 } } */
> +proc object-symbol-size { args } {

This needs to be documented in doc/sourcebuild.texi (Final Actions).  We
made a concerted effort to document the testsuite and should keep it
that way.

> +    # 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"
> +    }

Please move this to a separate proc like gnat.exp (find_gnatclean).

> +    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
> +    }

As I said, nm -S is completely unportable.  I'd rather at least try if
we can cope with the differences in size output format instead, or
use a hook here that allows to use different implementations.

Thanks for doing this.

	Rainer

Patch

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.