This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gdb/20948] --write option to GDB causes segmentation fault


https://sourceware.org/bugzilla/show_bug.cgi?id=20948

--- Comment #3 from jbm at bachmeier dot cc ---
Comment on attachment 10078
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10078
Full reproduction example

This indeed seems to be a problem in libbfd. I was encountered the problem
while using the library. 

The segfault seems to occur when opening a file for both reading and writing.

Minimal example:

 $ cat bfdbug.c
#include<bfd.h>

// Error checks omitted for clarity, see attachment
int main(int argc, char **argv) {
  bfd *abfd = bfd_fopen(argv[1], "default", "r+", -1);
  bfd_check_format(abfd, bfd_object);
  bfd_close(abfd);
}

 $ gcc bfdbug.c -g -lbfd -o bfdbug
 $ cp bfdbug test.elf
 $ gdb bfdbug
GNU gdb (Ubuntu 7.12.50.20170314-0ubuntu1) 7.12.50.20170314-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from bfdbug...done.
(gdb) run test.elf
Starting program: /home/bachme/bt-cgp/cgp/bfdbug test.elf

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b1f391 in _bfd_elf_strtab_finalize () from
/usr/lib/x86_64-linux-gnu/libbfd-2.28-system.so
(gdb) where
#0  0x00007ffff7b1f391 in _bfd_elf_strtab_finalize () from
/usr/lib/x86_64-linux-gnu/libbfd-2.28-system.so
#1  0x00007ffff7b01a17 in _bfd_elf_write_object_contents () from
/usr/lib/x86_64-linux-gnu/libbfd-2.28-system.so
#2  0x00007ffff7adff87 in bfd_close () from
/usr/lib/x86_64-linux-gnu/libbfd-2.28-system.so
#3  0x0000555555554856 in main (argc=2, argv=0x7fffffffe588) at bfdbug.c:7
(gdb)

When using "w" or "r" instead of "r+" as the mode argument to bfd_fopen (or
using bfd_openr/bfd_openw instead), no error ocurrs (even when adding symbols
to the symtab / strtab) before closing.

Binutils version:
 $ objdump -V
GNU objdump (GNU Binutils for Ubuntu) 2.28
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]