1 Jan 2006 01:27
Re: executable = exe + data
Brian Dessent <brian <at> dessent.net>
2006-01-01 00:27:44 GMT
2006-01-01 00:27:44 GMT
Brian Dessent wrote:
> All the methods mentioned so far are essentially hacks working against
> the linker, doing stuff behind its back. Why not go with the flow? Put
> your data in its own section, and write a linker script to handle that
> section in the desired way. You can access the address by referencing
> the linker script variables in your source code. See section 3 of the
> ld manual, particularly 3.5.3. This should work on any platform that
> uses ld.
Even simpler, use objcopy -B to convert raw binary data to an object
file.
$ echo -ne "this is some binary data\0" >data.bin
$ od -A x -v -t x1z -w12 data.bin
000000 74 68 69 73 20 69 73 20 73 6f 6d 65 >this is some<
00000c 20 62 69 6e 61 72 79 20 64 61 74 61 > binary data<
000018 00 >.<
000019
$ cat >prog.c <<EOF
#include <stdio.h>
extern long binary_data_bin_start, binary_data_bin_end,
binary_data_bin_size;
int main()
{
printf("data starts at %x, ends at %x, with size %ld: \"%s\"\n",
(Continue reading)
RSS Feed