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