title: How can I add sections to an existing (OS X) executable?
body: <p>Is there any way of adding sections to an already-linked executable?</p>
  
  <p>I'm trying to code-sign an OS X executable, based on the <a href="http://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html%23//apple_ref/doc/uid/TP40005929-CH4-SW2" rel="noreferrer">Apple instructions</a>.  These include the instruction to create a suitable section in the binary to be signed, by adding arguments to the linker options:</p>
  
  <pre><code>-sectcreate __TEXT __info_plist Info.plist_path
  </code></pre>
  
  <p><strong>But:</strong> The executable I'm trying to sign is produced using <a href="http://www.racket-lang.org" rel="noreferrer">Racket</a> (a Scheme implementation), which assembles a standalone executable from Racket/scheme code by cloning the 'real' racket executable and editing the Mach-O file directly.</p>
  
  <p><strong>So the question is</strong>: is there a way I can further edit this executable, to add the section which is required for the code-signing?</p>
  
  <p>Using <code>ld</code> doesn't work when used in the obvious way:</p>
  
  <pre><code>% ld -arch i386 -sectcreate __TEXT __info_plist ./hello.txt racket-executable
  ld: in racket-executable, can't link with a main executable
  %
  </code></pre>
  
  <p>That seems fair enough, I suppose.  Libtool doesn't have any likely-looking options, and neither does the <code>redo_prebinding</code> command (which is at least a command for editing executables).</p>
  
  <p>The two possibilities suggested by the relevant Racket list were (i) to extend the the racket compilation tool to adjust the surgery which is done on the executable (feasible, but scary), or (ii) to create a custom racket executable which has the desired section already in place.  Both seem like sledgehammer-and-nut solutions.  The <code>macosx-dev</code> list didn't come up with any suggestions.</p>