1 # Copyright 2006-2019 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 3 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, see <http://www.gnu.org/licenses/>.
16 # Please email any bugs, comments, and/or additions to this file to:
19 # This file was written by Alexandre Oliva <aoliva@redhat.com>
22 if { ![isnative] || [is_remote host] || [skip_shlib_tests]} {
26 if [get_compiler_info] {
30 if {$gcc_compiled == 0} {
34 load_lib prelink-support.exp
36 set testfile "prelink"
38 set libsrcfile ${testfile}-lib.c
39 set libfile [standard_output_file ${testfile}.so]
41 # Use -soname so that the new library gets copied by build_executable_own_libs.
43 if { [gdb_compile_shlib "${srcdir}/${subdir}/${libsrcfile}" "${libfile}" [list debug "ldflags=-Wl,-soname,[file tail ${libfile}]"]] != ""} {
44 # If creating the shared library fails, maybe we don't have the right tools
48 set srcfile ${testfile}.c
49 set executable ${testfile}t
50 set binfile [standard_output_file ${executable}]
51 set prelink_args [build_executable_own_libs ${testfile}.exp $executable $srcfile [list debug "ldflags=-Wl,${libfile},-rpath,[file dirname ${libfile}]"]]
52 if {$prelink_args == ""} {
56 set test "split debug of executable"
57 if [gdb_gnu_strip_debug $binfile] {
63 if ![prelink_yes $prelink_args] {
64 # Maybe we don't have prelink.
69 set coredir "[standard_output_file coredir.[getpid]]"
71 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
73 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
74 if [remote_file build exists $i] {
75 remote_exec build "mv $i [standard_output_file prelink.core]"
79 # Check for "core.PID".
81 set names [glob -nocomplain -directory $coredir core.*]
82 if {[llength $names] == 1} {
83 set corefile [file join $coredir [lindex $names 0]]
84 remote_exec build "mv $corefile [standard_output_file prelink.core]"
89 # Try to clean up after ourselves.
90 remote_file build delete [file join $coredir coremmap.data]
91 remote_exec build "rmdir $coredir"
94 warning "can't generate a core file - prelink tests suppressed - check ulimit -c"
98 # Relink $libfile to a different address.
99 if ![prelink_yes $prelink_args] {
103 # Start with a fresh gdb
105 clean_restart $executable
107 # Print the "adjusting expectations" message.
108 gdb_test_no_output "set verbose on"
110 gdb_test "core-file [standard_output_file prelink.core]" "Using PIC \\(Position Independent Code\\) prelink displacement 0x\[^0\]\[0-9a-f\]* for \[^\r\n\]*[file tail ${libfile}].*" "seen displacement message"
112 gdb_test "p &bssvar == bssvarp" " = 1" ".dynbss vs. .bss address shift"