From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14394 invoked by alias); 11 Jul 2006 13:57:55 -0000 Received: (qmail 14385 invoked by uid 22791); 11 Jul 2006 13:57:55 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 11 Jul 2006 13:57:53 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6BDvpA0032343; Tue, 11 Jul 2006 09:57:51 -0400 Received: from pobox.surrey.redhat.com (pobox.surrey.redhat.com [172.16.10.17]) by int-mx1.corp.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6BDvoMt008267; Tue, 11 Jul 2006 09:57:51 -0400 Received: from [10.32.68.5] (vpn-68-5.surrey.redhat.com [10.32.68.5]) by pobox.surrey.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6BDvolU024426; Tue, 11 Jul 2006 14:57:50 +0100 Message-ID: <44B3AE5D.4030304@redhat.com> Date: Tue, 11 Jul 2006 13:57:00 -0000 From: Nick Clifton User-Agent: Thunderbird 1.5.0.4 (X11/20060516) MIME-Version: 1.0 To: Bahadir Balban CC: binutils@sources.redhat.com Subject: Re: placing data into a section References: <7ac1e90c0607101106v8e41af1ge2ffb33410946487@mail.gmail.com> In-Reply-To: <7ac1e90c0607101106v8e41af1ge2ffb33410946487@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00138.txt.bz2 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.