开发者

Linking raw data/resource into executable using LD

Until now I've always used resources under MSVC++ to get access to raw data from inside of my programs and I've never worked with a linker directly, but now I'm under Linux and I'm using a cross-compiler to produce elf files开发者_StackOverflow社区. A friend and I are working on a toy OS.

One thing we need to get accomplished at some point is for a rather large piece of arbitrary raw data to be linked into the executable. We want the data to be located near the end of the executable and need to be able to get a pointer to that raw data as well. It's probably worth noting that GRUB is loading the kernel into memory at boot time.

One of our previous ideas was to just write a program to convert the data into a C source file where the data was represented as an array of bytes, but we figure that's a little bit messy and we'd rather have it linked in directly.

Any insights? I don't need the gruesome details just a broad overview of what needs to be done. I figure we probably have to make some changes to our linker script.


Take a look at calling objdump --add-section after you complete the link to add the arbitrary data to the ELF file.

Alternatively, if you are writing a kernel, you can do what Linux does to load an initrd and just have GRUB load your kernel and then load the data seperately to a known memory location and access it that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜