2018-01-01 05:43:02 +01:00
|
|
|
# Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
2003-06-09 23:23:53 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-08-23 20:14:19 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2003-06-09 23:23:53 +02:00
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-08-23 20:14:19 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-06-09 23:23:53 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
# Tests for shared object file relocation. If two shared objects have
|
|
|
|
# the same load address (actually, overlapping load spaces), one of
|
|
|
|
# them gets relocated at load-time. Check that gdb gets the right
|
|
|
|
# values for the debugging and minimal symbols.
|
|
|
|
|
2007-05-16 16:21:47 +02:00
|
|
|
if {[skip_shlib_tests]} {
|
2003-11-11 18:58:28 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2003-06-09 23:23:53 +02:00
|
|
|
#
|
|
|
|
# This file uses shreloc.c, shreloc1.c and shreloc2.c
|
|
|
|
#
|
|
|
|
|
|
|
|
|
test suite update - gdb.base/s*
Convert files gdb.base/s*.exp to use standard_output_file et al.
* gdb.base/save-bp.exp, gdb.base/savedregs.exp,
gdb.base/scope.exp, gdb.base/sep.exp, gdb.base/sepsymtab.exp,
gdb.base/set-lang-auto.exp, gdb.base/setshow.exp,
gdb.base/setvar.exp, gdb.base/shlib-call.exp,
gdb.base/shreloc.exp, gdb.base/sigall.exp,
gdb.base/sigaltstack.exp, gdb.base/sigbpt.exp,
gdb.base/sigchld.exp, gdb.base/siginfo-addr.exp,
gdb.base/siginfo-infcall.exp, gdb.base/siginfo-obj.exp,
gdb.base/siginfo.exp, gdb.base/signals.exp, gdb.base/signest.exp,
gdb.base/signull.exp, gdb.base/sigrepeat.exp,
gdb.base/sigstep.exp, gdb.base/sizeof.exp,
gdb.base/skip-solib.exp, gdb.base/so-impl-ld.exp,
gdb.base/solib-display.exp, gdb.base/solib-nodir.exp,
gdb.base/solib-overlap.exp, gdb.base/solib-symbol.exp,
gdb.base/solib-weak.exp, gdb.base/source.exp,
gdb.base/stack-checking.exp, gdb.base/stale-infcall.exp,
gdb.base/stap-probe.exp, gdb.base/start.exp,
gdb.base/step-break.exp, gdb.base/step-bt.exp,
gdb.base/step-line.exp, gdb.base/step-resume-infcall.exp,
gdb.base/step-test.exp, gdb.base/structs.exp,
gdb.base/structs2.exp, gdb.base/structs3.exp,
gdb.base/symbol-without-target_section.exp: Use standard_testfile,
standard_output_file, prepare_for_testing, clean_restart.
2013-06-27 20:58:28 +02:00
|
|
|
standard_testfile .c shreloc1.c shreloc2.c
|
|
|
|
|
|
|
|
set srcfile $srcdir/$subdir/$srcfile
|
|
|
|
set lib1src $srcdir/$subdir/$srcfile2
|
|
|
|
set lib2src $srcdir/$subdir/$srcfile3
|
|
|
|
set binfile [standard_output_file $testfile]
|
|
|
|
set lib1_sl [standard_output_file shreloc1.sl]
|
|
|
|
set lib2_sl [standard_output_file shreloc2.sl]
|
2005-05-18 03:38:46 +02:00
|
|
|
|
2012-06-21 22:46:25 +02:00
|
|
|
if [get_compiler_info] {
|
2005-05-18 03:38:46 +02:00
|
|
|
return -1
|
2003-06-09 23:23:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-18 03:38:46 +02:00
|
|
|
set lib_opts "debug"
|
|
|
|
set exec_opts [list debug shlib=$lib1_sl shlib=$lib2_sl]
|
2003-06-09 23:23:53 +02:00
|
|
|
|
|
|
|
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
|
2007-01-04 00:06:29 +01:00
|
|
|
lappend lib_opts "ldflags=-Wl,--image-base,0x04000000"
|
2003-06-09 23:23:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-18 03:38:46 +02:00
|
|
|
if [test_compiler_info "xlc-*"] {
|
|
|
|
|
|
|
|
# IBM's xlc compiler does not add static variables to the ELF symbol
|
|
|
|
# table by default. We need this option to make the variables show
|
|
|
|
# up in "maint print msymbols".
|
|
|
|
|
|
|
|
lappend lib_opts "additional_flags=-qstatsym"
|
|
|
|
|
2003-06-09 23:23:53 +02:00
|
|
|
}
|
|
|
|
|
2005-05-18 03:38:46 +02:00
|
|
|
if { [gdb_compile_shlib $lib1src $lib1_sl $lib_opts] != ""} {
|
2016-12-01 21:40:05 +01:00
|
|
|
untested "could not build $lib1_sl."
|
2005-05-18 03:38:46 +02:00
|
|
|
return -1
|
|
|
|
} elseif { [gdb_compile_shlib $lib2src $lib2_sl $lib_opts] != ""} {
|
2016-12-01 21:40:05 +01:00
|
|
|
untested "could not build $lib1_s2."
|
2005-05-18 03:38:46 +02:00
|
|
|
return -1
|
|
|
|
} elseif { [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
|
2016-12-01 21:40:05 +01:00
|
|
|
untested "could not build $binfile."
|
2003-06-09 23:23:53 +02:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2005-05-18 03:38:46 +02:00
|
|
|
# Start with a fresh gdb.
|
|
|
|
|
test suite update - gdb.base/s*
Convert files gdb.base/s*.exp to use standard_output_file et al.
* gdb.base/save-bp.exp, gdb.base/savedregs.exp,
gdb.base/scope.exp, gdb.base/sep.exp, gdb.base/sepsymtab.exp,
gdb.base/set-lang-auto.exp, gdb.base/setshow.exp,
gdb.base/setvar.exp, gdb.base/shlib-call.exp,
gdb.base/shreloc.exp, gdb.base/sigall.exp,
gdb.base/sigaltstack.exp, gdb.base/sigbpt.exp,
gdb.base/sigchld.exp, gdb.base/siginfo-addr.exp,
gdb.base/siginfo-infcall.exp, gdb.base/siginfo-obj.exp,
gdb.base/siginfo.exp, gdb.base/signals.exp, gdb.base/signest.exp,
gdb.base/signull.exp, gdb.base/sigrepeat.exp,
gdb.base/sigstep.exp, gdb.base/sizeof.exp,
gdb.base/skip-solib.exp, gdb.base/so-impl-ld.exp,
gdb.base/solib-display.exp, gdb.base/solib-nodir.exp,
gdb.base/solib-overlap.exp, gdb.base/solib-symbol.exp,
gdb.base/solib-weak.exp, gdb.base/source.exp,
gdb.base/stack-checking.exp, gdb.base/stale-infcall.exp,
gdb.base/stap-probe.exp, gdb.base/start.exp,
gdb.base/step-break.exp, gdb.base/step-bt.exp,
gdb.base/step-line.exp, gdb.base/step-resume-infcall.exp,
gdb.base/step-test.exp, gdb.base/structs.exp,
gdb.base/structs2.exp, gdb.base/structs3.exp,
gdb.base/symbol-without-target_section.exp: Use standard_testfile,
standard_output_file, prepare_for_testing, clean_restart.
2013-06-27 20:58:28 +02:00
|
|
|
clean_restart $binfile
|
2016-04-28 00:08:59 +02:00
|
|
|
gdb_load_shlib $lib1_sl
|
|
|
|
gdb_load_shlib $lib2_sl
|
2003-06-09 23:23:53 +02:00
|
|
|
|
|
|
|
# Load up the shared objects
|
|
|
|
if ![runto_main] then {
|
2016-12-01 21:40:05 +01:00
|
|
|
fail "can't run to main"
|
2003-06-09 23:23:53 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check debugging symbol relocations
|
|
|
|
#
|
|
|
|
|
|
|
|
# Check extern function for relocation
|
|
|
|
set fn_1_addr [get_var_address fn_1]
|
|
|
|
set fn_2_addr [get_var_address fn_2]
|
|
|
|
|
|
|
|
if { "${fn_1_addr}" == "${fn_2_addr}" } {
|
|
|
|
fail "relocated extern functions have different addresses"
|
|
|
|
} else {
|
|
|
|
pass "relocated extern functions have different addresses"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check extern var for relocation
|
|
|
|
set extern_var_1_addr [get_var_address extern_var_1]
|
|
|
|
set extern_var_2_addr [get_var_address extern_var_2]
|
|
|
|
|
|
|
|
if { "${extern_var_1_addr}" == "${extern_var_2_addr}" } {
|
|
|
|
fail "relocated extern variables have different addresses"
|
|
|
|
} else {
|
|
|
|
pass "relocated extern variables have different addresses"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check static var for relocation
|
|
|
|
set static_var_1_addr [get_var_address static_var_1]
|
|
|
|
set static_var_2_addr [get_var_address static_var_2]
|
|
|
|
|
|
|
|
if { "${static_var_1_addr}" == "${static_var_2_addr}" } {
|
|
|
|
fail "relocated static variables have different addresses"
|
|
|
|
} else {
|
|
|
|
pass "relocated static variables have different addresses"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check minimal symbol relocations
|
|
|
|
#
|
|
|
|
|
|
|
|
proc send_gdb_discard { command } {
|
|
|
|
# Send a command to gdb and discard output up to the next prompt
|
|
|
|
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
# Discard output
|
2010-05-28 01:44:51 +02:00
|
|
|
gdb_test_multiple "${command}" "${command}" {
|
2003-06-09 23:23:53 +02:00
|
|
|
-re ".*\[\r\n]+${gdb_prompt} $" {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "{$command} (timeout)"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc get_msym_addrs { var msymfile } {
|
|
|
|
# Extract the list of values for symbols matching var in the
|
|
|
|
# minimal symbol output file
|
|
|
|
|
|
|
|
global gdb_prompt hex
|
|
|
|
set result ""
|
|
|
|
|
|
|
|
send_gdb "shell grep -E \" ${var}(\[ \t\]+.*)?\$\" ${msymfile}\n"
|
|
|
|
|
|
|
|
while 1 {
|
|
|
|
gdb_expect {
|
|
|
|
-re "\[\[\]\[ 0-9\]+\] . (${hex}) ${var}(\[ \t\]+\[^\r\n\]*)?\[\r\n\]+" {
|
|
|
|
set result [concat $result $expect_out(1,string)]
|
|
|
|
}
|
|
|
|
|
|
|
|
-re "$gdb_prompt $" {
|
2006-02-19 21:53:34 +01:00
|
|
|
pass "get_msym_addrs ${var}"
|
2003-06-09 23:23:53 +02:00
|
|
|
return "${result}"
|
|
|
|
}
|
|
|
|
|
|
|
|
-re "\[^\r\n\]*\[\r\n\]+" {
|
|
|
|
# Skip
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout {
|
|
|
|
fail "get_msym_addrs ${var} (timeout)"
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc check_same {var msymfile} {
|
|
|
|
# Check that the minimal symbol values matching var are the same
|
|
|
|
|
|
|
|
set len [llength [lsort -unique [get_msym_addrs "${var}" "${msymfile}"]]]
|
|
|
|
|
|
|
|
if { $len == 1 } {
|
|
|
|
return 1
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc check_different {var msymfile} {
|
|
|
|
# Check that the minimal symbol values matching var are different
|
|
|
|
|
|
|
|
set addr_list [lsort [get_msym_addrs "${var}" "${msymfile}"]]
|
|
|
|
set prev ""
|
|
|
|
|
|
|
|
if { [llength ${addr_list}] < 2 } {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach addr ${addr_list} {
|
|
|
|
if { ${prev} == ${addr} } {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
set prev ${addr}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-09-29 16:05:36 +02:00
|
|
|
if [is_remote host] {
|
|
|
|
set msymfile shreloc.txt
|
|
|
|
} else {
|
|
|
|
set msymfile [standard_output_file shreloc.txt]
|
|
|
|
}
|
2003-06-09 23:23:53 +02:00
|
|
|
|
|
|
|
if [send_gdb_discard "maint print msymbols ${msymfile}"] {
|
|
|
|
if {[check_different "static_var_\[12\]" "${msymfile}"]} {
|
|
|
|
pass "(msymbol) relocated static vars have different addresses"
|
|
|
|
} else {
|
|
|
|
fail "(msymbol) relocated static vars have different addresses"
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[check_different "extern_var_\[12\]" "${msymfile}"]} {
|
|
|
|
pass "(msymbol) relocated extern vars have different addresses"
|
|
|
|
} else {
|
|
|
|
fail "(msymbol) relocated extern vars have different addresses"
|
|
|
|
}
|
|
|
|
|
|
|
|
if {[check_different "fn_\[12\]" "${msymfile}"]} {
|
|
|
|
pass "(msymbol) relocated functions have different addresses"
|
|
|
|
} else {
|
|
|
|
fail "(msymbol) relocated functions have different addresses"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
|
|
|
|
#
|
|
|
|
# We know the names of some absolute symbols included in the
|
|
|
|
# portable-executable (DLL) format. Check that they didn't get
|
|
|
|
# relocated.
|
|
|
|
#
|
|
|
|
# A better approach would be include absolute symbols via the assembler.
|
|
|
|
#
|
|
|
|
if {[check_same "_minor_os_version__" "${msymfile}"]} {
|
2016-12-01 21:40:05 +01:00
|
|
|
pass "absolute symbols not relocated"
|
2003-06-09 23:23:53 +02:00
|
|
|
} else {
|
2016-12-01 21:40:05 +01:00
|
|
|
fail "absolute symbols not relocated"
|
2003-06-09 23:23:53 +02:00
|
|
|
}
|
|
|
|
}
|