Upload Tizen:Base source
[external/binutils.git] / ld / testsuite / ld-scripts / script.exp
1 # Test basic linker script functionality
2 # By Ian Lance Taylor, Cygnus Support
3 #   Copyright 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2010
4 #   Free Software Foundation, Inc.
5 #
6 # This file is part of the GNU Binutils.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 # MA 02110-1301, USA.
22
23 set testname "script"
24
25 if ![ld_assemble $as $srcdir/$subdir/script.s tmpdir/script.o] { 
26     unresolved $testname
27     return
28 }
29
30 proc check_script { } {
31     global nm
32     global testname
33     global nm_output
34
35     if ![ld_nm $nm "" tmpdir/script] {
36         unresolved $testname
37         return
38     } 
39
40     if {![info exists nm_output(text_start)] \
41             || ![info exists nm_output(text_end)] \
42             || ![info exists nm_output(data_start)] \
43             || ![info exists nm_output(data_end)]} {
44         send_log "bad output from nm\n"
45         verbose "bad output from nm"
46         fail $testname
47         return
48     } 
49
50     set passes 1
51     set text_end 0x104
52     set data_end 0x1004
53
54     if [istarget *c4x*-*-*] then {
55         set text_end 0x101
56         set data_end 0x1001
57     }
58
59     if [istarget *c54x*-*-*] then {
60         set text_end 0x102
61         set data_end 0x1002
62     }
63
64     if {$nm_output(text_start) != 0x100} {
65         send_log "text_start == $nm_output(text_start)\n"
66         verbose "text_start == $nm_output(text_start)"
67         set passes 0
68     } 
69
70     if {$nm_output(text_end) < $text_end \
71             || $nm_output(text_end) > 0x110} {
72         send_log "text_end == $nm_output(text_end)\n"
73         verbose "text_end == $nm_output(text_end)"
74         set passes 0
75     } 
76
77     if {$nm_output(data_start) != 0x1000} {
78         send_log "data_start == $nm_output(data_start)\n"
79         verbose "data_start == $nm_output(data_start)"
80         set passes 0
81     } 
82
83     if {$nm_output(data_end) < $data_end \
84             || $nm_output(data_end) > 0x1010} {
85         send_log "data_end == $nm_output(data_end)\n"
86         verbose "data_end == $nm_output(data_end)"
87         set passes 0
88     } 
89
90     if { $passes } {
91         pass $testname
92     } else {
93         fail $testname
94     }
95 }
96
97 # PE targets need to set the image base to 0 to avoid complications from nm.
98 set flags ""
99 if {[istarget "*-*-pe*"] \
100     || [istarget "*-*-cygwin*"] \
101     || [istarget "*-*-mingw*"] \
102     || [istarget "*-*-winnt*"] \
103     || [istarget "*-*-nt"] \
104     || [istarget "*-*-interix*"] } then {
105   set flags "--image-base 0"
106 }
107
108 if ![ld_simple_link $ld tmpdir/script "$flags -T $srcdir/$subdir/script.t tmpdir/script.o"] {
109     fail $testname
110 } else {
111     check_script
112 }
113
114 set testname "MRI script"
115
116 if ![ld_simple_link $ld tmpdir/script "$flags -c $srcdir/$subdir/scriptm.t"] {
117     fail $testname
118 } else {
119     check_script
120 }
121
122 set testname "MEMORY"
123
124 if ![ld_simple_link $ld tmpdir/script "$flags -T $srcdir/$subdir/memory.t tmpdir/script.o"] {
125     fail $testname
126 } else {
127     check_script
128 }
129
130 set test_script_list [lsort [glob $srcdir/$subdir/region-alias-*.t]]
131
132 foreach test_script $test_script_list {
133     set testname [file tail $test_script]
134     if ![ld_simple_link $ld tmpdir/script "$flags -T $test_script tmpdir/script.o"] {
135         xfail "REGION_ALIAS: $testname"
136     } else {
137         xpass "REGION_ALIAS: $testname"
138     }
139 }