Generating an ELF file with PT_NOTE before PT_LOAD

Mike Crowe
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 <> 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 "", ""
> 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 "", "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

Program Headers:
  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:
  Segment Sections...
   00     .note
   01     .text

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 mailing list