c12f962c1614fda638b3adb663583f3b3a7c0b82
[binutils-gdb.git] / gdb / testsuite / gdb.base / prelink.exp
1 # Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@gnu.org
18
19 # This file was written by Alexandre Oliva <aoliva@redhat.com>
20
21 if $tracelevel then {
22 strace $tracelevel
23 }
24
25
26 # are we on a target board
27 if ![isnative] then {
28 return
29 }
30
31 if [get_compiler_info "ignored"] {
32 return -1
33 }
34
35 if {$gcc_compiled == 0} {
36 return -1
37 }
38
39 set testfile "prelink"
40
41 set libsrcfile ${testfile}-lib.c
42 set libfile ${objdir}/${subdir}/${testfile}.so
43 if { [gdb_compile "${srcdir}/${subdir}/${libsrcfile}" "${libfile}" executable [list debug "additional_flags=-fpic -shared -nodefaultlibs"]] != ""} {
44 # If creating the shared library fails, maybe we don't have the right tools
45 return -1
46 }
47
48 # `--no-exec-shield' is for i386 where prelink in the exec-shield mode is
49 # forced to push all the libraries tight together to fit into the first two
50 # memory areas (either the ASCII Shield area or at least below the executable).
51 # In this case its -R option cannot be applied and we falsely FAIL here as if
52 # the system is already prelinked prelink has no choice how to randomize the
53 # single new unprelinked library address without wasting the first one/two
54 # memory areas. We do not care of the efficiency of loading such resulting
55 # exec-shield unfriendly prelinked library.
56 if {[catch "system \"prelink -qNR --no-exec-shield ${libfile}\""] != 0} {
57 # Maybe we don't have prelink.
58 return -1
59 }
60
61 set srcfile ${testfile}.c
62 set binfile ${objdir}/${subdir}/${testfile}t
63 if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${libfile}" "${binfile}" executable [list debug "additional_flags=-Wl,-rpath,${objdir}/${subdir}"]] != ""} {
64 return -1;
65 }
66
67 set found 0
68 set coredir "${objdir}/${subdir}/coredir.[getpid]"
69 file mkdir $coredir
70 catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
71
72 foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
73 if [remote_file build exists $i] {
74 remote_exec build "mv $i ${objdir}/${subdir}/prelink.core"
75 set found 1
76 }
77 }
78 # Check for "core.PID".
79 if { $found == 0 } {
80 set names [glob -nocomplain -directory $coredir core.*]
81 if {[llength $names] == 1} {
82 set corefile [file join $coredir [lindex $names 0]]
83 remote_exec build "mv $corefile ${objdir}/${subdir}/prelink.core"
84 set found 1
85 }
86 }
87
88 # Try to clean up after ourselves.
89 remote_file build delete [file join $coredir coremmap.data]
90 remote_exec build "rmdir $coredir"
91
92 if { $found == 0 } {
93 warning "can't generate a core file - prelink tests suppressed - check ulimit -c"
94 return 0
95 }
96
97 if {[catch "system \"prelink -uN ${libfile}\""] != 0} {
98 untested "${testfile}.so was not prelinked, maybe system libraries are not prelinked?"
99 return 0
100 }
101 catch "system \"prelink -qNR --no-exec-shield ${libfile}\""
102
103 # Start with a fresh gdb
104
105 gdb_exit
106 gdb_start
107 gdb_reinitialize_dir $srcdir/$subdir
108 gdb_load ${binfile}
109
110 # Print the "adjusting expectations" message.
111 gdb_test "set verbose on"
112
113 gdb_test "core-file $objdir/$subdir/prelink.core" {Using PIC \(Position Independent Code\) prelink displacement.*} "prelink"