This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: 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 21:26:33 +0100
- Subject: Re: objcopy -j -O binary can't extract debug sections
- Authentication-results: sourceware.org; auth=none
- References: <20131122184033 dot GF28310 at calimero dot vinschen dot de> <CAKOQZ8yG91ZxQiMDHL3X0LhqPSPT3MwidjzTNxfjS-ASCsoe1w at mail dot gmail dot com>
Hi Ian,
On Nov 22 11:45, Ian Lance Taylor wrote:
> On Fri, Nov 22, 2013 at 10:40 AM, Corinna Vinschen <...> wrote:
> >
> > 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.
>
> It's because the .debug_XXX sections are marked with SEC_DEBUG in BFD,
> and the BFD "binary" format discards SEC_DEBUG sections.
>
> Try adding
> --set-section-flags=".debug*=alloc,load"
Thanks for the hint. Unfortunately it doesn't work. It silently ignores
the command. I also tried without the wildcard:
$ objdump -h foo.exe
[...]
14 .debug_ranges 00000030 0000000100415000 0000000100415000 0000b000 2**0
CONTENTS, READONLY, DEBUGGING
$ objcopy --long-section-names keep --set-section-flags ".debug_ranges=alloc,load" foo.exe
$ objdump -h foo.exe
[...]
14 .debug_ranges 00000030 0000000100415000 0000000100415000 0000b000 2**0
CONTENTS, READONLY, DEBUGGING
Nick Clifton gave me the hint to try renaming the sections before
exporting them. This allows exporting them, but then adding them back
fails:
$ objcopy --add-section .debug_ranges=foo.exe.debug_ranges --set-section-flags .debug_ranges=contents --adjust-section-vma .debug_ranges=0x100409000 --long-section-names keep foo.exe
objcopy:foo.exe: File truncated
objcopy: --change-section-vma .debug_ranges=0x0000000100409000 never used
objcopy: --change-section-lma .debug_ranges=0x0000000100409000 never used
Even trying to add the section under another name like ".foobar" doesn't
work. The error is exactly the same.
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat