This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
objcopy -j -O binary can't extract debug sections
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: binutils at sourceware dot org
- Date: Fri, 22 Nov 2013 19:40:33 +0100
- Subject: objcopy -j -O binary can't extract debug sections
- Authentication-results: sourceware.org; auth=none
Hi,
[please keep me CCed, I'm not subscribed to binutils]
for some reason which doesn't matter for this mail, I'm trying to
perform the following action under Cygwin:
1. Extract all sections with long section names from an executable
and store them in a file for step 4.
2. Strip these sections from the executable.
3. Tweak the executable's .rsrc section, using Windows calls which
don't understand long section names (it renders them unusable).
4. Add all sections with long section names back to the executable.
The sections in question are usually the .gnu_debuglink section, as well
as the Dwarf2 debug sections. So, for a start, I created a shell script
which extracts and removes the well-known sections from the executable
before calling the executable performing the magic Windows action.
Here's the start of the script:
EXE=$1
LONGSECTIONS=".gnu_debuglink \
.debug_aranges \
.debug_info \
.debug_abbrev \
.debug_line \
.debug_frame \
.debug_str \
.debug_loc \
.debug_ranges"
for section in ${LONGSECTIONS}
do
objcopy -j "${section}" -O binary "${EXE}" "${EXE}${section}"
objcopy -R "${section}" "${EXE}"
done
[...]
So I'm just storing the binary content of the debug sections in separate
files and then strip the section from the executable.
The problem is, it doesn't work. The only section which I can export
successfully this way is the .gnu_debuglink section. All the files
supposed to contain the Dwarf2 debug sections will have a length of 0.
No errors, no warnings, just a size of 0.
Adding "--long-section-names keep" has no effect. If I create an
executable with any arbitrary section with a long section name like,
say, ".long_section", I can extract the section in binary form. I just
can't export the debug sections this way.
At this point I assumed a bug in objcopy's COFF handling, but in fact,
the same happens on Linux using a native objcopy on a native Linux ELF
executable. There's apparently no way to extract the debug sections
in binary form to be able to attach them later on again with --add-section.
So, is that a bug or deliberately restricted?
Thanks,
Corinna