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

jbm at bachmeier dot cc sourceware-bugzilla@sourceware.org
Wed May 31 12:22:00 GMT 2017


--- 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

// 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);

 $ gcc bfdbug.c -g -lbfd -o bfdbug
 $ cp bfdbug test.elf
 $ gdb bfdbug
GNU gdb (Ubuntu
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:
Find the GDB manual and other documentation resources online at:
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
(gdb) where
#0  0x00007ffff7b1f391 in _bfd_elf_strtab_finalize () from
#1  0x00007ffff7b01a17 in _bfd_elf_write_object_contents () from
#2  0x00007ffff7adff87 in bfd_close () from
#3  0x0000555555554856 in main (argc=2, argv=0x7fffffffe588) at bfdbug.c:7

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.

More information about the Gdb-prs mailing list