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", &binary_data_bin_start, &binary_data_bin_end, &binary_data_bin_size, &binary_data_bin_start); } EOF $ objcopy -B i386 -I binary -O pe-i386 data.bin data.o $ gcc -c prog.c $ gcc -o prog data.o prog.o $ ./prog data starts at 402000, ends at 402019, with size 25: "this is some binary data" This works on linux also, except you must use "-O elf32-i386" instead of "-O pe-i386" and you must use a leading underscore on the symbol names. There's probably a way to abstract these differences away in the build system. Brian -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/