Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2009-2016 Free Software Foundation, Inc. |
e4620230 JK |
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 | if {[skip_shlib_tests]} { | |
17 | return 0 | |
18 | } | |
19 | ||
289f9037 | 20 | standard_testfile .c |
e4620230 | 21 | set executable ${testfile} |
e4620230 | 22 | set staticexecutable ${executable}-static |
289f9037 | 23 | set staticbinfile [standard_output_file ${staticexecutable}] |
e4620230 JK |
24 | |
25 | set libfile "${testfile}-lib" | |
26 | set libsrc ${libfile}.c | |
289f9037 | 27 | set lib_so [standard_output_file ${libfile}.so] |
e4620230 | 28 | # $lib_o must not have {debug}, it would override the STT_GNU_IFUNC ELF markers. |
289f9037 | 29 | set lib_o [standard_output_file ${libfile}.o] |
e4620230 JK |
30 | |
31 | # We need DWARF for the "final" function as we "step" into the function and GDB | |
32 | # would step-over the "final" function if there would be no line number debug | |
33 | # information (DWARF) available. | |
34 | # | |
35 | # We must not have DWARF for the "gnu_ifunc" function as DWARF has no way to | |
36 | # express the STT_GNU_IFUNC type and it would be considered as a regular | |
37 | # function due to DWARF by GDB. In ELF gnu-ifunc is expressed by the | |
38 | # STT_GNU_IFUNC type. | |
39 | # | |
40 | # Both functions need to be in the same shared library file but | |
41 | # gdb_compile_shlib has no way to specify source-specific compilation options. | |
42 | # | |
43 | # Therefore $libfile contains only the STT_GNU_IFUNC function with no DWARF | |
44 | # referencing all the other parts from the main executable with DWARF. | |
45 | ||
46 | set lib_opts {} | |
47 | set exec_opts [list debug shlib=$lib_so] | |
48 | ||
4c93b1db | 49 | if [get_compiler_info] { |
e4620230 JK |
50 | return -1 |
51 | } | |
52 | ||
53 | if { [gdb_compile_shlib ${srcdir}/${subdir}/$libsrc $lib_so $lib_opts] != "" | |
54 | || [gdb_compile ${srcdir}/${subdir}/$srcfile $binfile executable $exec_opts] != ""} { | |
84c93cd5 | 55 | untested "failed to compile first testcase" |
e4620230 JK |
56 | return -1 |
57 | } | |
58 | ||
59 | # Start with a fresh gdb. | |
60 | ||
61 | clean_restart $executable | |
d9019901 | 62 | gdb_load_shlib ${lib_so} |
e4620230 JK |
63 | |
64 | if ![runto_main] then { | |
bc6c7af4 | 65 | fail "can't run to main" |
ae59b1da | 66 | return 1 |
e4620230 JK |
67 | } |
68 | ||
69 | # The "if" condition is artifical to test regression of a former patch. | |
70 | gdb_breakpoint "[gdb_get_line_number "break-at-nextcall"] if i && gnu_ifunc (i) != 42" | |
71 | ||
72 | gdb_breakpoint [gdb_get_line_number "break-at-call"] | |
73 | gdb_continue_to_breakpoint "break-at-call" ".*break-at-call.*" | |
74 | ||
75 | # Test GDB will automatically indirect the call. | |
76 | ||
77 | gdb_test "p gnu_ifunc (3)" " = 4" | |
78 | ||
e1b2624a AA |
79 | # Test that the resolver received its argument. |
80 | ||
81 | set actual_hwcap "0x0" | |
82 | set test "info auxv" | |
83 | gdb_test_multiple $test $test { | |
84 | -re "\r\n\\d+\\s+AT_HWCAP\[^\r\n\]+($hex)\r\n.*$gdb_prompt $" { | |
85 | set actual_hwcap $expect_out(1,string) | |
86 | } | |
87 | -re ".*$gdb_prompt $" { | |
88 | pass "$test (no HWCAP)" | |
89 | } | |
90 | } | |
91 | ||
92 | gdb_test "p/x resolver_hwcap" "= $actual_hwcap" "resolver received HWCAP" | |
93 | ||
e4620230 JK |
94 | # Test GDB will skip the gnu_ifunc resolver on first call. |
95 | ||
96 | gdb_test "step" "\r\nfinal .*" | |
97 | ||
98 | # Test GDB will not break before the final chosen implementation. | |
99 | ||
100 | # Also test a former patch regression: | |
101 | # Continuing. | |
102 | # Error in testing breakpoint condition: | |
103 | # Attempt to take address of value not located in memory. | |
104 | # | |
105 | # Breakpoint 2, main () at ./gdb.base/gnu-ifunc.c:33 | |
106 | ||
107 | gdb_test "continue" "Continuing.\r\n\r\nBreakpoint .* (at|in) .*break-at-nextcall.*" \ | |
108 | "continue to break-at-nextcall" | |
109 | ||
110 | gdb_breakpoint "gnu_ifunc" | |
111 | ||
112 | gdb_continue_to_breakpoint "nextcall gnu_ifunc" | |
113 | ||
114 | gdb_test "frame" "#0 +(0x\[0-9a-f\]+ in +)?final \\(.*" "nextcall gnu_ifunc skipped" | |
115 | ||
116 | ||
117 | # Check any commands not doing an inferior call access the address of the | |
118 | # STT_GNU_IFUNC resolver, not the target function. | |
119 | ||
120 | if {[istarget powerpc64-*] && [is_lp64_target]} { | |
121 | # With only minimal symbols GDB provides the function descriptors. With | |
122 | # full debug info the function code would be displayed. | |
123 | set func_prefix {\.} | |
124 | } else { | |
125 | set func_prefix {} | |
126 | } | |
127 | ||
128 | 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" | |
129 | gdb_test "info sym gnu_ifunc" "gnu_ifunc in section .*" "info sym gnu_ifunc executing" | |
130 | ||
131 | set test "info addr gnu_ifunc" | |
132 | gdb_test_multiple $test $test { | |
133 | -re "Symbol \"gnu_ifunc\" is at (0x\[0-9a-f\]+) in .*$gdb_prompt $" { | |
134 | pass $test | |
135 | } | |
136 | } | |
137 | gdb_test "info sym $expect_out(1,string)" "gnu_ifunc in section .*" "info sym <gnu_ifunc-address>" | |
138 | ||
139 | ||
140 | # Test statically linked ifunc resolving during inferior start. | |
141 | # https://bugzilla.redhat.com/show_bug.cgi?id=624967 | |
142 | ||
924437bc | 143 | # Compile $staticbinfile separately as it may exit on error (ld/12595). |
e4620230 | 144 | |
924437bc PA |
145 | if { [gdb_compile ${srcdir}/${subdir}/$libsrc $lib_o object {}] != "" |
146 | || [gdb_compile "${srcdir}/${subdir}/$srcfile $lib_o" $staticbinfile executable {debug}] != "" } { | |
84c93cd5 | 147 | untested "failed to compile second testcase" |
924437bc PA |
148 | return -1 |
149 | } | |
e4620230 | 150 | |
924437bc | 151 | clean_restart $staticexecutable |
e4620230 | 152 | |
924437bc PA |
153 | gdb_breakpoint "gnu_ifunc" |
154 | gdb_breakpoint "main" | |
155 | gdb_run_cmd | |
156 | gdb_test "" "Breakpoint \[0-9\]*, main .*" "static gnu_ifunc" |