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 #13 from Jozef Lawrynowicz <jozef.l at mittosystems dot com> ---
Thanks for the info.
I wasn't able to reproduce your issue on x86_64-pc-linux-gnu.

gcc -g empty.c
gdb -q --write -ex q a.out
Reading symbols from a.out...done.
gdb -q --write -ex q a.out
Reading symbols from a.out...done.

No assertion fails for me.
However, if I compare the "readelf -a" ouput of a.out, before and after
invoking GDB, there is clearly an issue.

The following segments are missing from a.out after invoking gdb with --write:
06     .dynamic                             
07     .note.ABI-tag                        
08     .eh_frame_hdr                        
09                                          
10     .init_array .fini_array .dynamic .got

Could you post the "gcc -v" output, here's mine:
        ...
        Target: x86_64-pc-linux-gnu
        Configured with: ../configure --enable-languages=c,c++ --disable-nls
        Thread model: posix
        gcc version 8.1.0 (GCC) 

Could you also attach the linked executable you get from "gcc -g test.c".

---

I was actually able to reproduce the assertion failure at elf.c:5766 when
building test.c for the msp430-elf target.

The assertion fails because hdr->bfd_section->filepos has been
changed since opening the BFD, but hdr->sh_offset has not. However, another
copy of the section header for this section did have sh_offset updated to the
correct value.

The issue is that there are two copies of the Elf_Internal_Shdr for each
section. One is accessible via "elf_section_data(sec)->this_hdr", the other in
"elf_elfsections(abfd)" (you have to iterate to find the correct header for the
section first).

When linking files, these headers have the same address, i.e. the
"elf_elfsections(abfd)" headers point to the corresponding
"elf_section_data(sec)->this_hdr". But when opening a BFD for update, these
have different addresses, so updating the values in one does not update the
other.

---

Regarding object files, the documentation
(https://sourceware.org/gdb/onlinedocs/gdb/Patching.html#Patching)
says that the --write is for executable and core files only.
So I would say trying to use --write with a relocatable object file is maybe
not supposed to work, but at this point I don't have an opinion on whether
it fundamentally can or can't work.
After the issues with using --write on executable files is
fixed, if there are still problems with object files, I will take a look.

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