PATCH: gas .incbin pseudo-op

Anders Norlander anorland@synergenix.se
Fri Jul 6 01:23:00 GMT 2001


On 05 Jul 2001 23:48:29 +0930, Alan Modra wrote:
> On Fri, Jun 29, 2001 at 05:52:34PM +0200, Anders Norlander wrote:
> > 
> > this patch adds a .incbin directive to gas to include files
> > verbatim at the current location, as found in many other assemblers.
> > I'm a bit surprised this has not come up before, but the archives
> > didn't reveal anything.
> 
> Hi Anders,
>   It's already possible to include binary files using the linker, which
> is probably why no one has found this feature necessary.

Yeah, that's possible but not as flexible. With .incbin you can do
it directly from C (or whatever), like this
#define INCBIN(symname, filename) \
__asm__ (".section .rodata ; .align 2; .globl " symname); \
__asm__ (symname ":\n.incbin \"" filename "\""); \
extern unsigned char symname[];

INCBIN(resource, "resource.dat");

This can be extremely useful to include graphics/sound/tables etc.
and have full control over symbols, sections and data included
from the file without having to modify your linker command and/or
linker script. Many people use objcopy to convert the binary into
a real object file, but that adds an extra conversion step to the
procedure, so I think it can be really useful.

-Anders




More information about the Binutils mailing list