I've tried the following, but the resulting file is still an ELF and not purely the section content.
$ objcopy --only-section=<name> <infile> <outfile>
I just want the contents of the section. Is there any utility that can do this? Any ideas?
I've tried the following, but the resulting file is still an ELF and not purely the section content.
$ objcopy --only-section=<name> <infile> <outfile>
I just want the contents of the section. Is there any utility that can do this? Any ideas?
Use the
-O binary
output format:Just verified with
avr-objcopy
and an AVR ELF image's.text
section.Note that if, as Tim points out below, your section doesn't have the ALLOC flag, you may have to add
--set-section-flags .text=alloc
to be able to extract it.Rather inelegant hack around
objdump
anddd
:The
objdump -h
produces predictable output which contains section offset in the elf file. I made theawk
to generate add
command for the shell, sincedd
doesn't support hexadecimal numbers. And fed the command to shell.In past I did all that manually, without making any scripts, since it is rarely needed.
objcopy --dump-section
Introduced in Binutils 2.25, and achieves a similar effect to
-O binary --only-section
.Usage:
https://sourceware.org/binutils/docs-2.25/binutils/objcopy.html documents it as:
Minimal runnable example
a.S:
Assemble and extract:
Output:
Tested in Ubuntu 18.04 amd64, Binutils 2.30.