public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* placing data into a section
@ 2006-07-10 18:06 Bahadir Balban
  2006-07-10 18:09 ` Daniel Jacobowitz
  2006-07-11 13:57 ` Nick Clifton
  0 siblings, 2 replies; 5+ messages in thread
From: Bahadir Balban @ 2006-07-10 18:06 UTC (permalink / raw)
  To: binutils

Hi,

When I am linking an elf executable, I would like to place some bulk
data (e.g. a zip file or some other binary file) into a section in the
final executable. How can I achieve this with ld commands and the
linker script?

It will be something like:

SECTIONS {
    /* Other sections ... */

.data :
    {
    /* Some other data go here ... */

    bulk_data_start = .;
    *(.bulk_data)
    bulk_data_end = .;
    }
}

But how can I put a file into a .bulk_data section like that?

Thanks,
Bahadir

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

* Re: placing data into a section
  2006-07-10 18:06 placing data into a section Bahadir Balban
@ 2006-07-10 18:09 ` Daniel Jacobowitz
  2006-07-11 13:57 ` Nick Clifton
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2006-07-10 18:09 UTC (permalink / raw)
  To: Bahadir Balban; +Cc: binutils

On Mon, Jul 10, 2006 at 06:06:06PM +0000, Bahadir Balban wrote:
> But how can I put a file into a .bulk_data section like that?

You can use objcopy, or gas's .incbin directive.

-- 
Daniel Jacobowitz
CodeSourcery

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

* Re: placing data into a section
  2006-07-10 18:06 placing data into a section Bahadir Balban
  2006-07-10 18:09 ` Daniel Jacobowitz
@ 2006-07-11 13:57 ` Nick Clifton
  2006-07-11 14:11   ` vamsi krishna
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2006-07-11 13:57 UTC (permalink / raw)
  To: Bahadir Balban; +Cc: binutils

Hi Bahadir,

> When I am linking an elf executable, I would like to place some bulk
> data (e.g. a zip file or some other binary file) into a section in the
> final executable. How can I achieve this with ld commands and the
> linker script?

As has already been mentioned this is probably easier to do using the 
assembler's .incbin directive or the objcopy program's --add-section 
switch.  But if you do want to use a linker script...

> .data :
>    {
>    /* Some other data go here ... */
> 
>    bulk_data_start = .;
>    *(.bulk_data)
>    bulk_data_end = .;
>    }
> }
> 
> But how can I put a file into a .bulk_data section like that?

By explicitly mentioning the file name:

      bulk_data_start = .;
      bulk_data.o(.data)
      bulk_data_end = . ;

I am assuming here that you want the .data section from your bulk_data.o 
file.  If however you wanted the .bulk_data section, assuming that it 
exists, then the script would be:

      bulk_data_start = .;
      bulk_data.o(.bulk_data)
      bulk_data_end = . ;

Note however that if you want this data to come *after* the normal data 
(and assuming that it is in a section called .data) then you have to be 
a little bit more careful.  This, for example will not work:

   .data :
    {
      *(.data)
      bulk_data_start = .;
      bulk_data.o(.data)
      bulk_data_end = .;
    }

This is because the first "*(.data)" will match the .data section in all 
the input files, including .bulk_data.o.  So you have to exclude the 
bulk data from the ordinary data, like this:

   .data :
    {
      *(EXCLUDE_FILE (bulk_data.o) .data)
      bulk_data_start = .;
      bulk_data.o(.data)
      bulk_data_end = .;
    }

This is all documented in the linker manual.  I strongly recommend that 
you read it.

Cheers
   Nick

PS.  The above examples assume that you will be passing "bulk_data.o" as 
a filename on the linker command line.

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

* Re: placing data into a section
  2006-07-11 13:57 ` Nick Clifton
@ 2006-07-11 14:11   ` vamsi krishna
  2006-07-11 16:19     ` Daniel S. Wilkerson
  0 siblings, 1 reply; 5+ messages in thread
From: vamsi krishna @ 2006-07-11 14:11 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Bahadir Balban, binutils

Hello

> > When I am linking an elf executable, I would like to place some bulk
> > data (e.g. a zip file or some other binary file) into a section in the
> > final executable. How can I achieve this with ld commands and the
> > linker script?

I suggest you need to add this as a SEGMENT not a SECTION, because in
a executable the section header table can be stripped off. You may
need some mechanism to add the bulk file as a PHDR PT_LOAD entry.

Just more curious on how would you refer this in your code?

Thank you,
Vamsi kundeti

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

* Re: placing data into a section
  2006-07-11 14:11   ` vamsi krishna
@ 2006-07-11 16:19     ` Daniel S. Wilkerson
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel S. Wilkerson @ 2006-07-11 16:19 UTC (permalink / raw)
  To: vamsi krishna; +Cc: binutils

This is easy to do.  See how we do it in build-interceptor.tigris.org.

Basically, use objcopy --add-section.

Daniel

vamsi krishna wrote:

> Hello
>
> > > When I am linking an elf executable, I would like to place some bulk
> > > data (e.g. a zip file or some other binary file) into a section in the
> > > final executable. How can I achieve this with ld commands and the
> > > linker script?
>
> I suggest you need to add this as a SEGMENT not a SECTION, because in
> a executable the section header table can be stripped off. You may
> need some mechanism to add the bulk file as a PHDR PT_LOAD entry.
>
> Just more curious on how would you refer this in your code?
>
> Thank you,
> Vamsi kundeti

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

end of thread, other threads:[~2006-07-11 16:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-10 18:06 placing data into a section Bahadir Balban
2006-07-10 18:09 ` Daniel Jacobowitz
2006-07-11 13:57 ` Nick Clifton
2006-07-11 14:11   ` vamsi krishna
2006-07-11 16:19     ` Daniel S. Wilkerson

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).