1 # Copyright (C) 2009, 2010, 2011 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 if {[skip_shlib_tests]} {
20 set testfile "gnu-ifunc"
21 set executable ${testfile}
22 set srcfile ${testfile}.c
23 set binfile ${objdir}/${subdir}/${executable}
24 set staticexecutable ${executable}-static
25 set staticbinfile ${objdir}/${subdir}/${staticexecutable}
27 set libfile "${testfile}-lib"
28 set libsrc ${libfile}.c
29 set lib_so ${objdir}/${subdir}/${libfile}.so
30 # $lib_o must not have {debug}, it would override the STT_GNU_IFUNC ELF markers.
31 set lib_o ${objdir}/${subdir}/${libfile}.o
33 # We need DWARF for the "final" function as we "step" into the function and GDB
34 # would step-over the "final" function if there would be no line number debug
35 # information (DWARF) available.
37 # We must not have DWARF for the "gnu_ifunc" function as DWARF has no way to
38 # express the STT_GNU_IFUNC type and it would be considered as a regular
39 # function due to DWARF by GDB. In ELF gnu-ifunc is expressed by the
42 # Both functions need to be in the same shared library file but
43 # gdb_compile_shlib has no way to specify source-specific compilation options.
45 # Therefore $libfile contains only the STT_GNU_IFUNC function with no DWARF
46 # referencing all the other parts from the main executable with DWARF.
49 set exec_opts [list debug shlib=$lib_so]
51 if [get_compiler_info ${binfile}] {
55 if { [gdb_compile_shlib ${srcdir}/${subdir}/$libsrc $lib_so $lib_opts] != ""
56 || [gdb_compile ${srcdir}/${subdir}/$srcfile $binfile executable $exec_opts] != ""} {
57 untested "Could not compile dynamic executable $binfile."
61 # Start with a fresh gdb.
63 clean_restart $executable
64 gdb_load_shlibs ${lib_so}
66 if ![runto_main] then {
67 fail "Can't run to main"
71 # The "if" condition is artifical to test regression of a former patch.
72 gdb_breakpoint "[gdb_get_line_number "break-at-nextcall"] if i && gnu_ifunc (i) != 42"
74 gdb_breakpoint [gdb_get_line_number "break-at-call"]
75 gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*"
77 # Test GDB will automatically indirect the call.
79 gdb_test "p gnu_ifunc (3)" " = 4"
81 # Test GDB will skip the gnu_ifunc resolver on first call.
83 gdb_test "step" "\r\nfinal .*"
85 # Test GDB will not break before the final chosen implementation.
87 # Also test a former patch regression:
89 # Error in testing breakpoint condition:
90 # Attempt to take address of value not located in memory.
92 # Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33
94 gdb_test "continue" "Continuing.\r\n\r\nBreakpoint .* (at|in) .*break-at-nextcall.*" \
95 "continue to break-at-nextcall"
97 gdb_breakpoint "gnu_ifunc"
99 gdb_continue_to_breakpoint "nextcall gnu_ifunc"
101 gdb_test "frame" "#0 +(0x\[0-9a-f\]+ in +)?final \\(.*" "nextcall gnu_ifunc skipped"
104 # Check any commands not doing an inferior call access the address of the
105 # STT_GNU_IFUNC resolver, not the target function.
107 if {[istarget powerpc64-*] && [is_lp64_target]} {
108 # With only minimal symbols GDB provides the function descriptors. With
109 # full debug info the function code would be displayed.
115 gdb_test "p gnu_ifunc" " = {<text gnu-indirect-function variable, no debug info>} 0x\[0-9a-f\]+ <${func_prefix}gnu_ifunc>" "p gnu_ifunc executing"
116 gdb_test "info sym gnu_ifunc" "gnu_ifunc in section .*" "info sym gnu_ifunc executing"
118 set test "info addr gnu_ifunc"
119 gdb_test_multiple $test $test {
120 -re "Symbol \"gnu_ifunc\" is at (0x\[0-9a-f\]+) in .*$gdb_prompt $" {
124 gdb_test "info sym $expect_out(1,string)" "gnu_ifunc in section .*" "info sym <gnu_ifunc-address>"
127 # Test statically linked ifunc resolving during inferior start.
128 # https://bugzilla.redhat.com/show_bug.cgi?id=624967
130 if ![target_info exists gdb_stub] {
132 # Compile $staticbinfile separately as it may exit on error (ld/12595).
134 if { [gdb_compile ${srcdir}/${subdir}/$libsrc $lib_o object {}] != ""
135 || [gdb_compile "${srcdir}/${subdir}/$srcfile $lib_o" $staticbinfile executable {debug}] != "" } {
136 untested "Could not compile static executable $staticbinfile."
140 clean_restart $staticexecutable
142 gdb_breakpoint "gnu_ifunc"
143 gdb_breakpoint "main"
145 gdb_test "" "Breakpoint \[0-9\]*, main .*" "static gnu_ifunc"