placing data into a section
Nick Clifton
nickc@redhat.com
Tue Jul 11 13:57:00 GMT 2006
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.
More information about the Binutils
mailing list