This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Generating an ELF file with PT_NOTE before PT_LOAD


On Wednesday 21 February 2018 at 16:58:39 +0100, Andreas Schwab wrote:
> On Feb 21 2018, Mike Crowe <mac@mcrowe.com> 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:

--8<--
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
-->8--

Did I implement your suggestion incorrectly, or is there something else
that I need to do?

Thanks for your help.

Mike.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]