Ask anything your want about Megadrive/Genesis programming.
Moderator: BigEvilCorporation
-
Stef
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
-
Contact:
Post
by Stef » Tue Apr 03, 2007 4:03 pm
Mask of Destiny wrote:objcopy automatically creates start and end symbols when you turn a raw binary into an ELF .o based on the file name. You'll need something like this in your source:
Code: Select all
extern unsigned char _binary_somefile_ext_start[];
extern unsigned char _binary_somefile_ext_end[];
There's also a symbol called _binary_somefile_ext_size, but I tend to just do pointer math on the start and end symbols instead.
Cool, i didn't that
Anyway in my case i'm using the converter to C file because i want to specify a fixed type (u8, u16, u32) which permit me to assure some alignement / size requirement
-
commodorejohn
- Very interested
- Posts: 70
- Joined: Tue Mar 06, 2007 6:30 pm
Post
by commodorejohn » Tue Apr 03, 2007 6:58 pm
I'm a little confused here. Is there a good explanation of the details of extern somewhere? Specifically, how are extern symbols in the code linked to specific binary files on disk?
-
Mask of Destiny
- Very interested
- Posts: 616
- Joined: Thu Nov 30, 2006 6:30 am
Post
by Mask of Destiny » Tue Apr 03, 2007 8:30 pm
All extern does is tells the compiler that the symbol being referenced is in some other object file (not in the current code being compiled) and therefore the reference should be resolved at link time. Just sticking those two lines in your source won't cause the binary file to get included in your final executable and will result in the linker complaining about an unresolved reference. You need to use the objcopy utility (part of the binutils package) to wrap the raw binary into an ELF object file which can be included in the link. That ELF object file has a couple of symbols defined in it, including the _binary_blahfile_ext_start and _binary_blahfile_ext_end.
For what it's worth, the linker has no knowledge of type information so you can use whatever type you like in your extern declaration in your source. It doesn't have to be char. As far as alignment is concerned, I believe you should get word alignment without any extra effort (at the very least, I've been able to assume word alignment without any issues). However, if you need something more exotic you'd probably need to mess around with your linker script a bit.
-
KanedaFr
- Administrateur
- Posts: 1139
- Joined: Tue Aug 29, 2006 10:56 am
-
Contact:
Post
by KanedaFr » Wed Apr 04, 2007 2:49 pm
just my 2 cents but has someone tested
MaccerX ?
only Fonzie talked about it so I wonder if it's a used tool.....