1 # Copyright
2009-2024 Free Software Foundation
, Inc.
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.
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.
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
/>.
15 # Contributed by Jan Kratochvil
<jan.kratochvil@redhat.com
>.
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
25 # (wrong library or version mismatch?)
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.
30 require allow_shlib_tests can_spawn_for_attach
33 set libname "solib-overlap-lib"
34 set srcfile_lib ${srcdir}/${subdir}/${libname}.c
36 set testfile "solib-overlap-main"
37 set srcfile ${srcdir}/${subdir}/${testfile}.c
39 # Base addresses for `prelink -r' which should be compatible with both
-m32 and
40 #
-m64 targets.
If it clashes with
system prelinked libraries it would give
42 # Prelink first lib1 at
0x40000000 and lib2 at
0x41000000.
43 # During second pass try lib1 at
0x50000000 and lib2 at
0x51000000.
44 foreach prelink_lib1
{0x40000000 0x50000000} { with_test_prefix
"$prelink_lib1" {
45 set prelink_lib2
[format
"0x%x" [expr $prelink_lib1 + 0x01000000]]
48 set binfile_lib1
[standard_output_file $
{libname
}1-$
{prelink_lib1
}.so
]
49 set binfile_lib1_test_msg OBJDIR
/$
{subdir
}/$
{libname
}1-$
{prelink_lib1
}.so
50 set binfile_lib2
[standard_output_file $
{libname
}2-$
{prelink_lib1
}.so
]
51 set binfile_lib2_test_msg OBJDIR
/$
{subdir
}/$
{libname
}2-$
{prelink_lib1
}.so
54 set binfile_base $
{testfile
}-$
{prelink_lib1
}
55 set binfile
[standard_output_file $
{binfile_base
}]
56 set binfile_test_msg OBJDIR
/$
{subdir
}/$
{binfile_base
}
57 set bin_flags
[list debug shlib
=$
{binfile_lib1
} shlib
=$
{binfile_lib2
}]
58 set escapedbinfile
[string_to_regexp $
{binfile
}]
60 if { [gdb_compile_shlib $
{srcfile_lib
} $
{binfile_lib1
} $lib_flags
] != ""
61 ||
[gdb_compile_shlib $
{srcfile_lib
} $
{binfile_lib2
} $lib_flags
] != ""
62 ||
[gdb_compile $
{srcfile
} $
{binfile
} executable $bin_flags
] != "" } {
63 untested
"failed to compile"
67 if {[catch
"exec prelink -N -r ${prelink_lib1} ${binfile_lib1}" output] != 0
68 ||
[catch
"exec prelink -N -r ${prelink_lib2} ${binfile_lib2}" output] != 0} {
69 # Maybe we don
't have prelink.
70 verbose -log "prelink failed: $output"
71 untested "could not prelink ${binfile_lib1_test_msg} or ${binfile_lib2_test_msg}."
75 set test_spawn_id [spawn_wait_for_attach $binfile]
76 set testpid [spawn_id_get_pid $test_spawn_id]
78 remote_exec build "mv -f ${binfile_lib1} ${binfile_lib1}-running"
79 remote_exec build "mv -f ${binfile_lib2} ${binfile_lib2}-running"
81 # Provide another exported function name to cause different sizes of sections.
82 lappend lib_flags additional_flags=-DSYMB
84 if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib1} $lib_flags] != ""
85 || [gdb_compile_shlib ${srcfile_lib} ${binfile_lib2} $lib_flags] != ""} {
86 untested "failed to compile shared library"
87 kill_wait_spawned_process $test_spawn_id
91 clean_restart ${binfile_base}
92 # This testcase currently does not support remote targets.
93 # gdb_load_shlib ${binfile_lib1}
94 # gdb_load_shlib ${binfile_lib2}
97 # warning: .dynamic section for ".../solib-overlap-lib1.so" is not at the expected address (wrong library or version mismatch?)
98 # warning: .dynamic section for ".../solib-overlap-lib2.so" is not at the expected address (wrong library or version mismatch?)
101 gdb_test_multiple "attach $testpid" $test {
102 -re "Attaching to program.*`?$escapedbinfile'?
, process $testpid.
*$gdb_prompt $
" {
105 -re
"Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
106 # Response expected
on Cygwin
111 # Detach the process.
113 gdb_test
"detach" "Detaching from program: .*$escapedbinfile, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
115 # Wait a bit
for gdb to finish detaching
119 kill_wait_spawned_process $test_spawn_id