1 From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
2 From: Fedora GDB patches <invalid@email.com>
3 Date: Fri, 27 Oct 2017 21:07:50 +0200
4 Subject: gdb-6.6-buildid-locate-solib-missing-ids.patch
6 FileName: gdb-6.6-buildid-locate-solib-missing-ids.patch
8 ;; Fix loading of core files without build-ids but with build-ids in executables.
9 ;; Load strictly build-id-checked core files only if no executable is specified
10 ;; (Jan Kratochvil, RH BZ 1339862).
13 gdb returns an incorrect back trace when applying a debuginfo
14 https://bugzilla.redhat.com/show_bug.cgi?id=1339862
16 gdb/solib-svr4.c | 35 ++++---
17 .../gcore-buildid-exec-but-not-solib-lib.c | 21 +++++
18 .../gcore-buildid-exec-but-not-solib-main.c | 25 +++++
19 .../gdb.base/gcore-buildid-exec-but-not-solib.exp | 105 +++++++++++++++++++++
20 4 files changed, 167 insertions(+), 19 deletions(-)
21 create mode 100644 gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
22 create mode 100644 gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
23 create mode 100644 gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
25 diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
26 index a3399ad8f7..d7eeb6350d 100644
27 --- a/gdb/solib-svr4.c
28 +++ b/gdb/solib-svr4.c
29 @@ -1387,14 +1387,27 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
33 - struct bfd_build_id *build_id;
34 + struct bfd_build_id *build_id = NULL;
36 strncpy (newobj->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
37 newobj->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
38 /* May get overwritten below. */
39 strcpy (newobj->so_name, newobj->so_original_name);
41 - build_id = build_id_addr_get (newobj->lm_info->l_ld);
42 + /* In the case the main executable was found according to its build-id
43 + (from a core file) prevent loading a different build of a library
44 + with accidentally the same SO_NAME.
46 + It suppresses bogus backtraces (and prints "??" there instead) if
47 + the on-disk files no longer match the running program version.
49 + If the main executable was not loaded according to its build-id do
50 + not do any build-id checking of the libraries. There may be missing
51 + build-ids dumped in the core file and we would map all the libraries
52 + to the only existing file loaded that time - the executable. */
53 + if (symfile_objfile != NULL
54 + && (symfile_objfile->flags & OBJF_BUILD_ID_CORE_LOADED) != 0)
55 + build_id = build_id_addr_get (li->l_ld);
58 char *name, *build_id_filename;
59 @@ -1409,23 +1422,7 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
64 - debug_print_missing (newobj->so_name, build_id_filename);
66 - /* In the case the main executable was found according to
67 - its build-id (from a core file) prevent loading
68 - a different build of a library with accidentally the
71 - It suppresses bogus backtraces (and prints "??" there
72 - instead) if the on-disk files no longer match the
73 - running program version. */
75 - if (symfile_objfile != NULL
76 - && (symfile_objfile->flags
77 - & OBJF_BUILD_ID_CORE_LOADED) != 0)
78 - newobj->so_name[0] = 0;
80 + debug_print_missing (newobj->so_name, build_id_filename);
82 xfree (build_id_filename);
84 diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
86 index 0000000000..d74b690c73
88 +++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
90 +/* Copyright 2010 Free Software Foundation, Inc.
92 + This file is part of GDB.
94 + This program is free software; you can redistribute it and/or modify
95 + it under the terms of the GNU General Public License as published by
96 + the Free Software Foundation; either version 3 of the License, or
97 + (at your option) any later version.
99 + This program is distributed in the hope that it will be useful,
100 + but WITHOUT ANY WARRANTY; without even the implied warranty of
101 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102 + GNU General Public License for more details.
104 + You should have received a copy of the GNU General Public License
105 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
111 diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
113 index 0000000000..46b9dfe161
115 +++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
117 +/* Copyright 2010 Free Software Foundation, Inc.
119 + This file is part of GDB.
121 + This program is free software; you can redistribute it and/or modify
122 + it under the terms of the GNU General Public License as published by
123 + the Free Software Foundation; either version 3 of the License, or
124 + (at your option) any later version.
126 + This program is distributed in the hope that it will be useful,
127 + but WITHOUT ANY WARRANTY; without even the implied warranty of
128 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129 + GNU General Public License for more details.
131 + You should have received a copy of the GNU General Public License
132 + along with this program. If not, see <http://www.gnu.org/licenses/>. */
134 +extern void lib (void);
142 diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
144 index 0000000000..0c46489f31
146 +++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
148 +# Copyright 2016 Free Software Foundation, Inc.
150 +# This program is free software; you can redistribute it and/or modify
151 +# it under the terms of the GNU General Public License as published by
152 +# the Free Software Foundation; either version 3 of the License, or
153 +# (at your option) any later version.
155 +# This program is distributed in the hope that it will be useful,
156 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
157 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158 +# GNU General Public License for more details.
160 +# You should have received a copy of the GNU General Public License
161 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
163 +if {[skip_shlib_tests]} {
167 +set testfile "gcore-buildid-exec-but-not-solib"
168 +set srcmainfile ${testfile}-main.c
169 +set srclibfile ${testfile}-lib.c
170 +set libfile [standard_output_file ${testfile}-lib.so]
171 +set objfile [standard_output_file ${testfile}-main.o]
172 +set executable ${testfile}-main
173 +set binfile [standard_output_file ${executable}]
174 +set gcorefile [standard_output_file ${executable}.gcore]
175 +set outdir [file dirname $binfile]
177 +if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} "debug additional_flags=-Wl,--build-id"] != ""
178 + || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
179 + unsupported "-Wl,--build-id compilation failed"
182 +set opts [list debug shlib=${libfile} "additional_flags=-Wl,--build-id"]
183 +if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
184 + unsupported "-Wl,--build-id compilation failed"
188 +clean_restart $executable
189 +gdb_load_shlib $libfile
191 +# Does this gdb support gcore?
192 +set test "help gcore"
193 +gdb_test_multiple $test $test {
194 + -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
195 + # gcore command not supported -- nothing to test here.
196 + unsupported "gdb does not support gcore on this target"
199 + -re "Save a core file .*\r\n$gdb_prompt $" {
204 +if { ![runto lib] } then {
208 +set escapedfilename [string_to_regexp ${gcorefile}]
210 +set test "save a corefile"
211 +gdb_test_multiple "gcore ${gcorefile}" $test {
212 + -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
215 + -re "Can't create a corefile\r\n$gdb_prompt $" {
221 +# Now restart gdb and load the corefile.
223 +clean_restart $executable
224 +gdb_load_shlib $libfile
226 +set buildid [build_id_debug_filename_get $libfile]
228 +regsub {\.debug$} $buildid {} buildid
230 +set debugdir [standard_output_file ${testfile}-debugdir]
231 +file delete -force -- $debugdir
233 +file mkdir $debugdir/[file dirname $libfile]
234 +file copy $libfile $debugdir/${libfile}
236 +file mkdir $debugdir/[file dirname $buildid]
237 +file copy $libfile $debugdir/${buildid}
239 +remote_exec build "ln -s /lib ${debugdir}/"
240 +remote_exec build "ln -s /lib64 ${debugdir}/"
241 +# /usr is not needed, all the libs are in /lib64: libm.so.6 libc.so.6 ld-linux-x86-64.so.2
243 +gdb_test "set solib-absolute-prefix $debugdir"
245 +gdb_test_no_output "set debug-file-directory $debugdir" "set debug-file-directory"
247 +gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
249 +gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
252 +gdb_test "info shared"