This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: placing data into a section
- From: Nick Clifton <nickc at redhat dot com>
- To: Bahadir Balban <bahadir dot balban at gmail dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Tue, 11 Jul 2006 14:57:49 +0100
- Subject: Re: placing data into a section
- References: <7ac1e90c0607101106v8e41af1ge2ffb33410946487@mail.gmail.com>
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.