Discussion:
Adding segments to an executable
Norman Gray
2010-10-22 19:58:33 UTC
Permalink
Greetings

Is there any way of adding segments to an already-linked executable?

I appreciate that sounds like a rather odd thing to do. I'm trying to code-sign an executable, based on the instructions at <http://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html%23//apple_ref/doc/uid/TP40005929-CH4-SW2>. These include the instruction to create a suitable section in an output binary by adding arguments to the linker options:

-sectcreate __TEXT __info_plist Info.plist_path

However, the executable I'm trying to sign is produced using Racket's 'raco' tool, which creates an executable from Racket/scheme code by cloning the 'real' racket executable and editing the Mach-O file directly.

So the question is: is there a way I can further edit this executable, to add the section which is required for the code-signing?

Using ld doesn't work when used in the obvious way:

% ld -arch i386 -sectcreate __TEXT __info_plist ./hello.txt simbad-lod-copy
ld: in simbad-lod-copy, can't link with a main executable
%

That seems fair enough, I suppose. Libtool doesn't have any likely-looking options, and neither does the redo_prebinding command (which is at least a command for editing executables).

The two possibilities suggested by the relevant Racket list were (i) to adjust the 'raco' command to adjust the surgery which is done on the executable (feasible, I suppose, but scary), or (ii) to create a custom racket executable. Both seem like hammer-and-nut solutions.

Thanks for any pointers.

Norman
--
Norman Gray : http://nxg.me.uk
Loading...