Generating an ELF file with PT_NOTE before PT_LOAD
Wed Feb 21 18:46:00 GMT 2018
On Wednesday 21 February 2018 at 16:58:39 +0100, Andreas Schwab wrote:
> On Feb 21 2018, Mike Crowe <firstname.lastname@example.org> wrote:
> > --8<--
> > #!/bin/sh
> > set -e
> > dd if=/dev/zero of=binary bs=1M count=1
> > objcopy -I binary -O elf32-i386 -B i386 binary text.o
> > gcc -c -m32 -x assembler - -o note.o <<EOF
> > .section ".note.my-version", ""
> I think you need to make that section allocated, otherwise the linker
> will always place it after the other allocated sections.
I think that I've done that by changing the last line you quoted to:
.section ".note.my-version", "a"
Now the script warns, but doesn't seem to do anything else differently.
Here's the new output:
ld.bfd: out.elf: warning: allocated section `.note' not in segment
Elf file type is EXEC (Executable file)
Entry point 0x20
There are 2 program headers, starting at offset 52
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
NOTE 0x100074 0x00000000 0x00000000 0x00020 0x00020 R 0x4
LOAD 0x000074 0x00000020 0x00000020 0x100000 0x100000 R E 0x1
Section to Segment mapping:
Did I implement your suggestion incorrectly, or is there something else
that I need to do?
Thanks for your help.
More information about the Binutils