This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Determining size of embedded blobs
- From: Ian Lance Taylor <iant at google dot com>
- To: jhoderd at yahoo dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 21 Oct 2008 07:26:47 -0700
- Subject: Re: Determining size of embedded blobs
- References: <854269.70757.qm@web30408.mail.mud.yahoo.com>
Jean Hoderd <jhoderd@yahoo.com> writes:
> I want to embed an image into an executable. I managed
> to do it by running "ld -r -b binary -o blob.o blob.png"
> on the blob.png file, thus creating a blob.o that I can
> link into my main program. I have access to the binary
> blob by declaring an extern variable:
>
> extern char _binary_blob_png_start [];
>
> Normally I know the size of the blob I just linked in.
> But suppose I didn't. Is there a way I can determine
> it from within the C program? I know that by running
> "objdump -x blob.o" I can see the symbol table on the
> obj file, and that the symbols _binary_blob_png_end and
> _binary_blob_png_size are also defined:
>
> SYMBOL TABLE:
> 0000000000000000 l d .data 0000000000000000 .data
> 0000000000000400 g .data 0000000000000000 _binary_blob_png_end
> 0000000000000000 g .data 0000000000000000 _binary_blob_png_start
> 0000000000000400 g *ABS* 0000000000000000 _binary_blob_png_size
>
> I assumed that _binary_blob_png_end was a pointer to the
> end of the blob, but it doesn't seem so. Also, I always
> get a segfault if I assume that _binary_blob_png_size is
> an integer value.
As you've observed, _binary_blob_png_size is the size. To access it
from C, you have to write something like:
extern char _binary_blob_png_size[];
size_t size = (size_t) &_binary_blob_png_size[0];
It's an awkward translation from a linker symbol to a C value.
Ian