<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:html="http://www.w3.org/1999/html" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Ross Burton</title><link>http://www.burtonini.com/blog</link><description>A potted account of Ross' life</description><language>en</language><ttl>60</ttl><dc:creator>Ross Burton</dc:creator><admin:generatorAgent rdf:resource="http://pyblosxom.sourceforge.net/"/><admin:errorReportsTo rdf:resource="mailto:ross@burtonini.com"/><item><title>More GUADEC Lightning Talks</title><guid isPermaLink="false">computers/guadec-2007-07-13-19-20</guid><link>http://www.burtonini.com/blog/computers/guadec-2007-07-13-19-20</link><description>We've had so many great Lightning Talk submissions this year that we're going to have to split the session into ...</description><content:encoded><![CDATA[    <p>
      We've had so many great Lightning Talk submissions this year that we're
      going to have to split the session into two.  There is still the original
      session at 15:00, but there is now another session at 17:00 for any talks
      that don't fit into the first session.
    </p>
    <p>
      If you are doing a lightning talk, please remember to either check that
      your laptop works with the projector in the hall perfectly
      <strong>before</strong> the talks start, or put your talk on a USB memory
      stick -- something portable such as PDF or S5 please -- so you can use the
      provided laptop (a ThinkPad T43, 1024x768).
    </p>
]]></content:encoded><category domain="http://www.burtonini.com">/computers</category><dc:date>2007-07-13T18:20:00Z</dc:date></item><item><title>Embedding Binary Blobs With GCC</title><guid isPermaLink="false">computers/ld-blobs-2007-07-13-15-50</guid><link>http://www.burtonini.com/blog/computers/ld-blobs-2007-07-13-15-50</link><description>For a long time I've wanted to know how to embed binary blobs into executables. This would be most useful ...</description><content:encoded><![CDATA[    <p>
      For a long time I've wanted to know how to embed binary blobs into
      executables.  This would be most useful for files like Glade and and UI
      Manager definitions, which are required for a given program to work at all
      but either cannot be embedded as a string literal (Glade) or can be but is
      annoying (UI Manager).  I finally asked the Interweb, and Daniel
      Jacobowitz replied with some pointers.  It turns out that doing this is
      remarkable simple.
    </p>
    <p>
      First, a caveat.  This probably requires GNU ld, which may or may not be a
      deal breaker for many people.
    </p>
    <p>
      First, create a data file.  Let's call it foo.txt, and put some text in it.
    </p>
    <pre>Hello, World!</pre>
    <p>
      Using <tt>ld</tt> this can be read in as a plain binary blob, and then
      written as a standard relocatable ELF object.
    </p>
    <pre>ld -r -b binary -o foo.o foo.txt</pre>
    <p>
      Now we have a standard ELF object with the data and some useful symbols
      defined.  <tt>objdump</tt> will show you the contents.
    </p>
    <pre>$ objdump -x foo.o 
foo.o:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         0000000d  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
00000000 l    d  .data  00000000 .data
0000000d g       .data  00000000 _binary_foo_txt_end
0000000d g       *ABS*  00000000 _binary_foo_txt_size
00000000 g       .data  00000000 _binary_foo_txt_start</pre>
    <p>
      Here we see 13 bytes of data, and a symbol which contains the address of
      the data.  This is all we need to access it from a C program.
    </p>
    <pre>#include &lt;stdio.h&gt;
extern char _binary_foo_txt_start[];

int main (void) {
  puts (_binary_foo_txt_start);
  return 0;
}</pre>
    <p>
      Now if we compile this and link it against the generated object, we'll have a binary.
    </p>
    <pre>$ gcc -o test test.c foo.o
$ ./test
Hello, World!</pre>
    <p>
      Hooray!  One small problem which alert people should have noticed: the
      string itself is in the <tt>.data</tt> section, which is read/write.  For
      my use, I want it to be read-only data in the <tt>.rodata</tt> section so
      that it isn't copied for every instance of the application.  As far as I
      know, this isn't possible with <tt>ld</tt> but <tt>objcopy</tt> will let
      us rename sections on the fly.
    </p>
    <pre>$ objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents foo.o foo.o
$ objdump  -h foo.o
...
  0 .rodata       0000000d  00000000  00000000  00000034  2**0</pre>
    <p>
      Excellent, problem solved.  If you want to download this sample, I have <a
      href="http://burtonini.com/computing/ldblob.tar.gz">a tarball</a>.  Many
      thanks to Daniel Jacobowitz for pointing out how to achieve this.
    </p>
    <p>
      <strong>Update:</strong> note that any data embedded in the binary like
      this won't be terminated with a NULL.  This is obvious in hindsight, but
      due to luck my example still worked.  There might be a way of asking
      objcopy to append a 0 to the end of the data, but if not always remember
      to use the start and end pointers or size instead of just the start, or
      append a NULL yourself before converting to an ELF.
    </p>
    <p>
      <small>NP: <cite>()</cite>, Sigur R&oacute;s</small>
    </p>
]]></content:encoded><category domain="http://www.burtonini.com">/computers</category><dc:date>2007-07-13T14:50:00Z</dc:date></item><item><title>Dear Interweb: GCC and Arbitrary Binary Sections</title><guid isPermaLink="false">computers/gcc-2007-07-13-12-30</guid><link>http://www.burtonini.com/blog/computers/gcc-2007-07-13-12-30</link><description>Mono/C has this nice feature where arbitrary files can be linked into the final binary, and you can programmatically access ...</description><content:encoded><![CDATA[    <p>
      Mono/C&#9839; has this nice feature where arbitrary files can be linked
      into the final binary, and you can programmatically access them.  I'd like
      to be able to do that in C too, I'm sure it is possible, I just don't know
      an easy way.  I know that if you have a section <tt>foo</tt>, then ld will
      create <tt>__start_foo</tt> and <tt>__stop_foo</tt> symbols which point to
      the start and end of the section, so all I really want is an easy way to
      get ld to use the contents of an arbitrary file (say, <tt>ui.xml</tt>) as
      a section.
    </p>
    <p>
      Anybody know how to do this?  <strong>Update:</strong> thanks to Daniel
      Jacobowitz for giving enough clues to a working, and clean, solution.
      I'll blog this shortly.
    </p>
    <p>
      <small>NP: <cite>The Sound Of A Handshake</cite>, cLOUDDEAD</small>
    </p>
]]></content:encoded><category domain="http://www.burtonini.com">/computers</category><dc:date>2007-07-13T11:30:00Z</dc:date></item></channel></rss>