This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

objcopy / binary inclusion weirdness (repost)


Hello-- I posted this to the Gameboy Advance developers' list but it's really 
a GNU tools question.  Can anybody give me the 'correct' answer to these 
rather than the workarounds I've stumbled on?
-----------------------------------------------------------------------------

This is largely to do with me not being 100% on how the linker works, but
hey, I'm sure it's a puzzler someone has solved.  Yes I've read the entry on
Jeff's FAQ but I need a bit more information!  Anyhow here's a simple build
script for a GBA project:

objcopy -I binary -O elf32-arm sprite sprite.o
gcc -o test.elf test.c
objcopy -O binary test.elf test.gba

Right, now, my problem is how to reference the data in sprite.o from test.c.
I notice that trying to dereference:

  extern u8* _binary_sprite_start;

causes a segfault, but

  extern u8  _binary_sprite_start[];

allows me to reference the data as I'd expect.  What's the difference from
the linker's point of view?  I think I can hazard half an answer given my
second problem, but it'd be nice to hear from someone who knows for sure.

Question 2 is how to get to the size attribute:

  extern u32 _binary_sprite_size;
  ...
  printf("%d", _binary_sprite_size);

causes an explosion because according to the debugger, _binary_sprite_size is
stored at address 0x1000 (the size of the sprite, of course).  To get to the
integer I have to do:

  printf("%d", (u32) &_binary_sprite_size);

Which works, but looks like shit!  Can somebody tell me whether I should be
passing different arguments to objcopy to get it to generate binaries that
can be referenced sensibly from C, or otherwise tell me what the correct way
of getting at these two symbols is?

cheers,

--
Matthew       > http://www.soup-kitchen.net/

              > ICQ 19482073


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]