Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2009-2020 Free Software Foundation, Inc. |
817aadd2 JK |
2 | # This program is free software; you can redistribute it and/or modify |
3 | # it under the terms of the GNU General Public License as published by | |
4 | # the Free Software Foundation; either version 3 of the License, or | |
5 | # (at your option) any later version. | |
6 | # | |
7 | # This program is distributed in the hope that it will be useful, | |
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | # GNU General Public License for more details. | |
11 | # | |
12 | # You should have received a copy of the GNU General Public License | |
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | # | |
15 | # Contributed by Jan Kratochvil <jan.kratochvil@redhat.com>. | |
16 | ||
17 | # Test GDB can cope with two libraries loaded with overlapping VMA ranges. | |
18 | # Prelink libraries first so they can be loaded and their native address. | |
19 | # In such case `struct linkmap'.l_addr will be zero. Provide different | |
20 | # unprelinked library files on the disk which have zero-based VMAs. These | |
21 | # different files should have their .dynamic section at a different offset in | |
22 | # page size so that we get for | |
23 | # warning: .dynamic section for "..." is not at the expected address | |
24 | # the reason | |
25 | # (wrong library or version mismatch?) | |
26 | # and not: | |
27 | # difference appears to be caused by prelink, adjusting expectations | |
28 | # In such case both disk libraries will be loaded at VMAs starting at zero. | |
29 | ||
30 | if [skip_shlib_tests] { | |
31 | return 0 | |
32 | } | |
33 | ||
60b3033e | 34 | if {![can_spawn_for_attach]} { |
817aadd2 JK |
35 | return 0 |
36 | } | |
37 | ||
4c93b1db | 38 | if [get_compiler_info] { |
ae59b1da | 39 | return -1 |
817aadd2 JK |
40 | } |
41 | ||
42 | # Library file. | |
43 | set libname "solib-overlap-lib" | |
44 | set srcfile_lib ${srcdir}/${subdir}/${libname}.c | |
45 | # Binary file. | |
46 | set testfile "solib-overlap-main" | |
47 | set srcfile ${srcdir}/${subdir}/${testfile}.c | |
48 | ||
49 | # Base addresses for `prelink -r' which should be compatible with both -m32 and | |
50 | # -m64 targets. If it clashes with system prelinked libraries it would give | |
51 | # false PASS. | |
52 | # Prelink first lib1 at 0x40000000 and lib2 at 0x41000000. | |
53 | # During second pass try lib1 at 0x50000000 and lib2 at 0x51000000. | |
0f4d39d5 | 54 | foreach prelink_lib1 {0x40000000 0x50000000} { with_test_prefix "$prelink_lib1" { |
817aadd2 JK |
55 | set prelink_lib2 [format "0x%x" [expr $prelink_lib1 + 0x01000000]] |
56 | ||
817aadd2 | 57 | # Library file. |
0ab77f5f | 58 | set binfile_lib1 [standard_output_file ${libname}1-${prelink_lib1}.so] |
a449c2d8 | 59 | set binfile_lib1_test_msg OBJDIR/${subdir}/${libname}1-${prelink_lib1}.so |
0ab77f5f | 60 | set binfile_lib2 [standard_output_file ${libname}2-${prelink_lib1}.so] |
a449c2d8 | 61 | set binfile_lib2_test_msg OBJDIR/${subdir}/${libname}2-${prelink_lib1}.so |
817aadd2 JK |
62 | set lib_flags {debug} |
63 | # Binary file. | |
64 | set binfile_base ${testfile}-${prelink_lib1} | |
0ab77f5f | 65 | set binfile [standard_output_file ${binfile_base}] |
a449c2d8 | 66 | set binfile_test_msg OBJDIR/${subdir}/${binfile_base} |
817aadd2 JK |
67 | set bin_flags [list debug shlib=${binfile_lib1} shlib=${binfile_lib2}] |
68 | set escapedbinfile [string_to_regexp ${binfile}] | |
69 | ||
70 | if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib1} $lib_flags] != "" | |
71 | || [gdb_compile_shlib ${srcfile_lib} ${binfile_lib2} $lib_flags] != "" | |
72 | || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } { | |
84c93cd5 | 73 | untested "failed to compile" |
817aadd2 JK |
74 | return -1 |
75 | } | |
76 | ||
86cbc5dc TV |
77 | if {[catch "exec prelink -N -r ${prelink_lib1} ${binfile_lib1}" output] != 0 |
78 | || [catch "exec prelink -N -r ${prelink_lib2} ${binfile_lib2}" output] != 0} { | |
817aadd2 | 79 | # Maybe we don't have prelink. |
86cbc5dc | 80 | verbose -log "prelink failed: $output" |
bc6c7af4 | 81 | untested "could not prelink ${binfile_lib1_test_msg} or ${binfile_lib2_test_msg}." |
817aadd2 JK |
82 | return -1 |
83 | } | |
84 | ||
2c8c5d37 PA |
85 | set test_spawn_id [spawn_wait_for_attach $binfile] |
86 | set testpid [spawn_id_get_pid $test_spawn_id] | |
817aadd2 JK |
87 | |
88 | remote_exec build "mv -f ${binfile_lib1} ${binfile_lib1}-running" | |
89 | remote_exec build "mv -f ${binfile_lib2} ${binfile_lib2}-running" | |
90 | ||
91 | # Provide another exported function name to cause different sizes of sections. | |
92 | lappend lib_flags additional_flags=-DSYMB | |
93 | ||
94 | if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib1} $lib_flags] != "" | |
95 | || [gdb_compile_shlib ${srcfile_lib} ${binfile_lib2} $lib_flags] != ""} { | |
84c93cd5 | 96 | untested "failed to compile shared library" |
2c8c5d37 | 97 | kill_wait_spawned_process $test_spawn_id |
817aadd2 JK |
98 | return -1 |
99 | } | |
100 | ||
101 | clean_restart ${binfile_base} | |
102 | # This testcase currently does not support remote targets. | |
d9019901 SM |
103 | # gdb_load_shlib ${binfile_lib1} |
104 | # gdb_load_shlib ${binfile_lib2} | |
817aadd2 JK |
105 | |
106 | # Here we should get: | |
107 | # warning: .dynamic section for ".../solib-overlap-lib1.so" is not at the expected address (wrong library or version mismatch?) | |
108 | # warning: .dynamic section for ".../solib-overlap-lib2.so" is not at the expected address (wrong library or version mismatch?) | |
109 | ||
110 | set test attach | |
111 | gdb_test_multiple "attach $testpid" $test { | |
112 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" { | |
113 | pass $test | |
114 | } | |
115 | -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" { | |
116 | # Response expected on Cygwin | |
117 | pass $test | |
118 | } | |
119 | } | |
120 | ||
121 | # Detach the process. | |
122 | ||
f67c0c91 | 123 | gdb_test "detach" "Detaching from program: .*$escapedbinfile, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]" |
817aadd2 JK |
124 | |
125 | # Wait a bit for gdb to finish detaching | |
126 | ||
127 | sleep 5 | |
128 | ||
2c8c5d37 | 129 | kill_wait_spawned_process $test_spawn_id |
6a5870ce | 130 | }} |