public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Help with linker script to relocate a .note section
@ 2008-01-05 15:53 Tim Rightnour
  2008-01-08  0:00 ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Tim Rightnour @ 2008-01-05 15:53 UTC (permalink / raw)
  To: binutils


I am trying to write a linker script that will move a .note section of my
elf32-powerpc binary to the head of the file, directly after the ELF headers. 
Currently, what I have is this:

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 1] .note             NOTE            00000074 01d278 00002c 00      0   0  4
  [ 2] .text             PROGBITS        00040000 000080 00b7ec 00 WAX  0   0 16

I want the offset of the .note section to be directly after the headers, so
probably at 0x80 like the .text section is, thus moving the .text section down
further in the output file.

However, I have not been able to figure out what to put in the ld script to
make it do that.  I can move the note around in the section headers, but not
it's physical location in the resulting binary.

I am using GNU ld version 2.16.1 on NetBSD 4.0.

The linker script I have attempted to write is at
http://www.garbled.net/tmp/ldscript
My ld command line (truncated) is:

ld -s -N -T /tmp/lds -Ttext 40000 -Bstatic -e _start -o output foo.o bar.o

Any advice or assistance at all would be greatly appreciated.

---
Tim Rightnour <root@garbled.net>
NetBSD: Free multi-architecture OS http://www.netbsd.org/
Genecys: Open Source 3D MMORPG: http://www.genecys.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with linker script to relocate a .note section
  2008-01-05 15:53 Help with linker script to relocate a .note section Tim Rightnour
@ 2008-01-08  0:00 ` Alan Modra
  2008-01-08 14:18   ` Paul Koning
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2008-01-08  0:00 UTC (permalink / raw)
  To: Tim Rightnour; +Cc: binutils

On Thu, Jan 03, 2008 at 11:44:22PM -0700, Tim Rightnour wrote:
> 
> I am trying to write a linker script that will move a .note section of my
> elf32-powerpc binary to the head of the file, directly after the ELF headers. 
> Currently, what I have is this:
> 
>   [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
>   [ 1] .note             NOTE            00000074 01d278 00002c 00      0   0  4
>   [ 2] .text             PROGBITS        00040000 000080 00b7ec 00 WAX  0   0 16
> 
> I want the offset of the .note section to be directly after the headers, so
> probably at 0x80 like the .text section is, thus moving the .text section down
> further in the output file.

You can't do this, unless you make a loadable note section.  All load,
alloc sections get placed first in the file, then non-loaded sections.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with linker script to relocate a .note section
  2008-01-08  0:00 ` Alan Modra
@ 2008-01-08 14:18   ` Paul Koning
  2008-01-08 14:35     ` Tim Rightnour
  2008-01-08 15:02     ` Daniel Jacobowitz
  0 siblings, 2 replies; 6+ messages in thread
From: Paul Koning @ 2008-01-08 14:18 UTC (permalink / raw)
  To: amodra; +Cc: root, binutils

>>>>> "Alan" == Alan Modra <amodra@bigpond.net.au> writes:

 Alan> On Thu, Jan 03, 2008 at 11:44:22PM -0700, Tim Rightnour wrote:
 >>  I am trying to write a linker script that will move a .note
 >> section of my elf32-powerpc binary to the head of the file,
 >> directly after the ELF headers.  Currently, what I have is this:
 >> 
 >> [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 1] .note NOTE
 >> 00000074 01d278 00002c 00 0 0 4 [ 2] .text PROGBITS 00040000
 >> 000080 00b7ec 00 WAX 0 0 16
 >> 
 >> I want the offset of the .note section to be directly after the
 >> headers, so probably at 0x80 like the .text section is, thus
 >> moving the .text section down further in the output file.

 Alan> You can't do this, unless you make a loadable note section.
 Alan> All load, alloc sections get placed first in the file, then
 Alan> non-loaded sections.

I remember I had this work once early on (but at that time the linker
had a bug so it would create the section but wouldn't put stuff in it,
or something like that).

Having the ability to put NOTE sections up front is useful because
they can then be used to put markers in the image that are seen when
it is loaded.  That's what I needed to do.  In the end I ended up
creating a custom tool to create the NOTE section directly, rather
than relying on compiler/linker to do it.

If the restriction you mention is indended to be permanent then I
guess that tool will just live on...

      paul

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with linker script to relocate a .note section
  2008-01-08 14:18   ` Paul Koning
@ 2008-01-08 14:35     ` Tim Rightnour
  2008-01-08 14:42       ` Alexander Neundorf
  2008-01-08 15:02     ` Daniel Jacobowitz
  1 sibling, 1 reply; 6+ messages in thread
From: Tim Rightnour @ 2008-01-08 14:35 UTC (permalink / raw)
  To: Paul Koning; +Cc: binutils, amodra


On 07-Jan-2008 Paul Koning wrote:
> Having the ability to put NOTE sections up front is useful because
> they can then be used to put markers in the image that are seen when
> it is loaded.  That's what I needed to do.  In the end I ended up
> creating a custom tool to create the NOTE section directly, rather
> than relying on compiler/linker to do it.

Right, and thats exactly what I'm trying to do here.  I was really hoping I
could lay the binary out the way I wanted to with ld, rather than having to
write a program to mangle the finished binary for me.

---
Tim Rightnour <root@garbled.net>
NetBSD: Free multi-architecture OS http://www.netbsd.org/
Genecys: Open Source 3D MMORPG: http://www.genecys.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with linker script to relocate a .note section
  2008-01-08 14:35     ` Tim Rightnour
@ 2008-01-08 14:42       ` Alexander Neundorf
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Neundorf @ 2008-01-08 14:42 UTC (permalink / raw)
  To: binutils

On Monday 07 January 2008, Tim Rightnour wrote:
...
> Right, and thats exactly what I'm trying to do here.  I was really hoping I
> could lay the binary out the way I wanted to with ld, rather than having to
> write a program to mangle the finished binary for me.

I think this sounds like a task for objcopy.

Alex

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help with linker script to relocate a .note section
  2008-01-08 14:18   ` Paul Koning
  2008-01-08 14:35     ` Tim Rightnour
@ 2008-01-08 15:02     ` Daniel Jacobowitz
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2008-01-08 15:02 UTC (permalink / raw)
  To: Paul Koning; +Cc: amodra, root, binutils

On Mon, Jan 07, 2008 at 12:11:49PM -0500, Paul Koning wrote:
>  Alan> You can't do this, unless you make a loadable note section.
>  Alan> All load, alloc sections get placed first in the file, then
>  Alan> non-loaded sections.
> 
> I remember I had this work once early on (but at that time the linker
> had a bug so it would create the section but wouldn't put stuff in it,
> or something like that).
> 
> Having the ability to put NOTE sections up front is useful because
> they can then be used to put markers in the image that are seen when
> it is loaded.  That's what I needed to do.  In the end I ended up
> creating a custom tool to create the NOTE section directly, rather
> than relying on compiler/linker to do it.

How does this conflict with what Alan said?  Make the note loadable.
See .note.gnu.build.id.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-01-07 18:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-05 15:53 Help with linker script to relocate a .note section Tim Rightnour
2008-01-08  0:00 ` Alan Modra
2008-01-08 14:18   ` Paul Koning
2008-01-08 14:35     ` Tim Rightnour
2008-01-08 14:42       ` Alexander Neundorf
2008-01-08 15:02     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).