diff options
author | Jozef Lawrynowicz <jozef.l@mittosystems.com> | 2018-09-11 22:56:36 +0100 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-24 06:20:17 -0600 |
commit | db72737006fc383cb8838bf7f3dc8e641e60c38f (patch) | |
tree | 1c81ecc66318cd2e3e8cb8da3ae04e9855b5c945 /bfd/elf.c | |
parent | b5a9bfbebec0a42d3c5b4fe3b7a62bd31cecc440 (diff) | |
download | gdb-db72737006fc383cb8838bf7f3dc8e641e60c38f.zip gdb-db72737006fc383cb8838bf7f3dc8e641e60c38f.tar.gz gdb-db72737006fc383cb8838bf7f3dc8e641e60c38f.tar.bz2 |
Fix PR gdb/20948: --write option to GDB causes segmentation fault
When opening a BFD for update, as gdb --write does, modifications to
anything but the contents of sections is restricted.
Do not try to write back any ELF headers in this case.
bfd/ChangeLog
2018-09-24 Jozef Lawrynowicz <jozef.l@mittosystems.com>
PR gdb/20948
* elf.c (_bfd_elf_write_object_contents): Return from function
early if abfd->direction == both_direction.
gdb/testsuite/ChangeLog
2018-09-24 Jozef Lawrynowicz <jozef.l@mittosystems.com>
PR gdb/20948
* gdb.base/write_mem.exp: New test.
* gdb.base/write_mem.c: Likewise.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -6391,6 +6391,18 @@ _bfd_elf_write_object_contents (bfd *abfd) if (! abfd->output_has_begun && ! _bfd_elf_compute_section_file_positions (abfd, NULL)) return FALSE; + /* Do not rewrite ELF data when the BFD has been opened for update. + abfd->output_has_begun was set to TRUE on opening, so creation of new + sections, and modification of existing section sizes was restricted. + This means the ELF header, program headers and section headers can't have + changed. + If the contents of any sections has been modified, then those changes have + already been written to the BFD. */ + else if (abfd->direction == both_direction) + { + BFD_ASSERT (abfd->output_has_begun); + return TRUE; + } i_shdrp = elf_elfsections (abfd); |