1 # Copyright
(C
) 2003, 2005 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
2 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program; if not
, write to the Free Software
15 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
18 # Tests
for shared object file relocation.
If two shared objects have
19 # the same
load address
(actually
, overlapping
load spaces
), one of
20 # them gets relocated at
load-time. Check that gdb gets the right
21 #
values for the debugging and minimal symbols.
23 if {[istarget
*-elf
*] ||
[istarget
*-coff
] ||
[istarget
*-aout
]} then {
24 verbose
"test skipped - shared object files not supported by this target."
33 # This file uses shreloc.c
, shreloc1.c and shreloc2.c
39 set workdir $
{objdir
}/$
{subdir
}
40 set testfile
"shreloc"
41 set libfile1
"shreloc1"
42 set libfile2
"shreloc2"
43 set srcfile $srcdir
/$subdir
/$testfile.c
44 set lib1src $srcdir
/$subdir
/$libfile1.c
45 set lib2src $srcdir
/$subdir
/$libfile2.c
46 set binfile $objdir
/$subdir
/$testfile
47 set lib1_sl $objdir
/$subdir
/$libfile1.sl
48 set lib2_sl $objdir
/$subdir
/$libfile2.sl
50 if [get_compiler_info $
{binfile
}] {
55 set exec_opts
[list debug shlib
=$lib1_sl shlib
=$lib2_sl
]
57 if {([istarget
"*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
58 lappend lib_opts
"additional_flags=-Wl,--image-base,0x04000000"
61 if [test_compiler_info
"xlc-*"] {
63 # IBM
's xlc compiler does not add static variables to the ELF symbol
64 # table by default. We need this option to make the variables show
65 # up in "maint print msymbols".
67 lappend lib_opts "additional_flags=-qstatsym"
71 if { [gdb_compile_shlib $lib1src $lib1_sl $lib_opts] != ""} {
72 untested "Could not build $lib1_sl."
74 } elseif { [gdb_compile_shlib $lib2src $lib2_sl $lib_opts] != ""} {
75 untested "Could not build $lib1_s2."
77 } elseif { [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
78 untested "Could not build $binfile."
82 # Start with a fresh gdb.
86 gdb_reinitialize_dir $srcdir/$subdir
87 gdb_load ${workdir}/shreloc
89 # Load up the shared objects
90 if ![runto_main] then {
91 fail "Can't run to main
"
95 proc get_var_address
{ var
} {
98 send_gdb
"print &${var}\n"
102 # $
6 = (int (*)()) 0x24 <function_bar
>
104 -re
"\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
106 pass
"get address of ${var}"
107 if { $expect_out
(1,string
) == "0" } {
110 return $expect_out
(1,string
)
113 -re
"${gdb_prompt} $"
114 { fail
"get address of ${var} (unknown output)" }
116 { fail
"get address of ${var} (timeout)" }
122 # Check debugging symbol relocations
125 # Check extern function
for relocation
126 set fn_1_addr
[get_var_address fn_1
]
127 set fn_2_addr
[get_var_address fn_2
]
129 if { "${fn_1_addr}" == "${fn_2_addr}" } {
130 fail
"relocated extern functions have different addresses"
132 pass
"relocated extern functions have different addresses"
135 # Check extern var
for relocation
136 set extern_var_1_addr
[get_var_address extern_var_1
]
137 set extern_var_2_addr
[get_var_address extern_var_2
]
139 if { "${extern_var_1_addr}" == "${extern_var_2_addr}" } {
140 fail
"relocated extern variables have different addresses"
142 pass
"relocated extern variables have different addresses"
145 # Check static var
for relocation
146 set static_var_1_addr
[get_var_address static_var_1
]
147 set static_var_2_addr
[get_var_address static_var_2
]
149 if { "${static_var_1_addr}" == "${static_var_2_addr}" } {
150 fail
"relocated static variables have different addresses"
152 pass
"relocated static variables have different addresses"
156 # Check minimal symbol relocations
159 proc send_gdb_discard
{ command
} {
160 # Send a command to gdb and discard output up to the next prompt
164 send_gdb
"${command}\n"
168 -re
".*\[\r\n]+${gdb_prompt} $" {
172 fail
"{$command} (timeout)"
178 proc get_msym_addrs
{ var msymfile
} {
179 # Extract the list of
values for symbols matching var in the
180 # minimal symbol output file
182 global gdb_prompt hex
185 send_gdb
"shell grep -E \" ${var}(\[ \t\]+.*)?\$\" ${msymfile}\n"
189 -re
"\[\[\]\[ 0-9\]+\] . (${hex}) ${var}(\[ \t\]+\[^\r\n\]*)?\[\r\n\]+" {
190 set result
[concat $result $expect_out
(1,string
)]
193 -re
"$gdb_prompt $" {
194 pass
"get_msym_addrs ${var}"
198 -re
"\[^\r\n\]*\[\r\n\]+" {
203 fail
"get_msym_addrs ${var} (timeout)"
210 proc check_same
{var msymfile
} {
211 # Check that the minimal symbol
values matching var are the same
213 set len
[llength
[lsort
-unique
[get_msym_addrs
"${var}" "${msymfile}"]]]
222 proc check_different
{var msymfile
} {
223 # Check that the minimal symbol
values matching var are different
225 set addr_list
[lsort
[get_msym_addrs
"${var}" "${msymfile}"]]
228 if { [llength $
{addr_list
}] < 2 } {
232 foreach addr $
{addr_list
} {
233 if { $
{prev
} == $
{addr
} } {
242 set msymfile
"${workdir}/shreloc.txt"
244 if [send_gdb_discard
"maint print msymbols ${msymfile}"] {
245 if {[check_different
"static_var_\[12\]" "${msymfile}"]} {
246 pass
"(msymbol) relocated static vars have different addresses"
248 fail
"(msymbol) relocated static vars have different addresses"
251 if {[check_different
"extern_var_\[12\]" "${msymfile}"]} {
252 pass
"(msymbol) relocated extern vars have different addresses"
254 fail
"(msymbol) relocated extern vars have different addresses"
257 if {[check_different
"fn_\[12\]" "${msymfile}"]} {
258 pass
"(msymbol) relocated functions have different addresses"
260 fail
"(msymbol) relocated functions have different addresses"
264 if {([istarget
"*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
266 # We know the names of some absolute symbols included in the
267 # portable
-executable
(DLL
) format. Check that they didn
't get
270 # A better approach would be include absolute symbols via the assembler.
272 if {[check_same "_minor_os_version__" "${msymfile}"]} {
273 pass "Absolute symbols not relocated"
275 fail "Absolute symbols not relocated"